You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/12/07 04:46:35 UTC
[01/10] incubator-mynewt-core git commit: oic;
coap - log at debug level incoming request/response data.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 524a6ea72 -> 96a90d500
oic; coap - log at debug level incoming request/response data.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/d924e39e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d924e39e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d924e39e
Branch: refs/heads/develop
Commit: d924e39ebba66c12ed446e9cde52639c357f4ede
Parents: 9207785
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 6 20:40:01 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 6 20:45:59 2016 -0800
----------------------------------------------------------------------
net/oic/src/messaging/coap/engine.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d924e39e/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index 009a2e3..756af70 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -73,48 +73,52 @@ coap_receive(oc_message_t *msg)
/*TODO duplicates suppression, if required by application */
-#if DEBUG
- LOG(" Parsed: CoAP version: %u, token: 0x%02X%02X, mid: %u\n",
+ OC_LOG_DEBUG(" Parsed: CoAP version: %u, token: 0x%02X%02X, mid: %u\n",
message->version, message->token[0], message->token[1], message->mid);
switch (message->type) {
case COAP_TYPE_CON:
- LOG(" type: CON\n");
+ OC_LOG_DEBUG(" type: CON\n");
break;
case COAP_TYPE_NON:
- LOG(" type: NON\n");
+ OC_LOG_DEBUG(" type: NON\n");
break;
case COAP_TYPE_ACK:
- LOG(" type: ACK\n");
+ OC_LOG_DEBUG(" type: ACK\n");
break;
case COAP_TYPE_RST:
- LOG(" type: RST\n");
+ OC_LOG_DEBUG(" type: RST\n");
break;
default:
break;
}
-#endif
/* handle requests */
if (message->code >= COAP_GET && message->code <= COAP_DELETE) {
-#if DEBUG
switch (message->code) {
case COAP_GET:
- LOG(" method: GET\n");
+ OC_LOG_DEBUG(" method: GET\n");
break;
case COAP_PUT:
- LOG(" method: PUT\n");
+ OC_LOG_DEBUG(" method: PUT\n");
break;
case COAP_POST:
- LOG(" method: POST\n");
+ OC_LOG_DEBUG(" method: POST\n");
break;
case COAP_DELETE:
- LOG(" method: DELETE\n");
+ OC_LOG_DEBUG(" method: DELETE\n");
break;
}
- LOG(" URL: %.*s\n", (int) message->uri_path_len, message->uri_path);
- LOG(" Payload: %.*s\n", (int) message->payload_len, message->payload);
+
+#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_DEBUG
+ uint8_t uri[64];
+ memcpy(uri, message->uri_path, message->uri_path_len);
+ uri[message->uri_path_len] = '\0';
+
+ OC_LOG_DEBUG(" URL: %s\n", uri);
+ OC_LOG_DEBUG(" Payload: %d bytes\n", message->payload_len);
#endif
+
/* use transaction buffer for response to confirmable request */
if ((transaction = coap_new_transaction(message->mid, &msg->endpoint))) {
uint32_t block_num = 0;
[06/10] incubator-mynewt-core git commit: oic;
coap - fixes to TCP header parsing. Add initial statistics.
Posted by ma...@apache.org.
oic; coap - fixes to TCP header parsing. Add initial statistics.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/9207785d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9207785d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9207785d
Branch: refs/heads/develop
Commit: 9207785da38608018f3577f4ab76dc7a948994a0
Parents: 4dd5a1f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 6 20:39:23 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 6 20:45:59 2016 -0800
----------------------------------------------------------------------
net/oic/pkg.yml | 1 +
net/oic/src/messaging/coap/coap.c | 78 +++++++++++++++++++++++++++--
net/oic/src/messaging/coap/coap.h | 16 +++++-
net/oic/src/messaging/coap/constants.h | 6 +--
4 files changed, 94 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9207785d/net/oic/pkg.yml
----------------------------------------------------------------------
diff --git a/net/oic/pkg.yml b/net/oic/pkg.yml
index 92098cd..1c6c302 100644
--- a/net/oic/pkg.yml
+++ b/net/oic/pkg.yml
@@ -27,6 +27,7 @@ pkg.deps:
- "encoding/tinycbor"
- "kernel/os"
- "sys/log"
+ - "sys/stats"
pkg.deps.OC_TRANSPORT_GATT:
- "net/nimble/host"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9207785d/net/oic/src/messaging/coap/coap.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.c b/net/oic/src/messaging/coap/coap.c
index 470af9c..528a009 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -41,6 +41,13 @@
#include "security/oc_dtls.h"
#endif
+STATS_SECT_DECL(coap_stats) coap_stats;
+STATS_NAME_START(coap_stats)
+ STATS_NAME(coap_stats, iframe)
+ STATS_NAME(coap_stats, ierr)
+ STATS_NAME(coap_stats, oframe)
+STATS_NAME_END(coap_stats)
+
/*---------------------------------------------------------------------------*/
/*- Variables ---------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
@@ -266,6 +273,10 @@ coap_init_connection(void)
{
/* initialize transaction ID */
current_mid = oc_random_rand();
+
+ stats_init_and_reg(STATS_HDR(coap_stats),
+ STATS_SIZE_INIT_PARMS(coap_stats, STATS_SIZE_32),
+ STATS_NAME_INIT_PARMS(coap_stats), "coap");
}
/*---------------------------------------------------------------------------*/
uint16_t
@@ -391,7 +402,7 @@ coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer, int tcp_hdr)
cth8 = (struct coap_tcp_hdr8 *)buffer;
cth8->type = COAP_TCP_TYPE8;
cth8->token_len = pkt->token_len;
- cth8->data_len = data_len - 13;
+ cth8->data_len = data_len - COAP_TCP_LENGTH8_OFF;
cth8->code = pkt->code;
option = (uint8_t *)(cth8 + 1);
} else if (data_len < 65805) {
@@ -399,7 +410,7 @@ coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer, int tcp_hdr)
cth16 = (struct coap_tcp_hdr16 *)buffer;
cth16->type = COAP_TCP_TYPE16;
cth16->token_len = pkt->token_len;
- cth16->data_len = htons(data_len - 269);
+ cth16->data_len = htons(data_len - COAP_TCP_LENGTH16_OFF);
cth16->code = pkt->code;
option = (uint8_t *)(cth16 + 1);
} else {
@@ -407,7 +418,7 @@ coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer, int tcp_hdr)
cth32 = (struct coap_tcp_hdr32 *)buffer;
cth32->type = COAP_TCP_TYPE32;
cth32->token_len = pkt->token_len;
- cth32->data_len = htonl(data_len - 65805);
+ cth32->data_len = htonl(data_len - COAP_TCP_LENGTH32_OFF);
cth32->code = pkt->code;
option = (uint8_t *)(cth32 + 1);
}
@@ -432,9 +443,47 @@ coap_send_message(oc_message_t *message)
{
LOG("-sending OCF message (%u)-\n", (unsigned int) message->length);
+ STATS_INC(coap_stats, oframe);
+
oc_send_message(message);
}
+/*
+ * Given COAP message header, return the number of bytes to expect for
+ * this frame.
+ */
+uint16_t
+coap_tcp_msg_size(uint8_t *hdr, int datalen)
+{
+ struct coap_tcp_hdr0 *cth0;
+ struct coap_tcp_hdr8 *cth8;
+ struct coap_tcp_hdr16 *cth16;
+ struct coap_tcp_hdr32 *cth32;
+
+ if (datalen < sizeof(*cth32)) {
+ return -1;
+ }
+ cth0 = (struct coap_tcp_hdr0 *)hdr;
+ if (cth0->data_len < COAP_TCP_TYPE8) {
+ return cth0->data_len + sizeof(*cth0) + cth0->token_len;
+ } else if (cth0->data_len == COAP_TCP_TYPE8) {
+ cth8 = (struct coap_tcp_hdr8 *)hdr;
+ return cth8->data_len + sizeof(*cth8) + cth8->token_len +
+ COAP_TCP_LENGTH8_OFF;
+ } else if (cth0->data_len == COAP_TCP_TYPE16) {
+ cth16 = (struct coap_tcp_hdr16 *)hdr;
+ return ntohs(cth16->data_len) + sizeof(*cth16) + cth16->token_len +
+ COAP_TCP_LENGTH16_OFF;
+ } else if (cth0->data_len == COAP_TCP_TYPE32) {
+ cth32 = (struct coap_tcp_hdr32 *)hdr;
+ return ntohl(cth32->data_len) + sizeof(*cth32) + cth32->token_len +
+ COAP_TCP_LENGTH32_OFF;
+ } else {
+ /* never here */
+ return -1;
+ }
+}
+
/*---------------------------------------------------------------------------*/
coap_status_t
coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
@@ -455,6 +504,8 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
/* pointer to packet bytes */
pkt->buffer = data;
+ STATS_INC(coap_stats, iframe);
+
/* parse header fields */
if (!tcp_hdr) {
udp = (struct coap_udp_hdr *)data;
@@ -465,6 +516,7 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
pkt->mid = ntohs(udp->id);
if (pkt->version != 1) {
coap_error_message = "CoAP version must be 1";
+ STATS_INC(coap_stats, ierr);
return BAD_REQUEST_4_00;
}
cur_opt = (uint8_t *)(udp + 1);
@@ -477,27 +529,40 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
cth0 = (struct coap_tcp_hdr0 *)data;
if (cth0->data_len < 13) {
pkt->token_len = cth0->token_len;
+ if (data_len != cth0->data_len + sizeof(*cth0) + pkt->token_len) {
+ goto len_err;
+ }
pkt->code = cth0->code;
cur_opt = (uint8_t *)(cth0 + 1);
} else if (cth0->data_len == 13) {
cth8 = (struct coap_tcp_hdr8 *)data;
pkt->token_len = cth8->token_len;
+ if (data_len != cth8->data_len + sizeof(*cth8) + pkt->token_len) {
+ goto len_err;
+ }
pkt->code = cth8->code;
cur_opt = (uint8_t *)(cth8 + 1);
} else if (cth0->data_len == 14) {
cth16 = (struct coap_tcp_hdr16 *)data;
pkt->token_len = cth16->token_len;
+ if (data_len != cth16->data_len + sizeof(*cth16) + pkt->token_len) {
+ goto len_err;
+ }
pkt->code = cth16->code;
cur_opt = (uint8_t *)(cth16 + 1);
} else {
cth32 = (struct coap_tcp_hdr32 *)data;
pkt->token_len = cth32->token_len;
+ if (data_len != cth32->data_len + sizeof(*cth32) + pkt->token_len) {
+ goto len_err;
+ }
pkt->code = cth32->code;
cur_opt = (uint8_t *)(cth32 + 1);
}
}
if (pkt->token_len > COAP_TOKEN_LEN) {
coap_error_message = "Token Length must not be more than 8";
+ STATS_INC(coap_stats, ierr);
return BAD_REQUEST_4_00;
}
@@ -604,6 +669,7 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
LOG("Proxy-Uri NOT IMPLEMENTED [%s]\n", (char *)pkt->proxy_uri);
coap_error_message =
"This is a constrained server (MyNewt)";
+ STATS_INC(coap_stats, ierr);
return PROXYING_NOT_SUPPORTED_5_05;
break;
case COAP_OPTION_PROXY_SCHEME:
@@ -614,6 +680,7 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
LOG("Proxy-Scheme NOT IMPLEMENTED [%s]\n", pkt->proxy_scheme);
coap_error_message =
"This is a constrained server (MyNewt)";
+ STATS_INC(coap_stats, ierr);
return PROXYING_NOT_SUPPORTED_5_05;
break;
@@ -690,6 +757,7 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
/* check if critical (odd) */
if (opt_num & 1) {
coap_error_message = "Unsupported critical option";
+ STATS_INC(coap_stats, ierr);
return BAD_OPTION_4_02;
}
}
@@ -698,6 +766,10 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
LOG("-Done parsing-------\n");
return NO_ERROR;
+len_err:
+ STATS_INC(coap_stats, ierr);
+ coap_error_message = "Input len mismatch";
+ return BAD_REQUEST_4_00;
}
#if 0
int
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9207785d/net/oic/src/messaging/coap/coap.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.h b/net/oic/src/messaging/coap/coap.h
index 987f34a..4ff64d7 100644
--- a/net/oic/src/messaging/coap/coap.h
+++ b/net/oic/src/messaging/coap/coap.h
@@ -44,11 +44,12 @@
extern "C" {
#endif
+#include <stats/stats.h>
/* OIC stack headers */
#include "../src/port/mynewt/config.h"
#include "oic/oc_buffer.h"
+#include "oic/oc_log.h"
#include "../src/port/oc_connectivity.h"
-#include "../src/port/oc_log.h"
#include "../src/port/oc_random.h"
#ifndef MAX
@@ -160,6 +161,17 @@ typedef struct coap_packet {
uint8_t *payload;
} coap_packet_t;
+/*
+ * COAP statistics
+ */
+STATS_SECT_START(coap_stats)
+ STATS_SECT_ENTRY(iframe)
+ STATS_SECT_ENTRY(ierr)
+ STATS_SECT_ENTRY(oframe)
+STATS_SECT_END
+
+extern STATS_SECT_DECL(coap_stats) coap_stats;
+
/* option format serialization */
#define COAP_SERIALIZE_INT_OPTION(coap_pkt, number, field, text) \
if (IS_OPTION(coap_pkt, number)) { \
@@ -210,6 +222,8 @@ extern char *coap_error_message;
void coap_init_connection(void);
uint16_t coap_get_mid(void);
+uint16_t coap_tcp_msg_size(uint8_t *hdr, int datalen);
+
void coap_init_message(coap_packet_t *, coap_message_type_t type,
uint8_t code, uint16_t mid);
size_t coap_serialize_message(coap_packet_t *, uint8_t *buffer, int tcp_hdr);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9207785d/net/oic/src/messaging/coap/constants.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/constants.h b/net/oic/src/messaging/coap/constants.h
index 385df69..8620a6d 100644
--- a/net/oic/src/messaging/coap/constants.h
+++ b/net/oic/src/messaging/coap/constants.h
@@ -71,9 +71,9 @@ struct coap_udp_hdr {
* Header used by Iotivity for TCP-like transports.
* 4 different kinds of headers.
*/
-#define COAP_TCP_LENGTH_FIELD_8_BIT 13
-#define COAP_TCP_LENGTH_FIELD_16_BIT 269
-#define COAP_TCP_LENGTH_FIELD_32_BIT 65805
+#define COAP_TCP_LENGTH8_OFF 13
+#define COAP_TCP_LENGTH16_OFF 269
+#define COAP_TCP_LENGTH32_OFF 65805
#define COAP_TCP_TYPE0 0
#define COAP_TCP_TYPE8 13
[05/10] incubator-mynewt-core git commit: oic;
newconn/delconn calls to oic ble. These should be called when new
connection is established.
Posted by ma...@apache.org.
oic; newconn/delconn calls to oic ble. These should be called when
new connection is established.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/db3e41f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/db3e41f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/db3e41f0
Branch: refs/heads/develop
Commit: db3e41f09d45af93593898edb66aa89ad8d1975b
Parents: 3b8b692
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 6 20:30:03 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 6 20:45:59 2016 -0800
----------------------------------------------------------------------
net/oic/include/oic/oc_gatt.h | 6 ++-
net/oic/include/oic/oc_log.h | 82 ++++++++++++++++++++++++++++++++++++++
net/oic/src/port/mynewt/log.c | 43 --------------------
net/oic/src/port/oc_log.h | 82 --------------------------------------
4 files changed, 87 insertions(+), 126 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/db3e41f0/net/oic/include/oic/oc_gatt.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_gatt.h b/net/oic/include/oic/oc_gatt.h
index 0261678..2cf970e 100644
--- a/net/oic/include/oic/oc_gatt.h
+++ b/net/oic/include/oic/oc_gatt.h
@@ -24,7 +24,11 @@
extern "C" {
#endif
-int ble_coap_gatt_srv_init(void);
+int oc_ble_coap_gatt_srv_init(void);
+void oc_ble_coap_conn_new(uint16_t conn_handle);
+void oc_ble_coap_conn_del(uint16_t conn_handle);
+
+extern const uint8_t oc_gatt_svc_uuid[];
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/db3e41f0/net/oic/include/oic/oc_log.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_log.h b/net/oic/include/oic/oc_log.h
new file mode 100644
index 0000000..e77575b
--- /dev/null
+++ b/net/oic/include/oic/oc_log.h
@@ -0,0 +1,82 @@
+/*
+// Copyright (c) 2016 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#ifndef OC_LOG_H
+#define OC_LOG_H
+
+#include <stdio.h>
+#include "mynewt/config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define PRINT(...) printf(__VA_ARGS__)
+
+#define PRINTipaddr(endpoint) \
+ PRINT( \
+ "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%" \
+ "02x]:%d", \
+ ((endpoint).ipv6_addr.address)[0], ((endpoint).ipv6_addr.address)[1], \
+ ((endpoint).ipv6_addr.address)[2], ((endpoint).ipv6_addr.address)[3], \
+ ((endpoint).ipv6_addr.address)[4], ((endpoint).ipv6_addr.address)[5], \
+ ((endpoint).ipv6_addr.address)[6], ((endpoint).ipv6_addr.address)[7], \
+ ((endpoint).ipv6_addr.address)[8], ((endpoint).ipv6_addr.address)[9], \
+ ((endpoint).ipv6_addr.address)[10], ((endpoint).ipv6_addr.address)[11], \
+ ((endpoint).ipv6_addr.address)[12], ((endpoint).ipv6_addr.address)[13], \
+ ((endpoint).ipv6_addr.address)[14], ((endpoint).ipv6_addr.address)[15], \
+ (endpoint).ipv6_addr.port)
+
+#define LogMynewtipaddr(endpoint) \
+{\
+ char tmp_buf[16*3+6]; /* 16 octets plus port */ \
+ sprintf(tmp_buf, \
+ "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%" \
+ "02x]:%d", \
+ ((endpoint).ipv6_addr.address)[0], ((endpoint).ipv6_addr.address)[1], \
+ ((endpoint).ipv6_addr.address)[2], ((endpoint).ipv6_addr.address)[3], \
+ ((endpoint).ipv6_addr.address)[4], ((endpoint).ipv6_addr.address)[5], \
+ ((endpoint).ipv6_addr.address)[6], ((endpoint).ipv6_addr.address)[7], \
+ ((endpoint).ipv6_addr.address)[8], ((endpoint).ipv6_addr.address)[9], \
+ ((endpoint).ipv6_addr.address)[10], ((endpoint).ipv6_addr.address)[11], \
+ ((endpoint).ipv6_addr.address)[12], ((endpoint).ipv6_addr.address)[13], \
+ ((endpoint).ipv6_addr.address)[14], ((endpoint).ipv6_addr.address)[15], \
+ (endpoint).ipv6_addr.port); \
+ LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY, "%s", tmp_buf); \
+}
+
+#if defined(ARCH_sim)
+#define LOG(...) PRINT(__VA_ARGS__)
+#define ERROR(...) LOG(__VA_ARGS__)
+#define LOGipaddr(endpoint) PRINTipaddr(endpoint)
+#define oc_log_init() 0
+#elif defined(DEBUG)
+int oc_log_init(void);
+#define LOG(...) LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
+#define ERROR(...) LOG_ERROR(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
+#define LOGipaddr(endpoint) LogMynewtipaddr(endpoint)
+#else
+#define LOG(...)
+#define ERROR(...)
+#define LOGipaddr(endpoint)
+#define oc_log_init() 0
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* OC_LOG_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/db3e41f0/net/oic/src/port/mynewt/log.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/log.c b/net/oic/src/port/mynewt/log.c
deleted file mode 100644
index d205552..0000000
--- a/net/oic/src/port/mynewt/log.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-#include <log/log.h>
-
-/* logging data for this module. TODO, the application should
- * define the logging strategy for this module */
-#define MAX_CBMEM_BUF (600)
-static uint32_t *cbmem_buf;
-static struct cbmem cbmem;
-struct log oc_log;
-
-int
-oc_log_init(void) {
-
- log_init();
-
- cbmem_buf = malloc(sizeof(uint32_t) * MAX_CBMEM_BUF);
- if (cbmem_buf == NULL) {
- return -1;
- }
-
- cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF);
- log_register("iot", &oc_log, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL);
-
- LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY, "OC Init");
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/db3e41f0/net/oic/src/port/oc_log.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_log.h b/net/oic/src/port/oc_log.h
deleted file mode 100644
index e77575b..0000000
--- a/net/oic/src/port/oc_log.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
-// Copyright (c) 2016 Intel Corporation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-*/
-
-#ifndef OC_LOG_H
-#define OC_LOG_H
-
-#include <stdio.h>
-#include "mynewt/config.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define PRINT(...) printf(__VA_ARGS__)
-
-#define PRINTipaddr(endpoint) \
- PRINT( \
- "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%" \
- "02x]:%d", \
- ((endpoint).ipv6_addr.address)[0], ((endpoint).ipv6_addr.address)[1], \
- ((endpoint).ipv6_addr.address)[2], ((endpoint).ipv6_addr.address)[3], \
- ((endpoint).ipv6_addr.address)[4], ((endpoint).ipv6_addr.address)[5], \
- ((endpoint).ipv6_addr.address)[6], ((endpoint).ipv6_addr.address)[7], \
- ((endpoint).ipv6_addr.address)[8], ((endpoint).ipv6_addr.address)[9], \
- ((endpoint).ipv6_addr.address)[10], ((endpoint).ipv6_addr.address)[11], \
- ((endpoint).ipv6_addr.address)[12], ((endpoint).ipv6_addr.address)[13], \
- ((endpoint).ipv6_addr.address)[14], ((endpoint).ipv6_addr.address)[15], \
- (endpoint).ipv6_addr.port)
-
-#define LogMynewtipaddr(endpoint) \
-{\
- char tmp_buf[16*3+6]; /* 16 octets plus port */ \
- sprintf(tmp_buf, \
- "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%" \
- "02x]:%d", \
- ((endpoint).ipv6_addr.address)[0], ((endpoint).ipv6_addr.address)[1], \
- ((endpoint).ipv6_addr.address)[2], ((endpoint).ipv6_addr.address)[3], \
- ((endpoint).ipv6_addr.address)[4], ((endpoint).ipv6_addr.address)[5], \
- ((endpoint).ipv6_addr.address)[6], ((endpoint).ipv6_addr.address)[7], \
- ((endpoint).ipv6_addr.address)[8], ((endpoint).ipv6_addr.address)[9], \
- ((endpoint).ipv6_addr.address)[10], ((endpoint).ipv6_addr.address)[11], \
- ((endpoint).ipv6_addr.address)[12], ((endpoint).ipv6_addr.address)[13], \
- ((endpoint).ipv6_addr.address)[14], ((endpoint).ipv6_addr.address)[15], \
- (endpoint).ipv6_addr.port); \
- LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY, "%s", tmp_buf); \
-}
-
-#if defined(ARCH_sim)
-#define LOG(...) PRINT(__VA_ARGS__)
-#define ERROR(...) LOG(__VA_ARGS__)
-#define LOGipaddr(endpoint) PRINTipaddr(endpoint)
-#define oc_log_init() 0
-#elif defined(DEBUG)
-int oc_log_init(void);
-#define LOG(...) LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
-#define ERROR(...) LOG_ERROR(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
-#define LOGipaddr(endpoint) LogMynewtipaddr(endpoint)
-#else
-#define LOG(...)
-#define ERROR(...)
-#define LOGipaddr(endpoint)
-#define oc_log_init() 0
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* OC_LOG_H */
[08/10] incubator-mynewt-core git commit: oic;
location of oc_log.h was moved.
Posted by ma...@apache.org.
oic; location of oc_log.h was moved.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/183218f5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/183218f5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/183218f5
Branch: refs/heads/develop
Commit: 183218f5c917692922464bfc3d574e22cc2a0f6e
Parents: db3e41f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 6 20:34:28 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 6 20:45:59 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_rep.c | 4 ++--
net/oic/src/port/mynewt/adaptor.c | 8 +++++---
net/oic/src/port/mynewt/ip_adaptor.c | 8 +-------
net/oic/src/port/mynewt/serial_adaptor.c | 2 +-
net/oic/src/port/oc_connectivity.h | 1 -
5 files changed, 9 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/183218f5/net/oic/src/api/oc_rep.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_rep.c b/net/oic/src/api/oc_rep.c
index 08ec29b..4ef7161 100644
--- a/net/oic/src/api/oc_rep.c
+++ b/net/oic/src/api/oc_rep.c
@@ -17,10 +17,10 @@
#include <stddef.h>
#include <os/os_mempool.h>
-#include "oc_rep.h"
+#include "oic/oc_rep.h"
+#include "oic/oc_log.h"
#include "config.h"
#include "port/oc_assert.h"
-#include "port/oc_log.h"
#include "api/oc_priv.h"
#include <tinycbor/cbor_buf_writer.h>
#include <tinycbor/cbor_buf_reader.h>
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/183218f5/net/oic/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.c b/net/oic/src/port/mynewt/adaptor.c
index cdd31f5..83d73dd 100644
--- a/net/oic/src/port/mynewt/adaptor.c
+++ b/net/oic/src/port/mynewt/adaptor.c
@@ -22,14 +22,16 @@
#include <os/endian.h>
#include <string.h>
#include <log/log.h>
-#include "../oc_network_events_mutex.h"
-#include "../oc_connectivity.h"
+#include "oic/oc_log.h"
+#include "port/oc_network_events_mutex.h"
+#include "port/oc_connectivity.h"
#include "oc_buffer.h"
-#include "../oc_log.h"
#include "adaptor.h"
static struct os_eventq *oc_evq;
+struct log oc_log;
+
/* not sure if these semaphores are necessary yet. If we are running
* all of this from one task, we may not need these */
static struct os_mutex oc_net_mutex;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/183218f5/net/oic/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip_adaptor.c b/net/oic/src/port/mynewt/ip_adaptor.c
index fbf16ec..5bb73c9 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -28,9 +28,8 @@
#include <log/log.h>
#include <mn_socket/mn_socket.h>
-#include "../oc_connectivity.h"
+#include "port/oc_connectivity.h"
#include "oc_buffer.h"
-#include "../oc_log.h"
#include "adaptor.h"
static void oc_event_ip(struct os_event *ev);
@@ -253,11 +252,6 @@ oc_connectivity_init_ip(void)
LOG("OC transport init IP\n");
memset(&itf, 0, sizeof(itf));
- rc = oc_log_init();
- if ( rc != 0) {
- ERROR("Could not create oc logging\n");
- return rc; }
-
rc = mn_socket(&ucast, MN_PF_INET6, MN_SOCK_DGRAM, 0);
if ( rc != 0 || !ucast ) {
ERROR("Could not create oc unicast socket\n");
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/183218f5/net/oic/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/serial_adaptor.c b/net/oic/src/port/mynewt/serial_adaptor.c
index 59342a9..e3c350f 100644
--- a/net/oic/src/port/mynewt/serial_adaptor.c
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -28,7 +28,7 @@
#include "oc_buffer.h"
#include "port/oc_connectivity.h"
-#include "../oc_log.h"
+#include "oic/oc_log.h"
#include "adaptor.h"
struct os_mqueue oc_serial_mqueue;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/183218f5/net/oic/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_connectivity.h b/net/oic/src/port/oc_connectivity.h
index f5a075e..e8762a3 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -18,7 +18,6 @@
#define OC_CONNECTIVITY_H
#include "mynewt/config.h"
-#include "oc_log.h"
#include <stdint.h>
#ifdef __cplusplus
[09/10] incubator-mynewt-core git commit: oic ble;
switch to use same UUID as iotivity. Add reassembly/fragmentation of
data to BLE MTU size chunks. Add initial statistics.
Posted by ma...@apache.org.
oic ble; switch to use same UUID as iotivity.
Add reassembly/fragmentation of data to BLE MTU size chunks.
Add initial statistics.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/d382b9c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d382b9c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d382b9c7
Branch: refs/heads/develop
Commit: d382b9c7398249b880b34f8829ed6bdbff639b8a
Parents: d924e39
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 6 20:41:07 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 6 20:46:00 2016 -0800
----------------------------------------------------------------------
net/oic/src/port/mynewt/ble_adaptor.c | 331 +++++++++++++++++++++++------
1 file changed, 266 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d382b9c7/net/oic/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
index 81f2d2c..9ca7443 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -22,53 +22,93 @@
#include <assert.h>
#include <os/os.h>
#include <string.h>
+
+#include <stats/stats.h>
+#include "oic/oc_gatt.h"
+#include "oic/oc_log.h"
+#include "messaging/coap/coap.h"
#include "oc_buffer.h"
#include "port/oc_connectivity.h"
-#include "../oc_log.h"
#include "adaptor.h"
#include "host/ble_hs.h"
#include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h"
+/* OIC Transport Profile GATT */
+
+/* service UUID */
+/* ADE3D529-C784-4F63-A987-EB69 F70E E816 */
+const uint8_t oc_gatt_svc_uuid[16] = {
+ 0x16, 0xe8, 0x0e, 0xf7, 0x69, 0xeb, 0x87, 0xa9,
+ 0x63, 0x4f, 0x84, 0xc7, 0x29, 0xd5, 0xe3, 0xad
+};
-/* a custom service for COAP over GATT */
-/* {e3f9f9c4-8a83-4055-b647-728b769745d6} */
-const uint8_t gatt_svr_svc_coap[16] = {
- 0xd6, 0x45, 0x97, 0x76, 0x8b, 0x72, 0x47, 0xb6,
- 0x55, 0x40, 0x83, 0x8a, 0xc4, 0xf9, 0xf9, 0xe3,
+/* request characteristic UUID */
+/* AD7B334F-4637-4B86-90B6-9D78 7F03 D218 */
+static const uint8_t oc_gatt_req_chr_uuid[16] = {
+ 0x18, 0xd2, 0x03, 0x7f, 0x78, 0x9d, 0xb6, 0x90,
+ 0x86, 0x4b, 0x37, 0x46, 0x4f, 0x33, 0x7b, 0xad
};
-/* {e467fee6-d6bb-4956-94df-0090350631f5} */
-const uint8_t gatt_svr_chr_coap[16] = {
- 0xf5, 0x31, 0x06, 0x35, 0x90, 0x00, 0xdf, 0x94,
- 0x56, 0x49, 0xbb, 0xd6, 0xe6, 0xfe, 0x67, 0xe4,
+/* response characteristic UUID */
+/* E9241982-4580-42C4-8831-9504 8216 B256 */
+static const uint8_t oc_gatt_rsp_chr_uuid[16] = {
+ 0x56, 0xb2, 0x16, 0x82, 0x04, 0x95, 0x31, 0x88,
+ 0xc4, 0x42, 0x80, 0x45, 0x82, 0x19, 0x24, 0xe9
};
+STATS_SECT_START(oc_ble_stats)
+ STATS_SECT_ENTRY(iseg)
+ STATS_SECT_ENTRY(ibytes)
+ STATS_SECT_ENTRY(ierr)
+ STATS_SECT_ENTRY(oseg)
+ STATS_SECT_ENTRY(obytes)
+ STATS_SECT_ENTRY(oerr)
+STATS_SECT_END
+static STATS_SECT_DECL(oc_ble_stats) oc_ble_stats;
+STATS_NAME_START(oc_ble_stats)
+ STATS_NAME(oc_ble_stats, iseg)
+ STATS_NAME(oc_ble_stats, ibytes)
+ STATS_NAME(oc_ble_stats, ierr)
+ STATS_NAME(oc_ble_stats, oseg)
+ STATS_NAME(oc_ble_stats, obytes)
+ STATS_NAME(oc_ble_stats, oerr)
+STATS_NAME_END(oc_ble_stats)
+
/* queue to hold mbufs until we get called from oic */
-struct os_mqueue ble_coap_mq;
+static struct os_mqueue oc_ble_coap_mq;
+static STAILQ_HEAD(, os_mbuf_pkthdr) oc_ble_reass_q;
#if (MYNEWT_VAL(OC_SERVER) == 1)
/* ble nmgr attr handle */
-uint16_t g_ble_coap_attr_handle;
+static uint16_t oc_ble_coap_req_handle;
+static uint16_t oc_ble_coap_rsp_handle;
-static int
-gatt_svr_chr_access_coap(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt, void *arg);
+static int oc_gatt_chr_access(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt, void *arg);
-static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
- {
+static const struct ble_gatt_svc_def gatt_svr_svcs[] = { {
/* Service: newtmgr */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid128 = (void *)gatt_svr_svc_coap,
- .characteristics = (struct ble_gatt_chr_def[]) { {
- /* Characteristic: Write No Rsp */
- .uuid128 = (void *)gatt_svr_chr_coap,
- .access_cb = gatt_svr_chr_access_coap,
- .flags = BLE_GATT_CHR_F_WRITE_NO_RSP | BLE_GATT_CHR_F_NOTIFY,
- .val_handle = &g_ble_coap_attr_handle,
- }, {
- 0, /* No more characteristics in this service */
- } },
+ .uuid128 = (void *)oc_gatt_svc_uuid,
+ .characteristics = (struct ble_gatt_chr_def[]) {
+ {
+ /* Characteristic: Request */
+ .uuid128 = (void *)oc_gatt_req_chr_uuid,
+ .access_cb = oc_gatt_chr_access,
+ .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_NO_RSP |
+ BLE_GATT_CHR_F_NOTIFY,
+ .val_handle = &oc_ble_coap_req_handle,
+ },{
+ /* Characteristic: Response */
+ .uuid128 = (void *)oc_gatt_rsp_chr_uuid,
+ .access_cb = oc_gatt_chr_access,
+ .flags = BLE_GATT_CHR_F_NOTIFY,
+ .val_handle = &oc_ble_coap_rsp_handle,
+ },{
+ 0, /* No more characteristics in this service */
+ }
+ },
},
{
0, /* No more services */
@@ -76,35 +116,35 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
};
static int
-gatt_svr_chr_access_coap(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt, void *arg)
+oc_gatt_chr_access(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt, void *arg)
{
struct os_mbuf *m;
int rc;
- (void) attr_handle; /* no need to use this since we have onyl one attr
- * tied to this callback */
+ (void) attr_handle; /* xxx req should only come in via req handle */
switch (ctxt->op) {
- case BLE_GATT_ACCESS_OP_WRITE_CHR:
- m = ctxt->om;
- /* stick the conn handle at the end of the frame -- we will
- * pull it out later */
- rc = os_mbuf_append(m, &conn_handle, sizeof(conn_handle));
- if (rc) {
- return BLE_ATT_ERR_INSUFFICIENT_RES;
- }
- rc = os_mqueue_put(&ble_coap_mq, oc_evq_get(), m);
- if (rc) {
- return BLE_ATT_ERR_PREPARE_QUEUE_FULL;
- }
-
- /* tell nimble we are keeping the mbuf */
- ctxt->om = NULL;
-
- break;
- default:
- assert(0);
- return BLE_ATT_ERR_UNLIKELY;
+ case BLE_GATT_ACCESS_OP_WRITE_CHR:
+ m = ctxt->om;
+
+ /* stick the conn handle at the end of the frame -- we will
+ * pull it out later */
+ rc = os_mbuf_append(m, &conn_handle, sizeof(conn_handle));
+ if (rc) {
+ return BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
+ rc = os_mqueue_put(&oc_ble_coap_mq, oc_evq_get(), m);
+ if (rc) {
+ return BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
+
+ /* tell nimble we are keeping the mbuf */
+ ctxt->om = NULL;
+
+ break;
+ default:
+ assert(0);
+ return BLE_ATT_ERR_UNLIKELY;
}
return 0;
}
@@ -119,22 +159,25 @@ oc_attempt_rx_gatt(void)
struct oc_endpoint *oe;
uint16_t conn_handle;
- LOG("oc_transport_gatt attempt rx\n");
+ LOG("oc_gatt attempt rx\n");
/* get an mbuf from the queue */
- n = os_mqueue_get(&ble_coap_mq);
+ n = os_mqueue_get(&oc_ble_coap_mq);
if (NULL == n) {
- ERROR("oc_transport_gatt: Woke for receive but found no mbufs\n");
+ ERROR("oc_gatt Woke for receive but found no mbufs\n");
return NULL;
}
pkt = OS_MBUF_PKTHDR(n);
+ STATS_INC(oc_ble_stats, iseg);
+ STATS_INCN(oc_ble_stats, ibytes, pkt->omp_len);
+
/* get the conn handle from the end of the message */
rc = os_mbuf_copydata(n, pkt->omp_len - sizeof(conn_handle),
sizeof(conn_handle), &conn_handle);
if (rc != 0) {
- ERROR("Failed to retrieve conn_handle from mbuf\n");
+ ERROR("oc_gatt Failed to retrieve conn_handle from mbuf\n");
goto rx_attempt_err;
}
@@ -143,7 +186,7 @@ oc_attempt_rx_gatt(void)
m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
if (!m) {
- ERROR("Could not allocate OC message buffer\n");
+ ERROR("oc_gatt Could not allocate OC message buffer\n");
goto rx_attempt_err;
}
OS_MBUF_PKTHDR(m)->omp_len = pkt->omp_len;
@@ -154,22 +197,24 @@ oc_attempt_rx_gatt(void)
oe->flags = GATT;
oe->bt_addr.conn_handle = conn_handle;
- LOG("oc_transport_gatt rx %p-%u\n", pkt, pkt->omp_len);
+ LOG("oc_gatt rx %x-%u\n", (unsigned)pkt, pkt->omp_len);
return m;
/* add the addr info to the message */
rx_attempt_err:
+ STATS_INC(oc_ble_stats, ierr);
os_mbuf_free_chain(n);
return NULL;
}
#endif
int
-ble_coap_gatt_srv_init(void)
+oc_ble_coap_gatt_srv_init(void)
{
#if (MYNEWT_VAL(OC_SERVER) == 1)
int rc;
+
rc = ble_gatts_count_cfg(gatt_svr_svcs);
if (rc != 0) {
return rc;
@@ -180,24 +225,109 @@ ble_coap_gatt_srv_init(void)
return rc;
}
#endif
-
+ stats_init_and_reg(STATS_HDR(oc_ble_stats),
+ STATS_SIZE_INIT_PARMS(oc_ble_stats, STATS_SIZE_32),
+ STATS_NAME_INIT_PARMS(oc_ble_stats), "oc_ble");
return 0;
}
+void
+oc_ble_reass(struct os_mbuf *om1)
+{
+ struct os_mbuf_pkthdr *pkt1;
+ struct oc_endpoint *oe1;
+ struct os_mbuf *om2;
+ struct os_mbuf_pkthdr *pkt2;
+ struct oc_endpoint *oe2;
+ int sr;
+ uint8_t hdr[6]; /* sizeof(coap_tcp_hdr32) */
+
+ pkt1 = OS_MBUF_PKTHDR(om1);
+ assert(pkt1);
+ oe1 = OC_MBUF_ENDPOINT(om1);
+
+ LOG("oc_gatt rx seg %d-%x-%u\n", oe1->bt_addr.conn_handle,
+ (unsigned)pkt1, pkt1->omp_len);
+
+ OS_ENTER_CRITICAL(sr);
+ STAILQ_FOREACH(pkt2, &oc_ble_reass_q, omp_next) {
+ om2 = OS_MBUF_PKTHDR_TO_MBUF(pkt2);
+ oe2 = OC_MBUF_ENDPOINT(om2);
+ if (oe1->bt_addr.conn_handle == oe2->bt_addr.conn_handle) {
+ /*
+ * Data from same connection. Append.
+ */
+ os_mbuf_concat(om2, om1);
+ if (os_mbuf_copydata(om2, 0, sizeof(hdr), hdr)) {
+ pkt1 = NULL;
+ break;
+ }
+ if (coap_tcp_msg_size(hdr, sizeof(hdr)) <= pkt2->omp_len) {
+ STAILQ_REMOVE(&oc_ble_reass_q, pkt2, os_mbuf_pkthdr,
+ omp_next);
+ oc_recv_message(om2);
+ }
+ pkt1 = NULL;
+ break;
+ }
+ }
+ if (pkt1) {
+ /*
+ *
+ */
+ if (os_mbuf_copydata(om1, 0, sizeof(hdr), hdr) ||
+ coap_tcp_msg_size(hdr, sizeof(hdr)) > pkt1->omp_len) {
+ STAILQ_INSERT_TAIL(&oc_ble_reass_q, pkt1, omp_next);
+ } else {
+ oc_recv_message(om1);
+ }
+ }
+ OS_EXIT_CRITICAL(sr);
+}
+
+void
+oc_ble_coap_conn_new(uint16_t conn_handle)
+{
+ LOG("oc_gatt newconn %x\n", conn_handle);
+}
+
+void
+oc_ble_coap_conn_del(uint16_t conn_handle)
+{
+ struct os_mbuf_pkthdr *pkt;
+ struct os_mbuf *m;
+ struct oc_endpoint *oe;
+ int sr;
+
+ LOG("oc_gatt endconn %x\n", conn_handle);
+ OS_ENTER_CRITICAL(sr);
+ STAILQ_FOREACH(pkt, &oc_ble_reass_q, omp_next) {
+ m = OS_MBUF_PKTHDR_TO_MBUF(pkt);
+ oe = OC_MBUF_ENDPOINT(m);
+ if (oe->bt_addr.conn_handle == conn_handle) {
+ STAILQ_REMOVE(&oc_ble_reass_q, pkt, os_mbuf_pkthdr, omp_next);
+ os_mbuf_free_chain(m);
+ break;
+ }
+ }
+ OS_EXIT_CRITICAL(sr);
+}
+
static void
oc_event_gatt(struct os_event *ev)
{
struct os_mbuf *m;
while ((m = oc_attempt_rx_gatt()) != NULL) {
- oc_recv_message(m);
+ oc_ble_reass(m);
}
}
int
oc_connectivity_init_gatt(void)
{
- os_mqueue_init(&ble_coap_mq, oc_event_gatt, NULL);
+ os_mqueue_init(&oc_ble_coap_mq, oc_event_gatt, NULL);
+ STAILQ_INIT(&oc_ble_reass_q);
return 0;
}
@@ -207,19 +337,90 @@ oc_connectivity_shutdown_gatt(void)
/* there is not unregister for BLE */
}
+static int
+oc_ble_frag(struct os_mbuf *m, uint16_t mtu)
+{
+ struct os_mbuf_pkthdr *pkt;
+ struct os_mbuf *n;
+ uint16_t off, blk;
+
+ pkt = OS_MBUF_PKTHDR(m);
+ if (pkt->omp_len <= mtu) {
+ STAILQ_NEXT(pkt, omp_next) = NULL;
+ return 0;
+ }
+ off = mtu;
+
+ while (off < OS_MBUF_PKTLEN(m)) {
+ n = os_msys_get_pkthdr(mtu, 0);
+ if (!n) {
+ goto err;
+ }
+
+ STAILQ_NEXT(pkt, omp_next) = OS_MBUF_PKTHDR(n);
+ pkt = STAILQ_NEXT(pkt, omp_next);
+
+ blk = OS_MBUF_PKTLEN(m) - off;
+ if (blk > mtu) {
+ blk = mtu;
+ }
+ if (os_mbuf_appendfrom(n, m, off, blk)) {
+ goto err;
+ }
+ off += blk;
+ }
+ os_mbuf_adj(m, mtu - OS_MBUF_PKTLEN(m));
+ return 0;
+err:
+ pkt = OS_MBUF_PKTHDR(m);
+ while (1) {
+ pkt = STAILQ_NEXT(pkt, omp_next);
+ os_mbuf_free_chain(m);
+ if (!pkt) {
+ break;
+ }
+ m = OS_MBUF_PKTHDR_TO_MBUF(pkt);
+ };
+ return -1;
+}
+
void
oc_send_buffer_gatt(struct os_mbuf *m)
{
struct oc_endpoint *oe;
+ struct os_mbuf_pkthdr *pkt;
+ uint16_t mtu;
+ uint16_t conn_handle;
oe = OC_MBUF_ENDPOINT(m);
+ conn_handle = oe->bt_addr.conn_handle;
#if (MYNEWT_VAL(OC_CLIENT) == 1)
- ERROR("send not supported on client");
+ ERROR("oc_gatt send not supported on client");
#endif
#if (MYNEWT_VAL(OC_SERVER) == 1)
- ble_gattc_notify_custom(oe->bt_addr.conn_handle, g_ble_coap_attr_handle, m);
+
+ STATS_INC(oc_ble_stats, oseg);
+ STATS_INCN(oc_ble_stats, obytes, OS_MBUF_PKTLEN(m));
+
+ mtu = ble_att_mtu(oe->bt_addr.conn_handle);
+ mtu -= 3; /* # of bytes for ATT notification base */
+
+ if (oc_ble_frag(m, mtu)) {
+ STATS_INC(oc_ble_stats, oerr);
+ return;
+ }
+ while (1) {
+ pkt = STAILQ_NEXT(OS_MBUF_PKTHDR(m), omp_next);
+
+ ble_gattc_notify_custom(conn_handle, oc_ble_coap_rsp_handle, m);
+ if (pkt) {
+ m = OS_MBUF_PKTHDR_TO_MBUF(pkt);
+ } else {
+ break;
+ }
+ }
#endif
}
@@ -227,10 +428,10 @@ void
oc_send_buffer_gatt_mcast(oc_message_t *message)
{
#if (MYNEWT_VAL(OC_CLIENT) == 1)
- ERROR("send not supported on client");
+ ERROR("oc_gatt send not supported on client");
#elif (MYNEWT_VAL(OC_SERVER) == 1)
oc_message_unref(message);
- ERROR("oc_transport_gatt: no multicast support for server only system \n");
+ ERROR("oc_gatt no multicast support for server only system \n");
#endif
}
[07/10] incubator-mynewt-core git commit: oic;
advertise host OS as mynewt in platform info.
Posted by ma...@apache.org.
oic; advertise host OS as mynewt in platform info.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4dd5a1f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4dd5a1f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4dd5a1f4
Branch: refs/heads/develop
Commit: 4dd5a1f4528a49cb9c9a2e870f4686e75da9a23e
Parents: 57df837
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 6 20:36:42 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 6 20:45:59 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_core_res.c | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4dd5a1f4/net/oic/src/api/oc_core_res.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_core_res.c b/net/oic/src/api/oc_core_res.c
index c3f4e66..5d908fc 100644
--- a/net/oic/src/api/oc_core_res.c
+++ b/net/oic/src/api/oc_core_res.c
@@ -232,6 +232,7 @@ oc_core_init_platform(const char *mfg_name, oc_core_init_platform_cb_t init_cb,
oc_uuid_to_str(&uuid, uuid_str, 37);
oc_rep_set_text_string(root, pi, uuid_str);
oc_rep_set_text_string(root, mnmn, mfg_name);
+ oc_rep_set_text_string(root, mnos, "MyNewt");
if (init_cb) {
init_cb(data);
[04/10] incubator-mynewt-core git commit: oic;
add parsing/encoding TCP like CoAP. Use this with BLE.
Posted by ma...@apache.org.
oic; add parsing/encoding TCP like CoAP. Use this with BLE.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3b8b6928
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3b8b6928
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3b8b6928
Branch: refs/heads/develop
Commit: 3b8b69283744cdec31c6537bccd21dbaa56cf455
Parents: 524a6ea
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Dec 2 17:49:22 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 6 20:45:59 2016 -0800
----------------------------------------------------------------------
net/oic/src/api/oc_client_api.c | 54 +++++-----
net/oic/src/api/oc_ri.c | 23 ++--
net/oic/src/api/oc_server_api.c | 2 +-
net/oic/src/messaging/coap/coap.c | 162 +++++++++++++++++++---------
net/oic/src/messaging/coap/coap.h | 4 +-
net/oic/src/messaging/coap/constants.h | 72 ++++++++++++-
net/oic/src/messaging/coap/engine.c | 14 ++-
net/oic/src/messaging/coap/observe.c | 3 +-
net/oic/src/messaging/coap/separate.c | 3 +-
net/oic/src/port/oc_connectivity.h | 10 ++
10 files changed, 247 insertions(+), 100 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b8b6928/net/oic/src/api/oc_client_api.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_client_api.c b/net/oic/src/api/oc_client_api.c
index 8122f17..0dce249 100644
--- a/net/oic/src/api/oc_client_api.c
+++ b/net/oic/src/api/oc_client_api.c
@@ -28,33 +28,35 @@ coap_packet_t request[1];
static bool
dispatch_coap_request(void)
{
- int response_length = oc_rep_finalize();
- if (!transaction) {
- if (message) {
- if (response_length) {
- coap_set_payload(request, message->data + COAP_MAX_HEADER_SIZE,
- response_length);
- coap_set_header_content_format(request, APPLICATION_CBOR);
- }
- message->length = coap_serialize_message(request, message->data);
- coap_send_message(message);
- message = 0;
- return true;
+ int response_length = oc_rep_finalize();
+ if (!transaction) {
+ if (message) {
+ if (response_length) {
+ coap_set_payload(request, message->data + COAP_MAX_HEADER_SIZE,
+ response_length);
+ coap_set_header_content_format(request, APPLICATION_CBOR);
+ }
+ message->length = coap_serialize_message(request, message->data,
+ oc_endpoint_use_tcp(&message->endpoint));
+ coap_send_message(message);
+ message = 0;
+ return true;
+ }
+ } else {
+ if (response_length) {
+ coap_set_payload(request,
+ transaction->message->data + COAP_MAX_HEADER_SIZE,
+ response_length);
+ coap_set_header_content_format(request, APPLICATION_CBOR);
+ }
+ transaction->message->length =
+ coap_serialize_message(request, transaction->message->data,
+ oc_endpoint_use_tcp(&transaction->message->endpoint));
+ coap_send_transaction(transaction);
+ transaction = 0;
+ return true;
}
- } else {
- if (response_length) {
- coap_set_payload(request,
- transaction->message->data + COAP_MAX_HEADER_SIZE,
- response_length);
- coap_set_header_content_format(request, APPLICATION_CBOR);
- }
- transaction->message->length =
- coap_serialize_message(request, transaction->message->data);
- coap_send_transaction(transaction);
- transaction = 0;
- return true;
- }
- return false;
+ return false;
}
static bool
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b8b6928/net/oic/src/api/oc_ri.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_ri.c b/net/oic/src/api/oc_ri.c
index da89d11..fae737c 100644
--- a/net/oic/src/api/oc_ri.c
+++ b/net/oic/src/api/oc_ri.c
@@ -696,17 +696,18 @@ bool
oc_ri_send_rst(oc_endpoint_t *endpoint, uint8_t *token, uint8_t token_len,
uint16_t mid)
{
- coap_packet_t rst[1];
- coap_init_message(rst, COAP_TYPE_RST, 0, mid);
- coap_set_header_observe(rst, 1);
- coap_set_token(rst, token, token_len);
- oc_message_t *message = oc_allocate_message();
- if (message) {
- message->length = coap_serialize_message(rst, message->data);
- coap_send_message(message);
- return true;
- }
- return false;
+ coap_packet_t rst[1];
+ coap_init_message(rst, COAP_TYPE_RST, 0, mid);
+ coap_set_header_observe(rst, 1);
+ coap_set_token(rst, token, token_len);
+ oc_message_t *message = oc_allocate_message();
+ if (message) {
+ message->length = coap_serialize_message(rst, message->data,
+ oc_endpoint_use_tcp(endpoint));
+ coap_send_message(message);
+ return true;
+ }
+ return false;
}
bool
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b8b6928/net/oic/src/api/oc_server_api.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_server_api.c b/net/oic/src/api/oc_server_api.c
index a45cc6f..9cdb4e1 100644
--- a/net/oic/src/api/oc_server_api.c
+++ b/net/oic/src/api/oc_server_api.c
@@ -260,7 +260,7 @@ oc_send_separate_response(oc_separate_response_t *handle,
}
t->type = response->type;
t->message->length = coap_serialize_message(response,
- t->message->data);
+ t->message->data, oc_endpoint_use_tcp(&cur->endpoint));
coap_send_transaction(t);
}
coap_separate_clear(handle, cur);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b8b6928/net/oic/src/messaging/coap/coap.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.c b/net/oic/src/messaging/coap/coap.c
index 5e490bd..470af9c 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -289,46 +289,27 @@ coap_init_message(coap_packet_t *pkt, coap_message_type_t type,
/*---------------------------------------------------------------------------*/
size_t
-coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer)
+coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer, int tcp_hdr)
{
struct coap_udp_hdr *cuh;
+ struct coap_tcp_hdr0 *cth0;
+ struct coap_tcp_hdr8 *cth8;
+ struct coap_tcp_hdr16 *cth16;
+ struct coap_tcp_hdr32 *cth32;
uint8_t *option;
unsigned int current_number = 0;
+ int len, data_len;
/* Initialize */
pkt->buffer = buffer;
pkt->version = 1;
- LOG("-Serializing MID %u to %p, ", pkt->mid, pkt->buffer);
-
- /* set header fields */
- cuh = (struct coap_udp_hdr *)pkt->buffer;
- cuh->version = pkt->version;
- cuh->type = pkt->type;
- cuh->token_len = pkt->token_len;
- cuh->code = pkt->code;
- cuh->id = htons(pkt->mid);
-
- /* empty packet, dont need to do more stuff */
- if (!pkt->code) {
- LOG("-Done serializing empty message at %p-\n", pkt->buffer);
- return 4;
- }
-
- /* set Token */
- LOG("Token (len %u)", pkt->token_len);
- option = pkt->buffer + COAP_HEADER_LEN;
- for (current_number = 0; current_number < pkt->token_len;
- ++current_number) {
- LOG(" %02X", pkt->token[current_number]);
- *option = pkt->token[current_number];
- ++option;
- }
- LOG("-\n");
+ LOG("-Serializing MID %u to %p, ", pkt->mid, buffer);
/* Serialize options */
current_number = 0;
+ option = buffer;
LOG("-Serializing options at %p-\n", option);
#if 0
/* The options must be serialized in the order of their number */
@@ -374,21 +355,68 @@ coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer)
LOG("-Done serializing at %p----\n", option);
- /* Pack payload */
- if ((option - pkt->buffer) <= COAP_MAX_HEADER_SIZE) {
- /* Payload marker */
- if (pkt->payload_len) {
- *option = 0xFF;
- ++option;
+ /* Payload marker */
+ if (pkt->payload_len) {
+ *option = 0xFF;
+ ++option;
+ }
+ len = option - buffer;
+ data_len = len + pkt->payload_len;
+
+ /* set header fields */
+ if (!tcp_hdr) {
+ if (len + sizeof(*cuh) + pkt->token_len > COAP_MAX_HEADER_SIZE) {
+ pkt->buffer = NULL;
+ coap_error_message = "Serialized header exceeds MAX_HEADER_SIZE";
+ return 0;
}
- memmove(option, pkt->payload, pkt->payload_len);
+ memmove(buffer + sizeof(*cuh) + pkt->token_len, buffer, len);
+ cuh = (struct coap_udp_hdr *)buffer;
+ cuh->version = pkt->version;
+ cuh->type = pkt->type;
+ cuh->token_len = pkt->token_len;
+ cuh->code = pkt->code;
+ cuh->id = htons(pkt->mid);
+ option = (uint8_t *)(cuh + 1);
} else {
- /* an error occurred: caller must check for !=0 */
- pkt->buffer = NULL;
- coap_error_message = "Serialized header exceeds COAP_MAX_HEADER_SIZE";
- return 0;
+ if (data_len < 13) {
+ memmove(buffer + sizeof(*cth0) + pkt->token_len, buffer, len);
+ cth0 = (struct coap_tcp_hdr0 *)buffer;
+ cth0->data_len = data_len;
+ cth0->token_len = pkt->token_len;
+ cth0->code = pkt->code;
+ option = (uint8_t *)(cth0 + 1);
+ } else if (data_len < 269) {
+ memmove(buffer + sizeof(*cth8) + pkt->token_len, buffer, len);
+ cth8 = (struct coap_tcp_hdr8 *)buffer;
+ cth8->type = COAP_TCP_TYPE8;
+ cth8->token_len = pkt->token_len;
+ cth8->data_len = data_len - 13;
+ cth8->code = pkt->code;
+ option = (uint8_t *)(cth8 + 1);
+ } else if (data_len < 65805) {
+ memmove(buffer + sizeof(*cth16) + pkt->token_len, buffer, len);
+ cth16 = (struct coap_tcp_hdr16 *)buffer;
+ cth16->type = COAP_TCP_TYPE16;
+ cth16->token_len = pkt->token_len;
+ cth16->data_len = htons(data_len - 269);
+ cth16->code = pkt->code;
+ option = (uint8_t *)(cth16 + 1);
+ } else {
+ memmove(buffer + sizeof(*cth32) + pkt->token_len, buffer, len);
+ cth32 = (struct coap_tcp_hdr32 *)buffer;
+ cth32->type = COAP_TCP_TYPE32;
+ cth32->token_len = pkt->token_len;
+ cth32->data_len = htonl(data_len - 65805);
+ cth32->code = pkt->code;
+ option = (uint8_t *)(cth32 + 1);
+ }
}
+ memcpy(option, pkt->token, pkt->token_len);
+ option += (len + pkt->token_len);
+ memmove(option, pkt->payload, pkt->payload_len);
+
LOG("-Done %u B (header len %u, payload len %u)-\n",
(unsigned int)(pkt->payload_len + option - buffer),
(unsigned int)(option - buffer), (unsigned int)pkt->payload_len);
@@ -409,9 +437,14 @@ coap_send_message(oc_message_t *message)
/*---------------------------------------------------------------------------*/
coap_status_t
-coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
+coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len,
+ int tcp_hdr)
{
struct coap_udp_hdr *udp;
+ struct coap_tcp_hdr0 *cth0;
+ struct coap_tcp_hdr8 *cth8;
+ struct coap_tcp_hdr16 *cth16;
+ struct coap_tcp_hdr32 *cth32;
uint8_t *cur_opt;
unsigned int opt_num = 0;
unsigned int opt_delta = 0;
@@ -423,24 +456,51 @@ coap_parse_message(coap_packet_t *pkt, uint8_t *data, uint16_t data_len)
pkt->buffer = data;
/* parse header fields */
- udp = (struct coap_udp_hdr *)data;
- pkt->version = udp->version;
- pkt->type = udp->type;
- pkt->token_len = udp->token_len;
- pkt->code = udp->code;
- pkt->mid = ntohs(udp->id);
-
- if (pkt->version != 1) {
- coap_error_message = "CoAP version must be 1";
- return BAD_REQUEST_4_00;
+ if (!tcp_hdr) {
+ udp = (struct coap_udp_hdr *)data;
+ pkt->version = udp->version;
+ pkt->type = udp->type;
+ pkt->token_len = udp->token_len;
+ pkt->code = udp->code;
+ pkt->mid = ntohs(udp->id);
+ if (pkt->version != 1) {
+ coap_error_message = "CoAP version must be 1";
+ return BAD_REQUEST_4_00;
+ }
+ cur_opt = (uint8_t *)(udp + 1);
+ } else {
+ /*
+ * We cannot just look at the data length, as token might or might
+ * not be present. Need to figure out which header is present
+ * programmatically.
+ */
+ cth0 = (struct coap_tcp_hdr0 *)data;
+ if (cth0->data_len < 13) {
+ pkt->token_len = cth0->token_len;
+ pkt->code = cth0->code;
+ cur_opt = (uint8_t *)(cth0 + 1);
+ } else if (cth0->data_len == 13) {
+ cth8 = (struct coap_tcp_hdr8 *)data;
+ pkt->token_len = cth8->token_len;
+ pkt->code = cth8->code;
+ cur_opt = (uint8_t *)(cth8 + 1);
+ } else if (cth0->data_len == 14) {
+ cth16 = (struct coap_tcp_hdr16 *)data;
+ pkt->token_len = cth16->token_len;
+ pkt->code = cth16->code;
+ cur_opt = (uint8_t *)(cth16 + 1);
+ } else {
+ cth32 = (struct coap_tcp_hdr32 *)data;
+ pkt->token_len = cth32->token_len;
+ pkt->code = cth32->code;
+ cur_opt = (uint8_t *)(cth32 + 1);
+ }
}
if (pkt->token_len > COAP_TOKEN_LEN) {
coap_error_message = "Token Length must not be more than 8";
return BAD_REQUEST_4_00;
}
- cur_opt = data + sizeof(*udp);
-
memcpy(pkt->token, cur_opt, pkt->token_len);
LOG("Token (len %u) [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n",
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b8b6928/net/oic/src/messaging/coap/coap.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.h b/net/oic/src/messaging/coap/coap.h
index 11377eb..987f34a 100644
--- a/net/oic/src/messaging/coap/coap.h
+++ b/net/oic/src/messaging/coap/coap.h
@@ -212,10 +212,10 @@ uint16_t coap_get_mid(void);
void coap_init_message(coap_packet_t *, coap_message_type_t type,
uint8_t code, uint16_t mid);
-size_t coap_serialize_message(coap_packet_t *, uint8_t *buffer);
+size_t coap_serialize_message(coap_packet_t *, uint8_t *buffer, int tcp_hdr);
void coap_send_message(oc_message_t *message);
coap_status_t coap_parse_message(coap_packet_t *request, uint8_t *data,
- uint16_t data_len);
+ uint16_t data_len, int tcp_hdr);
int coap_get_query_variable(coap_packet_t *, const char *name,
const char **output);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b8b6928/net/oic/src/messaging/coap/constants.h
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/constants.h b/net/oic/src/messaging/coap/constants.h
index e0c0f66..385df69 100644
--- a/net/oic/src/messaging/coap/constants.h
+++ b/net/oic/src/messaging/coap/constants.h
@@ -50,6 +50,9 @@ extern "C" {
#define COAP_TOKEN_LEN 8 /* The maximum number of bytes for the Token */
#define COAP_ETAG_LEN 8 /* The maximum number of bytes for the ETag */
+/*
+ * Standard COAP header
+ */
struct coap_udp_hdr {
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t version:2; /* protocol version */
@@ -60,10 +63,75 @@ struct coap_udp_hdr {
uint8_t type:2; /* type flag */
uint8_t version:2; /* protocol version */
#endif
- uint8_t code; /* request (1-10) or response (value 40-255) */
- uint16_t id; /* transaction id */
+ uint8_t code; /* request (1-10) or response (value 40-255) */
+ uint16_t id; /* transaction id */
+};
+
+/*
+ * Header used by Iotivity for TCP-like transports.
+ * 4 different kinds of headers.
+ */
+#define COAP_TCP_LENGTH_FIELD_8_BIT 13
+#define COAP_TCP_LENGTH_FIELD_16_BIT 269
+#define COAP_TCP_LENGTH_FIELD_32_BIT 65805
+
+#define COAP_TCP_TYPE0 0
+#define COAP_TCP_TYPE8 13
+#define COAP_TCP_TYPE16 14
+#define COAP_TCP_TYPE32 15
+
+struct coap_tcp_hdr0 {
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ uint8_t data_len:4; /* packet length */
+ uint8_t token_len:4; /* length of token */
+#else
+ uint8_t token_len:4; /* length of token */
+ uint8_t data_len:4; /* packet length */
+#endif
+ uint8_t code;
+};
+
+struct coap_tcp_hdr8 {
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ uint8_t type:4; /* header type == 13 */
+ uint8_t token_len:4; /* length of token */
+#else
+ uint8_t token_len:4; /* length of token */
+ uint8_t type:4; /* header type == 13*/
+#endif
+ uint8_t data_len; /* packet size - 13 */
+ uint8_t code;
};
+struct coap_tcp_hdr16 {
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ uint8_t type:4; /* header type == 14 */
+ uint8_t token_len:4; /* length of token */
+#else
+ uint8_t token_len:4; /* length of token */
+ uint8_t type:4; /* header type == 14 */
+#endif
+ uint16_t data_len; /* packet size - 269 */
+ uint8_t code;
+} __attribute__((packed));
+
+struct coap_tcp_hdr32 {
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ uint8_t type:4; /* header type == 15 */
+ uint8_t token_len:4; /* length of token */
+#else
+ uint8_t token_len:4; /* length of token */
+ uint8_t type:4; /* header type == 15*/
+#endif
+ uint32_t data_len; /* packet size - 65805 */
+ uint8_t code;
+} __attribute__((packed));
+
+#define COAP_TCP_TYPE8 13
+#define COAP_TCP_TYPE16 14
+#define COAP_TCP_TYPE32 15
+
+
#define COAP_HEADER_OPTION_DELTA_MASK 0xF0
#define COAP_HEADER_OPTION_SHORT_LENGTH_MASK 0x0F
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b8b6928/net/oic/src/messaging/coap/engine.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/engine.c b/net/oic/src/messaging/coap/engine.c
index 511b71c..009a2e3 100644
--- a/net/oic/src/messaging/coap/engine.c
+++ b/net/oic/src/messaging/coap/engine.c
@@ -66,7 +66,8 @@ coap_receive(oc_message_t *msg)
static coap_packet_t response[1];
static coap_transaction_t *transaction = NULL;
- erbium_status_code = coap_parse_message(message, msg->data, msg->length);
+ erbium_status_code = coap_parse_message(message, msg->data, msg->length,
+ oc_endpoint_use_tcp(&msg->endpoint));
if (erbium_status_code == NO_ERROR) {
@@ -220,7 +221,8 @@ coap_receive(oc_message_t *msg)
}
if (erbium_status_code == NO_ERROR) {
if ((transaction->message->length = coap_serialize_message(
- response, transaction->message->data)) == 0) {
+ response, transaction->message->data,
+ oc_endpoint_use_tcp(&msg->endpoint))) == 0) {
erbium_status_code = PACKET_SERIALIZATION_ERROR;
}
transaction->type = response->type;
@@ -264,7 +266,7 @@ coap_receive(oc_message_t *msg)
coap_send_transaction(transaction);
}
} else if (erbium_status_code == CLEAR_TRANSACTION) {
- LOG("Clearing transaction for manual response");
+ LOG("Clearing transaction for manual response\n");
coap_clear_transaction(transaction); // used in server for separate response
}
#ifdef OC_CLIENT
@@ -273,7 +275,8 @@ coap_receive(oc_message_t *msg)
oc_message_t *response = oc_allocate_message();
if (response) {
memcpy(&response->endpoint, &msg->endpoint, sizeof(msg->endpoint));
- response->length = coap_serialize_message(message, response->data);
+ response->length = coap_serialize_message(message, response->data,
+ oc_endpoint_use_tcp(&msg->endpoint));
coap_send_message(response);
}
}
@@ -290,7 +293,8 @@ coap_receive(oc_message_t *msg)
oc_message_t *response = oc_allocate_message();
if (response) {
memcpy(&response->endpoint, &msg->endpoint, sizeof(msg->endpoint));
- response->length = coap_serialize_message(message, response->data);
+ response->length = coap_serialize_message(message, response->data,
+ oc_endpoint_use_tcp(&response->endpoint));
coap_send_message(response);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b8b6928/net/oic/src/messaging/coap/observe.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.c b/net/oic/src/messaging/coap/observe.c
index 0202bb6..d6c5cba 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -297,7 +297,8 @@ coap_notify_observers(oc_resource_t *resource,
transaction->message->length =
coap_serialize_message(notification,
- transaction->message->data);
+ transaction->message->data,
+ oc_endpoint_use_tcp(&obs->endpoint));
transaction->type = notification->type;
coap_send_transaction(transaction);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b8b6928/net/oic/src/messaging/coap/separate.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/separate.c b/net/oic/src/messaging/coap/separate.c
index 015aa2d..757860e 100644
--- a/net/oic/src/messaging/coap/separate.c
+++ b/net/oic/src/messaging/coap/separate.c
@@ -105,7 +105,8 @@ coap_separate_accept(coap_packet_t *coap_req,
if (message != NULL) {
message->endpoint.flags = IP;
memcpy(&message->endpoint, endpoint, sizeof(oc_endpoint_t));
- message->length = coap_serialize_message(ack, message->data);
+ message->length = coap_serialize_message(ack, message->data,
+ oc_endpoint_use_tcp(&message->endpoint));
coap_send_message(message);
} else {
coap_separate_clear(separate_response, separate_store);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b8b6928/net/oic/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_connectivity.h b/net/oic/src/port/oc_connectivity.h
index 123db7c..f5a075e 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -73,6 +73,16 @@ uint16_t oc_connectivity_get_dtls_port(void);
int oc_connectivity_init(void);
void oc_connectivity_shutdown(void);
+static inline int
+oc_endpoint_use_tcp(struct oc_endpoint *oe)
+{
+ if (oe->flags & GATT) {
+ return 1;
+ }
+ return 0;
+}
+
+
void oc_send_buffer(struct os_mbuf *);
void oc_send_multicast_message(struct os_mbuf *);
[10/10] incubator-mynewt-core git commit: oic;
add back accidentally dropped include of oc_log.h.
Posted by ma...@apache.org.
oic; add back accidentally dropped include of oc_log.h.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/96a90d50
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/96a90d50
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/96a90d50
Branch: refs/heads/develop
Commit: 96a90d500ed5a6031475a1586a4aac9a92a949a9
Parents: d382b9c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 6 20:45:20 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 6 20:46:00 2016 -0800
----------------------------------------------------------------------
net/oic/src/port/mynewt/ip_adaptor.c | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/96a90d50/net/oic/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip_adaptor.c b/net/oic/src/port/mynewt/ip_adaptor.c
index 5bb73c9..7824260 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -29,6 +29,7 @@
#include <mn_socket/mn_socket.h>
#include "port/oc_connectivity.h"
+#include "oic/oc_log.h"
#include "oc_buffer.h"
#include "adaptor.h"
[03/10] incubator-mynewt-core git commit: bleprph_oic;
make calls to oic ble to notify it about connections. Advertise a
full UUID for OIC support.
Posted by ma...@apache.org.
bleprph_oic; make calls to oic ble to notify it about connections.
Advertise a full UUID for OIC support.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2822a9ca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2822a9ca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2822a9ca
Branch: refs/heads/develop
Commit: 2822a9ca9601c57d5d0458c054ee4857f6d03fe5
Parents: 183218f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 6 20:35:18 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 6 20:45:59 2016 -0800
----------------------------------------------------------------------
apps/bleprph_oic/src/main.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2822a9ca/apps/bleprph_oic/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph_oic/src/main.c b/apps/bleprph_oic/src/main.c
index 72e2f5e..2907639 100755
--- a/apps/bleprph_oic/src/main.c
+++ b/apps/bleprph_oic/src/main.c
@@ -38,7 +38,8 @@
/* Application-specified header. */
#include "bleprph.h"
-#include "oic/oc_gatt.h"
+#include <oic/oc_gatt.h>
+#include <oic/oc_log.h>
/** Log data. */
struct log bleprph_log;
@@ -121,9 +122,9 @@ bleprph_advertise(void)
fields.name_len = strlen(name);
fields.name_is_complete = 1;
- fields.uuids16 = (uint16_t[]){ GATT_SVR_SVC_ALERT_UUID, 0x1812 };
- fields.num_uuids16 = 2;
- fields.uuids16_is_complete = 1;
+ fields.uuids128 = (void *)oc_gatt_svc_uuid;
+ fields.num_uuids128 = 1;
+ fields.uuids128_is_complete = 1;
rc = ble_gap_adv_set_fields(&fields);
if (rc != 0) {
@@ -180,6 +181,8 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
if (event->connect.status != 0) {
/* Connection failed; resume advertising. */
bleprph_advertise();
+ } else {
+ oc_ble_coap_conn_new(event->connect.conn_handle);
}
return 0;
@@ -188,6 +191,8 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
bleprph_print_conn_desc(&event->disconnect.conn);
BLEPRPH_LOG(INFO, "\n");
+ oc_ble_coap_conn_del(event->disconnect.conn.conn_handle);
+
/* Connection terminated; resume advertising. */
bleprph_advertise();
return 0;
@@ -274,7 +279,7 @@ main(void)
int rc;
/* Set initial BLE device address. */
- memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0x0a, 0xf0, 0x0b, 0xa5, 0x0a}, 6);
+ memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0xfa, 0xcf, 0xac, 0xfa, 0xc0}, 6);
/* Initialize OS */
sysinit();
@@ -285,6 +290,9 @@ main(void)
/* Initialize the NimBLE host configuration. */
log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+ /* Initialize the OIC */
+ log_register("oic", &oc_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+
os_eventq_init(&bleprph_evq);
os_eventq_dflt_set(&bleprph_evq);
@@ -298,13 +306,13 @@ main(void)
mgmt_evq_set(&bleprph_evq);
ble_hs_evq_set(&bleprph_evq);
- ble_coap_gatt_srv_init();
+ oc_ble_coap_gatt_srv_init();
ble_hs_cfg.reset_cb = bleprph_on_reset;
ble_hs_cfg.sync_cb = bleprph_on_sync;
ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
/* Set the default device name. */
- rc = ble_svc_gap_device_name_set("pimple-bleprph");
+ rc = ble_svc_gap_device_name_set("pi");
assert(rc == 0);
/* Start the OS */
[02/10] incubator-mynewt-core git commit: oic; add debug log macro.
Posted by ma...@apache.org.
oic; add debug log macro.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/57df8376
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/57df8376
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/57df8376
Branch: refs/heads/develop
Commit: 57df8376decc113edf1f3a0ca057417c6a8069f1
Parents: 2822a9c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 6 20:36:14 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 6 20:45:59 2016 -0800
----------------------------------------------------------------------
net/oic/include/oic/oc_log.h | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/57df8376/net/oic/include/oic/oc_log.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_log.h b/net/oic/include/oic/oc_log.h
index e77575b..547f452 100644
--- a/net/oic/include/oic/oc_log.h
+++ b/net/oic/include/oic/oc_log.h
@@ -18,12 +18,13 @@
#define OC_LOG_H
#include <stdio.h>
-#include "mynewt/config.h"
+#include <log/log.h>
#ifdef __cplusplus
extern "C" {
#endif
+
#define PRINT(...) printf(__VA_ARGS__)
#define PRINTipaddr(endpoint) \
@@ -58,22 +59,11 @@ extern "C" {
LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY, "%s", tmp_buf); \
}
-#if defined(ARCH_sim)
-#define LOG(...) PRINT(__VA_ARGS__)
-#define ERROR(...) LOG(__VA_ARGS__)
-#define LOGipaddr(endpoint) PRINTipaddr(endpoint)
-#define oc_log_init() 0
-#elif defined(DEBUG)
-int oc_log_init(void);
+extern struct log oc_log;
+#define OC_LOG_DEBUG(...) LOG_DEBUG(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
#define LOG(...) LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
#define ERROR(...) LOG_ERROR(&oc_log, LOG_MODULE_IOTIVITY,__VA_ARGS__)
#define LOGipaddr(endpoint) LogMynewtipaddr(endpoint)
-#else
-#define LOG(...)
-#define ERROR(...)
-#define LOGipaddr(endpoint)
-#define oc_log_init() 0
-#endif
#ifdef __cplusplus
}