samples: net: Convert to use generic logging macros
Use generic logging macros LOG_*() instead of NET_*() as the latter are mostly meant for internal networking stack use. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
86689030e8
commit
cd4eb946c4
47 changed files with 764 additions and 764 deletions
|
|
@ -43,7 +43,7 @@ static int dump_payload(const struct coap_packet *response)
|
||||||
|
|
||||||
frag = coap_packet_get_payload(response, &offset, &len);
|
frag = coap_packet_get_payload(response, &offset, &len);
|
||||||
if (!frag && len == 0xffff) {
|
if (!frag && len == 0xffff) {
|
||||||
NET_ERR("Invalid payload");
|
LOG_ERR("Invalid payload");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,7 +70,7 @@ static void udp_receive(struct net_context *context,
|
||||||
|
|
||||||
r = coap_packet_parse(&response, pkt, NULL, 0);
|
r = coap_packet_parse(&response, pkt, NULL, 0);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Invalid data received (%d)\n", r);
|
LOG_ERR("Invalid data received (%d)\n", r);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +101,7 @@ static void send_coap_request(u8_t method)
|
||||||
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
||||||
*p, strlen(*p));
|
*p, strlen(*p));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Unable add option to request");
|
LOG_ERR("Unable add option to request");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -114,14 +114,14 @@ static void send_coap_request(u8_t method)
|
||||||
case COAP_METHOD_POST:
|
case COAP_METHOD_POST:
|
||||||
r = coap_packet_append_payload_marker(&request);
|
r = coap_packet_append_payload_marker(&request);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Unable to append payload marker");
|
LOG_ERR("Unable to append payload marker");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = coap_packet_append_payload(&request, (u8_t *)payload,
|
r = coap_packet_append_payload(&request, (u8_t *)payload,
|
||||||
sizeof(payload) - 1);
|
sizeof(payload) - 1);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Not able to append payload");
|
LOG_ERR("Not able to append payload");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +132,7 @@ static void send_coap_request(u8_t method)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_ERR("Error sending the packet (%d)", r);
|
LOG_ERR("Error sending the packet (%d)", r);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
|
|
@ -145,21 +145,21 @@ static int init_app(void)
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, CONFIG_NET_CONFIG_MY_IPV6_ADDR,
|
if (net_addr_pton(AF_INET6, CONFIG_NET_CONFIG_MY_IPV6_ADDR,
|
||||||
&my_addr.sin6_addr)) {
|
&my_addr.sin6_addr)) {
|
||||||
NET_ERR("Invalid my IPv6 address: %s",
|
LOG_ERR("Invalid my IPv6 address: %s",
|
||||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR);
|
CONFIG_NET_CONFIG_MY_IPV6_ADDR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, CONFIG_NET_CONFIG_PEER_IPV6_ADDR,
|
if (net_addr_pton(AF_INET6, CONFIG_NET_CONFIG_PEER_IPV6_ADDR,
|
||||||
&peer_addr.sin6_addr)) {
|
&peer_addr.sin6_addr)) {
|
||||||
NET_ERR("Invalid peer IPv6 address: %s",
|
LOG_ERR("Invalid peer IPv6 address: %s",
|
||||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR);
|
CONFIG_NET_CONFIG_PEER_IPV6_ADDR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_get(PF_INET6, SOCK_DGRAM, IPPROTO_UDP, &context);
|
r = net_context_get(PF_INET6, SOCK_DGRAM, IPPROTO_UDP, &context);
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not get an UDP context");
|
LOG_ERR("Could not get an UDP context");
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,13 +168,13 @@ static int init_app(void)
|
||||||
r = net_context_bind(context, (struct sockaddr *) &my_addr,
|
r = net_context_bind(context, (struct sockaddr *) &my_addr,
|
||||||
sizeof(my_addr));
|
sizeof(my_addr));
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not bind the context");
|
LOG_ERR("Could not bind the context");
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_recv(context, udp_receive, 0, NULL);
|
r = net_context_recv(context, udp_receive, 0, NULL);
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not set receive callback");
|
LOG_ERR("Could not set receive callback");
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,22 +191,22 @@ void main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test CoAP GET method */
|
/* Test CoAP GET method */
|
||||||
NET_DBG("CoAP client GET test");
|
LOG_DBG("CoAP client GET test");
|
||||||
send_coap_request(COAP_METHOD_GET);
|
send_coap_request(COAP_METHOD_GET);
|
||||||
|
|
||||||
/* Take semaphore */
|
/* Take semaphore */
|
||||||
k_sem_take(&coap_sem, K_FOREVER);
|
k_sem_take(&coap_sem, K_FOREVER);
|
||||||
|
|
||||||
/* Test CoAP PUT method */
|
/* Test CoAP PUT method */
|
||||||
NET_DBG("CoAP client PUT test");
|
LOG_DBG("CoAP client PUT test");
|
||||||
send_coap_request(COAP_METHOD_PUT);
|
send_coap_request(COAP_METHOD_PUT);
|
||||||
|
|
||||||
/* Take semaphore */
|
/* Take semaphore */
|
||||||
k_sem_take(&coap_sem, K_FOREVER);
|
k_sem_take(&coap_sem, K_FOREVER);
|
||||||
|
|
||||||
/* Test CoAP POST method*/
|
/* Test CoAP POST method*/
|
||||||
NET_DBG("CoAP client POST test");
|
LOG_DBG("CoAP client POST test");
|
||||||
send_coap_request(COAP_METHOD_POST);
|
send_coap_request(COAP_METHOD_POST);
|
||||||
|
|
||||||
NET_DBG("Done");
|
LOG_DBG("Done");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ static int well_known_core_get(struct coap_resource *resource,
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
NET_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(context, K_FOREVER);
|
pkt = net_pkt_get_tx(context, K_FOREVER);
|
||||||
frag = net_pkt_get_data(context, K_FOREVER);
|
frag = net_pkt_get_data(context, K_FOREVER);
|
||||||
|
|
@ -142,9 +142,9 @@ static int test_del(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
LOG_INF("type: %u code %u id %u\n", type, code, id);
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(context, K_FOREVER);
|
pkt = net_pkt_get_tx(context, K_FOREVER);
|
||||||
frag = net_pkt_get_data(context, K_FOREVER);
|
frag = net_pkt_get_data(context, K_FOREVER);
|
||||||
|
|
@ -195,18 +195,18 @@ static int test_put(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("\n ****** test put method *******\n");
|
LOG_INF("\n ****** test put method *******\n");
|
||||||
|
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
LOG_INF("type: %u code %u id %u\n", type, code, id);
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
|
|
||||||
payloadfrag = coap_packet_get_payload(request, &offset, &len);
|
payloadfrag = coap_packet_get_payload(request, &offset, &len);
|
||||||
if (!payloadfrag && len == 0xffff) {
|
if (!payloadfrag && len == 0xffff) {
|
||||||
NET_ERR("Invalid payload");
|
LOG_ERR("Invalid payload");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
} else if (!payloadfrag && !len) {
|
} else if (!payloadfrag && !len) {
|
||||||
NET_INFO("Packet without payload\n");
|
LOG_INF("Packet without payload\n");
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -267,17 +267,17 @@ static int test_post(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("\n ****** test post method *******\n");
|
LOG_INF("\n ****** test post method *******\n");
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
LOG_INF("type: %u code %u id %u\n", type, code, id);
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
|
|
||||||
payloadfrag = coap_packet_get_payload(request, &offset, &len);
|
payloadfrag = coap_packet_get_payload(request, &offset, &len);
|
||||||
if (!payloadfrag && len == 0xffff) {
|
if (!payloadfrag && len == 0xffff) {
|
||||||
NET_ERR("Invalid payload");
|
LOG_ERR("Invalid payload");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
} else if (!payloadfrag && !len) {
|
} else if (!payloadfrag && !len) {
|
||||||
NET_INFO("Packet without payload\n");
|
LOG_INF("Packet without payload\n");
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -341,9 +341,9 @@ static int location_query_post(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
LOG_INF("type: %u code %u id %u\n", type, code, id);
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(context, K_FOREVER);
|
pkt = net_pkt_get_tx(context, K_FOREVER);
|
||||||
frag = net_pkt_get_data(context, K_FOREVER);
|
frag = net_pkt_get_data(context, K_FOREVER);
|
||||||
|
|
@ -396,9 +396,9 @@ static int piggyback_get(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
LOG_INF("type: %u code %u id %u\n", type, code, id);
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(context, K_FOREVER);
|
pkt = net_pkt_get_tx(context, K_FOREVER);
|
||||||
frag = net_pkt_get_data(context, K_FOREVER);
|
frag = net_pkt_get_data(context, K_FOREVER);
|
||||||
|
|
@ -477,15 +477,15 @@ static int query_get(struct coap_resource *resource,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
LOG_INF("type: %u code %u id %u\n", type, code, id);
|
||||||
NET_INFO("num queries: %d\n", r);
|
LOG_INF("num queries: %d\n", r);
|
||||||
|
|
||||||
for (i = 0; i < r; i++) {
|
for (i = 0; i < r; i++) {
|
||||||
char str[16];
|
char str[16];
|
||||||
|
|
||||||
if (options[i].len + 1 > sizeof(str)) {
|
if (options[i].len + 1 > sizeof(str)) {
|
||||||
NET_INFO("Unexpected length of query: "
|
LOG_INF("Unexpected length of query: "
|
||||||
"%d (expected %zu)\n",
|
"%d (expected %zu)\n",
|
||||||
options[i].len, sizeof(str));
|
options[i].len, sizeof(str));
|
||||||
break;
|
break;
|
||||||
|
|
@ -494,10 +494,10 @@ static int query_get(struct coap_resource *resource,
|
||||||
memcpy(str, options[i].value, options[i].len);
|
memcpy(str, options[i].value, options[i].len);
|
||||||
str[options[i].len] = '\0';
|
str[options[i].len] = '\0';
|
||||||
|
|
||||||
NET_INFO("query[%d]: %s\n", i + 1, log_strdup(str));
|
LOG_INF("query[%d]: %s\n", i + 1, log_strdup(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(context, K_FOREVER);
|
pkt = net_pkt_get_tx(context, K_FOREVER);
|
||||||
frag = net_pkt_get_data(context, K_FOREVER);
|
frag = net_pkt_get_data(context, K_FOREVER);
|
||||||
|
|
@ -564,9 +564,9 @@ static int separate_get(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
LOG_INF("type: %u code %u id %u\n", type, code, id);
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
|
|
||||||
if (type == COAP_TYPE_NON_CON) {
|
if (type == COAP_TYPE_NON_CON) {
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -697,9 +697,9 @@ static int large_get(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
LOG_INF("type: %u code %u id %u\n", type, code, id);
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(context, K_FOREVER);
|
pkt = net_pkt_get_tx(context, K_FOREVER);
|
||||||
frag = net_pkt_get_data(context, K_FOREVER);
|
frag = net_pkt_get_data(context, K_FOREVER);
|
||||||
|
|
@ -796,21 +796,21 @@ static int large_update_put(struct coap_resource *resource,
|
||||||
|
|
||||||
r = coap_update_from_block(request, &ctx);
|
r = coap_update_from_block(request, &ctx);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Invalid block size option from request");
|
LOG_ERR("Invalid block size option from request");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = coap_packet_get_payload(request, &offset, &len);
|
frag = coap_packet_get_payload(request, &offset, &len);
|
||||||
if (!last_block && frag == NULL && len == 0) {
|
if (!last_block && frag == NULL && len == 0) {
|
||||||
NET_ERR("Packet without payload\n");
|
LOG_ERR("Packet without payload\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("**************\n");
|
LOG_INF("**************\n");
|
||||||
NET_INFO("[ctx] current %zu block_size %u total_size %zu\n",
|
LOG_INF("[ctx] current %zu block_size %u total_size %zu\n",
|
||||||
ctx.current, coap_block_size_to_bytes(ctx.block_size),
|
ctx.current, coap_block_size_to_bytes(ctx.block_size),
|
||||||
ctx.total_size);
|
ctx.total_size);
|
||||||
NET_INFO("**************\n");
|
LOG_INF("**************\n");
|
||||||
|
|
||||||
get_from_ip_addr(request, &from);
|
get_from_ip_addr(request, &from);
|
||||||
code = coap_header_get_code(request);
|
code = coap_header_get_code(request);
|
||||||
|
|
@ -818,9 +818,9 @@ static int large_update_put(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
LOG_INF("type: %u code %u id %u\n", type, code, id);
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
|
|
||||||
/* Do something with the payload */
|
/* Do something with the payload */
|
||||||
|
|
||||||
|
|
@ -843,7 +843,7 @@ static int large_update_put(struct coap_resource *resource,
|
||||||
|
|
||||||
r = coap_append_block1_option(&response, &ctx);
|
r = coap_append_block1_option(&response, &ctx);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Could not add Block1 option to response");
|
LOG_ERR("Could not add Block1 option to response");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -881,13 +881,13 @@ static int large_create_post(struct coap_resource *resource,
|
||||||
|
|
||||||
r = coap_update_from_block(request, &ctx);
|
r = coap_update_from_block(request, &ctx);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Invalid block size option from request");
|
LOG_ERR("Invalid block size option from request");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = coap_packet_get_payload(request, &offset, &len);
|
frag = coap_packet_get_payload(request, &offset, &len);
|
||||||
if (!last_block && frag == NULL && len == 0) {
|
if (!last_block && frag == NULL && len == 0) {
|
||||||
NET_ERR("Packet without payload\n");
|
LOG_ERR("Packet without payload\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -897,9 +897,9 @@ static int large_create_post(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
LOG_INF("type: %u code %u id %u\n", type, code, id);
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(context, K_FOREVER);
|
pkt = net_pkt_get_tx(context, K_FOREVER);
|
||||||
frag = net_pkt_get_data(context, K_FOREVER);
|
frag = net_pkt_get_data(context, K_FOREVER);
|
||||||
|
|
@ -919,7 +919,7 @@ static int large_create_post(struct coap_resource *resource,
|
||||||
|
|
||||||
r = coap_append_block1_option(&response, &ctx);
|
r = coap_append_block1_option(&response, &ctx);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Could not add Block1 option to response");
|
LOG_ERR("Could not add Block1 option to response");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1061,9 +1061,9 @@ done:
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
NET_INFO("type: %u code %u id %u\n", type, code, id);
|
LOG_INF("type: %u code %u id %u\n", type, code, id);
|
||||||
NET_INFO("*******\n");
|
LOG_INF("*******\n");
|
||||||
|
|
||||||
return send_notification_packet((const struct sockaddr *)&from,
|
return send_notification_packet((const struct sockaddr *)&from,
|
||||||
observe ? resource->age : 0,
|
observe ? resource->age : 0,
|
||||||
|
|
@ -1241,7 +1241,7 @@ static void udp_receive(struct net_context *context,
|
||||||
|
|
||||||
r = coap_packet_parse(&request, pkt, options, opt_num);
|
r = coap_packet_parse(&request, pkt, options, opt_num);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Invalid data received (%d)\n", r);
|
LOG_ERR("Invalid data received (%d)\n", r);
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1260,13 +1260,13 @@ static void udp_receive(struct net_context *context,
|
||||||
o = coap_find_observer_by_addr(observers, NUM_OBSERVERS,
|
o = coap_find_observer_by_addr(observers, NUM_OBSERVERS,
|
||||||
(struct sockaddr *)&from);
|
(struct sockaddr *)&from);
|
||||||
if (!o) {
|
if (!o) {
|
||||||
NET_ERR("Observer not found\n");
|
LOG_ERR("Observer not found\n");
|
||||||
goto not_found;
|
goto not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = find_resouce_by_observer(resources, o);
|
r = find_resouce_by_observer(resources, o);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
NET_ERR("Observer found but Resource not found\n");
|
LOG_ERR("Observer found but Resource not found\n");
|
||||||
goto not_found;
|
goto not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1279,7 +1279,7 @@ static void udp_receive(struct net_context *context,
|
||||||
not_found:
|
not_found:
|
||||||
r = coap_handle_request(&request, resources, options, opt_num);
|
r = coap_handle_request(&request, resources, options, opt_num);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("No handler for such request (%d)\n", r);
|
LOG_ERR("No handler for such request (%d)\n", r);
|
||||||
}
|
}
|
||||||
|
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
|
|
@ -1298,7 +1298,7 @@ static bool join_coap_multicast_group(void)
|
||||||
|
|
||||||
iface = net_if_get_default();
|
iface = net_if_get_default();
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
NET_ERR("Could not get te default interface\n");
|
LOG_ERR("Could not get te default interface\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1306,14 +1306,14 @@ static bool join_coap_multicast_group(void)
|
||||||
if (net_addr_pton(AF_INET6,
|
if (net_addr_pton(AF_INET6,
|
||||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR,
|
CONFIG_NET_CONFIG_MY_IPV6_ADDR,
|
||||||
&my_addr) < 0) {
|
&my_addr) < 0) {
|
||||||
NET_ERR("Invalid IPv6 address %s",
|
LOG_ERR("Invalid IPv6 address %s",
|
||||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR);
|
CONFIG_NET_CONFIG_MY_IPV6_ADDR);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ifaddr = net_if_ipv6_addr_add(iface, &my_addr, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv6_addr_add(iface, &my_addr, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Could not add unicast address to interface");
|
LOG_ERR("Could not add unicast address to interface");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1321,7 +1321,7 @@ static bool join_coap_multicast_group(void)
|
||||||
|
|
||||||
mcast = net_if_ipv6_maddr_add(iface, &mcast_addr.sin6_addr);
|
mcast = net_if_ipv6_maddr_add(iface, &mcast_addr.sin6_addr);
|
||||||
if (!mcast) {
|
if (!mcast) {
|
||||||
NET_ERR("Could not add multicast address to interface\n");
|
LOG_ERR("Could not add multicast address to interface\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1369,20 +1369,20 @@ void main(void)
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!join_coap_multicast_group()) {
|
if (!join_coap_multicast_group()) {
|
||||||
NET_ERR("Could not join CoAP multicast group\n");
|
LOG_ERR("Could not join CoAP multicast group\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_get(PF_INET6, SOCK_DGRAM, IPPROTO_UDP, &context);
|
r = net_context_get(PF_INET6, SOCK_DGRAM, IPPROTO_UDP, &context);
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not get an UDP context\n");
|
LOG_ERR("Could not get an UDP context\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_bind(context, (struct sockaddr *) &any_addr,
|
r = net_context_bind(context, (struct sockaddr *) &any_addr,
|
||||||
sizeof(any_addr));
|
sizeof(any_addr));
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not bind the context\n");
|
LOG_ERR("Could not bind the context\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1393,7 +1393,7 @@ void main(void)
|
||||||
|
|
||||||
r = net_context_recv(context, udp_receive, 0, NULL);
|
r = net_context_recv(context, udp_receive, 0, NULL);
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not receive in the context\n");
|
LOG_ERR("Could not receive in the context\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,20 +40,20 @@ static void handler(struct net_mgmt_event_callback *cb,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("Your address: %s",
|
LOG_INF("Your address: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET,
|
log_strdup(net_addr_ntop(AF_INET,
|
||||||
&iface->config.ip.ipv4->unicast[i].address.in_addr,
|
&iface->config.ip.ipv4->unicast[i].address.in_addr,
|
||||||
buf, sizeof(buf))));
|
buf, sizeof(buf))));
|
||||||
NET_INFO("Lease time: %u seconds",
|
LOG_INF("Lease time: %u seconds",
|
||||||
iface->config.dhcpv4.lease_time);
|
iface->config.dhcpv4.lease_time);
|
||||||
NET_INFO("Subnet: %s",
|
LOG_INF("Subnet: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET,
|
log_strdup(net_addr_ntop(AF_INET,
|
||||||
&iface->config.ip.ipv4->netmask,
|
&iface->config.ip.ipv4->netmask,
|
||||||
buf, sizeof(buf))));
|
buf, sizeof(buf))));
|
||||||
NET_INFO("Router: %s",
|
LOG_INF("Router: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET,
|
log_strdup(net_addr_ntop(AF_INET,
|
||||||
&iface->config.ip.ipv4->gw,
|
&iface->config.ip.ipv4->gw,
|
||||||
buf, sizeof(buf))));
|
buf, sizeof(buf))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ void main(void)
|
||||||
{
|
{
|
||||||
struct net_if *iface;
|
struct net_if *iface;
|
||||||
|
|
||||||
NET_INFO("Run dhcpv4 client");
|
LOG_INF("Run dhcpv4 client");
|
||||||
|
|
||||||
net_mgmt_init_event_callback(&mgmt_cb, handler,
|
net_mgmt_init_event_callback(&mgmt_cb, handler,
|
||||||
NET_EVENT_IPV4_ADDR_ADD);
|
NET_EVENT_IPV4_ADDR_ADD);
|
||||||
|
|
|
||||||
|
|
@ -40,21 +40,21 @@ void dns_result_cb(enum dns_resolve_status status,
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case DNS_EAI_CANCELED:
|
case DNS_EAI_CANCELED:
|
||||||
NET_INFO("DNS query was canceled");
|
LOG_INF("DNS query was canceled");
|
||||||
return;
|
return;
|
||||||
case DNS_EAI_FAIL:
|
case DNS_EAI_FAIL:
|
||||||
NET_INFO("DNS resolve failed");
|
LOG_INF("DNS resolve failed");
|
||||||
return;
|
return;
|
||||||
case DNS_EAI_NODATA:
|
case DNS_EAI_NODATA:
|
||||||
NET_INFO("Cannot resolve address");
|
LOG_INF("Cannot resolve address");
|
||||||
return;
|
return;
|
||||||
case DNS_EAI_ALLDONE:
|
case DNS_EAI_ALLDONE:
|
||||||
NET_INFO("DNS resolving finished");
|
LOG_INF("DNS resolving finished");
|
||||||
return;
|
return;
|
||||||
case DNS_EAI_INPROGRESS:
|
case DNS_EAI_INPROGRESS:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
NET_INFO("DNS resolving error (%d)", status);
|
LOG_INF("DNS resolving error (%d)", status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,14 +79,14 @@ void dns_result_cb(enum dns_resolve_status status,
|
||||||
k_delayed_work_submit(&mdns_ipv6_timer, 0);
|
k_delayed_work_submit(&mdns_ipv6_timer, 0);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
NET_ERR("Invalid IP address family %d", info->ai_family);
|
LOG_ERR("Invalid IP address family %d", info->ai_family);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("%s %s address: %s", user_data ? (char *)user_data : "<null>",
|
LOG_INF("%s %s address: %s", user_data ? (char *)user_data : "<null>",
|
||||||
hr_family,
|
hr_family,
|
||||||
log_strdup(net_addr_ntop(info->ai_family, addr,
|
log_strdup(net_addr_ntop(info->ai_family, addr,
|
||||||
hr_addr, sizeof(hr_addr))));
|
hr_addr, sizeof(hr_addr))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mdns_result_cb(enum dns_resolve_status status,
|
void mdns_result_cb(enum dns_resolve_status status,
|
||||||
|
|
@ -99,21 +99,21 @@ void mdns_result_cb(enum dns_resolve_status status,
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case DNS_EAI_CANCELED:
|
case DNS_EAI_CANCELED:
|
||||||
NET_INFO("DNS query was canceled");
|
LOG_INF("DNS query was canceled");
|
||||||
return;
|
return;
|
||||||
case DNS_EAI_FAIL:
|
case DNS_EAI_FAIL:
|
||||||
NET_INFO("DNS resolve failed");
|
LOG_INF("DNS resolve failed");
|
||||||
return;
|
return;
|
||||||
case DNS_EAI_NODATA:
|
case DNS_EAI_NODATA:
|
||||||
NET_INFO("Cannot resolve address");
|
LOG_INF("Cannot resolve address");
|
||||||
return;
|
return;
|
||||||
case DNS_EAI_ALLDONE:
|
case DNS_EAI_ALLDONE:
|
||||||
NET_INFO("DNS resolving finished");
|
LOG_INF("DNS resolving finished");
|
||||||
return;
|
return;
|
||||||
case DNS_EAI_INPROGRESS:
|
case DNS_EAI_INPROGRESS:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
NET_INFO("DNS resolving error (%d)", status);
|
LOG_INF("DNS resolving error (%d)", status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,14 +128,14 @@ void mdns_result_cb(enum dns_resolve_status status,
|
||||||
hr_family = "IPv6";
|
hr_family = "IPv6";
|
||||||
addr = &net_sin6(&info->ai_addr)->sin6_addr;
|
addr = &net_sin6(&info->ai_addr)->sin6_addr;
|
||||||
} else {
|
} else {
|
||||||
NET_ERR("Invalid IP address family %d", info->ai_family);
|
LOG_ERR("Invalid IP address family %d", info->ai_family);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("%s %s address: %s", user_data ? (char *)user_data : "<null>",
|
LOG_INF("%s %s address: %s", user_data ? (char *)user_data : "<null>",
|
||||||
hr_family,
|
hr_family,
|
||||||
log_strdup(net_addr_ntop(info->ai_family, addr,
|
log_strdup(net_addr_ntop(info->ai_family, addr,
|
||||||
hr_addr, sizeof(hr_addr))));
|
hr_addr, sizeof(hr_addr))));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_DHCPV4)
|
#if defined(CONFIG_NET_DHCPV4)
|
||||||
|
|
@ -155,11 +155,11 @@ static void do_ipv4_lookup(struct k_work *work)
|
||||||
(void *)query,
|
(void *)query,
|
||||||
DNS_TIMEOUT);
|
DNS_TIMEOUT);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot resolve IPv4 address (%d)", ret);
|
LOG_ERR("Cannot resolve IPv4 address (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("DNS id %u", dns_id);
|
LOG_DBG("DNS id %u", dns_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
|
static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
|
||||||
|
|
@ -181,18 +181,18 @@ static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("IPv4 address: %s",
|
LOG_INF("IPv4 address: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET,
|
log_strdup(net_addr_ntop(AF_INET,
|
||||||
&if_addr->address.in_addr,
|
&if_addr->address.in_addr,
|
||||||
hr_addr, NET_IPV4_ADDR_LEN)));
|
hr_addr, NET_IPV4_ADDR_LEN)));
|
||||||
NET_INFO("Lease time: %u seconds",
|
LOG_INF("Lease time: %u seconds",
|
||||||
iface->config.dhcpv4.lease_time);
|
iface->config.dhcpv4.lease_time);
|
||||||
NET_INFO("Subnet: %s",
|
LOG_INF("Subnet: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET,
|
log_strdup(net_addr_ntop(AF_INET,
|
||||||
&iface->config.ip.ipv4->netmask,
|
&iface->config.ip.ipv4->netmask,
|
||||||
hr_addr, NET_IPV4_ADDR_LEN)));
|
hr_addr, NET_IPV4_ADDR_LEN)));
|
||||||
NET_INFO("Router: %s",
|
LOG_INF("Router: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET,
|
log_strdup(net_addr_ntop(AF_INET,
|
||||||
&iface->config.ip.ipv4->gw,
|
&iface->config.ip.ipv4->gw,
|
||||||
hr_addr, NET_IPV4_ADDR_LEN)));
|
hr_addr, NET_IPV4_ADDR_LEN)));
|
||||||
break;
|
break;
|
||||||
|
|
@ -208,7 +208,7 @@ static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
|
||||||
|
|
||||||
static void setup_dhcpv4(struct net_if *iface)
|
static void setup_dhcpv4(struct net_if *iface)
|
||||||
{
|
{
|
||||||
NET_INFO("Getting IPv4 address via DHCP before issuing DNS query");
|
LOG_INF("Getting IPv4 address via DHCP before issuing DNS query");
|
||||||
|
|
||||||
net_mgmt_init_event_callback(&mgmt4_cb, ipv4_addr_add_handler,
|
net_mgmt_init_event_callback(&mgmt4_cb, ipv4_addr_add_handler,
|
||||||
NET_EVENT_IPV4_ADDR_ADD);
|
NET_EVENT_IPV4_ADDR_ADD);
|
||||||
|
|
@ -229,7 +229,7 @@ static void do_mdns_ipv4_lookup(struct k_work *work)
|
||||||
u16_t dns_id;
|
u16_t dns_id;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
NET_DBG("Doing mDNS IPv4 query");
|
LOG_DBG("Doing mDNS IPv4 query");
|
||||||
|
|
||||||
ret = dns_get_addr_info(query,
|
ret = dns_get_addr_info(query,
|
||||||
DNS_QUERY_TYPE_A,
|
DNS_QUERY_TYPE_A,
|
||||||
|
|
@ -238,11 +238,11 @@ static void do_mdns_ipv4_lookup(struct k_work *work)
|
||||||
(void *)query,
|
(void *)query,
|
||||||
DNS_TIMEOUT);
|
DNS_TIMEOUT);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot resolve mDNS IPv4 address (%d)", ret);
|
LOG_ERR("Cannot resolve mDNS IPv4 address (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("mDNS id %u", dns_id);
|
LOG_DBG("mDNS id %u", dns_id);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -262,15 +262,15 @@ static void setup_ipv4(struct net_if *iface)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET, CONFIG_NET_CONFIG_MY_IPV4_ADDR, &addr)) {
|
if (net_addr_pton(AF_INET, CONFIG_NET_CONFIG_MY_IPV4_ADDR, &addr)) {
|
||||||
NET_ERR("Invalid address: %s", CONFIG_NET_CONFIG_MY_IPV4_ADDR);
|
LOG_ERR("Invalid address: %s", CONFIG_NET_CONFIG_MY_IPV4_ADDR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
net_if_ipv4_addr_add(iface, &addr, NET_ADDR_MANUAL, 0);
|
net_if_ipv4_addr_add(iface, &addr, NET_ADDR_MANUAL, 0);
|
||||||
|
|
||||||
NET_INFO("IPv4 address: %s",
|
LOG_INF("IPv4 address: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET, &addr, hr_addr,
|
log_strdup(net_addr_ntop(AF_INET, &addr, hr_addr,
|
||||||
NET_IPV4_ADDR_LEN)));
|
NET_IPV4_ADDR_LEN)));
|
||||||
|
|
||||||
ret = dns_get_addr_info(query,
|
ret = dns_get_addr_info(query,
|
||||||
DNS_QUERY_TYPE_A,
|
DNS_QUERY_TYPE_A,
|
||||||
|
|
@ -279,11 +279,11 @@ static void setup_ipv4(struct net_if *iface)
|
||||||
(void *)query,
|
(void *)query,
|
||||||
DNS_TIMEOUT);
|
DNS_TIMEOUT);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot resolve IPv4 address (%d)", ret);
|
LOG_ERR("Cannot resolve IPv4 address (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("DNS id %u", dns_id);
|
LOG_DBG("DNS id %u", dns_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
@ -309,11 +309,11 @@ static void do_ipv6_lookup(void)
|
||||||
(void *)query,
|
(void *)query,
|
||||||
DNS_TIMEOUT);
|
DNS_TIMEOUT);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot resolve IPv6 address (%d)", ret);
|
LOG_ERR("Cannot resolve IPv6 address (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("DNS id %u", dns_id);
|
LOG_DBG("DNS id %u", dns_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup_ipv6(struct net_if *iface)
|
static void setup_ipv6(struct net_if *iface)
|
||||||
|
|
@ -328,7 +328,7 @@ static void do_mdns_ipv6_lookup(struct k_work *work)
|
||||||
u16_t dns_id;
|
u16_t dns_id;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
NET_DBG("Doing mDNS IPv6 query");
|
LOG_DBG("Doing mDNS IPv6 query");
|
||||||
|
|
||||||
ret = dns_get_addr_info(query,
|
ret = dns_get_addr_info(query,
|
||||||
DNS_QUERY_TYPE_AAAA,
|
DNS_QUERY_TYPE_AAAA,
|
||||||
|
|
@ -337,11 +337,11 @@ static void do_mdns_ipv6_lookup(struct k_work *work)
|
||||||
(void *)query,
|
(void *)query,
|
||||||
DNS_TIMEOUT);
|
DNS_TIMEOUT);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot resolve mDNS IPv6 address (%d)", ret);
|
LOG_ERR("Cannot resolve mDNS IPv6 address (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("mDNS id %u", dns_id);
|
LOG_DBG("mDNS id %u", dns_id);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -353,7 +353,7 @@ void main(void)
|
||||||
{
|
{
|
||||||
struct net_if *iface = net_if_get_default();
|
struct net_if *iface = net_if_get_default();
|
||||||
|
|
||||||
NET_INFO("Starting DNS resolve sample");
|
LOG_INF("Starting DNS resolve sample");
|
||||||
|
|
||||||
setup_ipv4(iface);
|
setup_ipv4(iface);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ struct k_sem tcp_ready;
|
||||||
void panic(const char *msg)
|
void panic(const char *msg)
|
||||||
{
|
{
|
||||||
if (msg) {
|
if (msg) {
|
||||||
NET_ERR("%s", msg);
|
LOG_ERR("%s", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
k_sem_give(&quit_lock);
|
k_sem_give(&quit_lock);
|
||||||
|
|
@ -93,7 +93,7 @@ void panic(const char *msg)
|
||||||
|
|
||||||
static inline int init_app(void)
|
static inline int init_app(void)
|
||||||
{
|
{
|
||||||
NET_INFO(APP_BANNER);
|
LOG_INF(APP_BANNER);
|
||||||
|
|
||||||
k_sem_init(&quit_lock, 0, UINT_MAX);
|
k_sem_init(&quit_lock, 0, UINT_MAX);
|
||||||
|
|
||||||
|
|
@ -152,7 +152,7 @@ void main(void)
|
||||||
k_sem_take(&quit_lock, K_FOREVER);
|
k_sem_take(&quit_lock, K_FOREVER);
|
||||||
|
|
||||||
quit:
|
quit:
|
||||||
NET_INFO("Stopping...");
|
LOG_INF("Stopping...");
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||||
stop_udp();
|
stop_udp();
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ static int setup_cert(struct net_app_ctx *ctx, void *cert)
|
||||||
ca_certificate,
|
ca_certificate,
|
||||||
sizeof(ca_certificate));
|
sizeof(ca_certificate));
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_x509_crt_parse_der failed "
|
LOG_ERR("mbedtls_x509_crt_parse_der failed "
|
||||||
"(-0x%x)", -ret);
|
"(-0x%x)", -ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -162,7 +162,7 @@ static void send_tcp_data(struct net_app_ctx *ctx,
|
||||||
ret = net_app_send_pkt(ctx, pkt, NULL, 0, K_FOREVER,
|
ret = net_app_send_pkt(ctx, pkt, NULL, 0, K_FOREVER,
|
||||||
UINT_TO_POINTER(len));
|
UINT_TO_POINTER(len));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send %s data to peer (%d)", data->proto, ret);
|
LOG_ERR("Cannot send %s data to peer (%d)", data->proto, ret);
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -190,7 +190,7 @@ static bool compare_tcp_data(struct net_pkt *pkt, int expecting_len,
|
||||||
|
|
||||||
while (frag) {
|
while (frag) {
|
||||||
if (memcmp(ptr, start + pos, len)) {
|
if (memcmp(ptr, start + pos, len)) {
|
||||||
NET_DBG("Invalid data received");
|
LOG_DBG("Invalid data received");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,7 +205,7 @@ static bool compare_tcp_data(struct net_pkt *pkt, int expecting_len,
|
||||||
len = frag->len;
|
len = frag->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Compared %d bytes, all ok", net_pkt_appdatalen(pkt));
|
LOG_DBG("Compared %d bytes, all ok", net_pkt_appdatalen(pkt));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -228,11 +228,11 @@ static void tcp_received(struct net_app_ctx *ctx,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("%s: Sent %d bytes, received %u bytes",
|
LOG_DBG("%s: Sent %d bytes, received %u bytes",
|
||||||
data->proto, data->expecting_tcp, net_pkt_appdatalen(pkt));
|
data->proto, data->expecting_tcp, net_pkt_appdatalen(pkt));
|
||||||
|
|
||||||
if (!compare_tcp_data(pkt, data->expecting_tcp, data->received_tcp)) {
|
if (!compare_tcp_data(pkt, data->expecting_tcp, data->received_tcp)) {
|
||||||
NET_DBG("Data mismatch");
|
LOG_DBG("Data mismatch");
|
||||||
} else {
|
} else {
|
||||||
data->received_tcp += net_pkt_appdatalen(pkt);
|
data->received_tcp += net_pkt_appdatalen(pkt);
|
||||||
}
|
}
|
||||||
|
|
@ -278,7 +278,7 @@ static int connect_tcp(struct net_app_ctx *ctx, const char *peer,
|
||||||
ret = net_app_init_tcp_client(ctx, NULL, NULL, peer, PEER_PORT,
|
ret = net_app_init_tcp_client(ctx, NULL, NULL, peer, PEER_PORT,
|
||||||
WAIT_TIME, user_data);
|
WAIT_TIME, user_data);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init %s TCP client (%d)", data->proto, ret);
|
LOG_ERR("Cannot init %s TCP client (%d)", data->proto, ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -288,7 +288,7 @@ static int connect_tcp(struct net_app_ctx *ctx, const char *peer,
|
||||||
|
|
||||||
ret = net_app_set_cb(ctx, tcp_connected, tcp_received, NULL, NULL);
|
ret = net_app_set_cb(ctx, tcp_connected, tcp_received, NULL, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot set callbacks (%d)", ret);
|
LOG_ERR("Cannot set callbacks (%d)", ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,14 +305,14 @@ static int connect_tcp(struct net_app_ctx *ctx, const char *peer,
|
||||||
stack,
|
stack,
|
||||||
stack_size);
|
stack_size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init TLS");
|
LOG_ERR("Cannot init TLS");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = net_app_connect(ctx, CONNECT_TIME);
|
ret = net_app_connect(ctx, CONNECT_TIME);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot connect TCP (%d)", ret);
|
LOG_ERR("Cannot connect TCP (%d)", ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -332,7 +332,7 @@ int start_tcp(void)
|
||||||
K_THREAD_STACK_SIZEOF(
|
K_THREAD_STACK_SIZEOF(
|
||||||
net_app_tls_stack_ipv6));
|
net_app_tls_stack_ipv6));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init IPv6 TCP client (%d)", ret);
|
LOG_ERR("Cannot init IPv6 TCP client (%d)", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -344,7 +344,7 @@ int start_tcp(void)
|
||||||
K_THREAD_STACK_SIZEOF(
|
K_THREAD_STACK_SIZEOF(
|
||||||
net_app_tls_stack_ipv4));
|
net_app_tls_stack_ipv4));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init IPv4 TCP client (%d)", ret);
|
LOG_ERR("Cannot init IPv4 TCP client (%d)", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ static void send_udp_data(struct net_app_ctx *ctx, struct data *data)
|
||||||
ret = net_app_send_pkt(ctx, pkt, NULL, 0, K_FOREVER,
|
ret = net_app_send_pkt(ctx, pkt, NULL, 0, K_FOREVER,
|
||||||
UINT_TO_POINTER(len));
|
UINT_TO_POINTER(len));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send %s data to peer (%d)", data->proto, ret);
|
LOG_ERR("Cannot send %s data to peer (%d)", data->proto, ret);
|
||||||
|
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
}
|
}
|
||||||
|
|
@ -185,7 +185,7 @@ static bool compare_udp_data(struct net_pkt *pkt, int expecting_len)
|
||||||
|
|
||||||
while (frag) {
|
while (frag) {
|
||||||
if (memcmp(ptr, lorem_ipsum + pos, len)) {
|
if (memcmp(ptr, lorem_ipsum + pos, len)) {
|
||||||
NET_DBG("Invalid data received");
|
LOG_DBG("Invalid data received");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
pos += len;
|
pos += len;
|
||||||
|
|
@ -200,7 +200,7 @@ static bool compare_udp_data(struct net_pkt *pkt, int expecting_len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Compared %d bytes, all ok", expecting_len);
|
LOG_DBG("Compared %d bytes, all ok", expecting_len);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -216,12 +216,12 @@ static void udp_received(struct net_app_ctx *ctx,
|
||||||
ARG_UNUSED(status);
|
ARG_UNUSED(status);
|
||||||
|
|
||||||
if (data->expecting_udp != net_pkt_appdatalen(pkt)) {
|
if (data->expecting_udp != net_pkt_appdatalen(pkt)) {
|
||||||
NET_DBG("Sent %d bytes, received %u bytes",
|
LOG_DBG("Sent %d bytes, received %u bytes",
|
||||||
data->expecting_udp, net_pkt_appdatalen(pkt));
|
data->expecting_udp, net_pkt_appdatalen(pkt));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compare_udp_data(pkt, data->expecting_udp)) {
|
if (!compare_udp_data(pkt, data->expecting_udp)) {
|
||||||
NET_DBG("Data mismatch");
|
LOG_DBG("Data mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
|
|
@ -259,7 +259,7 @@ static int connect_udp(struct net_app_ctx *ctx, const char *peer,
|
||||||
ret = net_app_init_udp_client(ctx, NULL, NULL, peer, PEER_PORT,
|
ret = net_app_init_udp_client(ctx, NULL, NULL, peer, PEER_PORT,
|
||||||
WAIT_TIME, user_data);
|
WAIT_TIME, user_data);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init %s UDP client (%d)", data->proto, ret);
|
LOG_ERR("Cannot init %s UDP client (%d)", data->proto, ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -269,7 +269,7 @@ static int connect_udp(struct net_app_ctx *ctx, const char *peer,
|
||||||
|
|
||||||
ret = net_app_set_cb(ctx, udp_connected, udp_received, NULL, NULL);
|
ret = net_app_set_cb(ctx, udp_connected, udp_received, NULL, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot set callbacks (%d)", ret);
|
LOG_ERR("Cannot set callbacks (%d)", ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,7 +286,7 @@ static int connect_udp(struct net_app_ctx *ctx, const char *peer,
|
||||||
stack,
|
stack,
|
||||||
stack_size);
|
stack_size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init DTLS");
|
LOG_ERR("Cannot init DTLS");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
@ -298,7 +298,7 @@ static int connect_udp(struct net_app_ctx *ctx, const char *peer,
|
||||||
|
|
||||||
ret = net_app_connect(ctx, CONNECT_TIME);
|
ret = net_app_connect(ctx, CONNECT_TIME);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot connect UDP (%d)", ret);
|
LOG_ERR("Cannot connect UDP (%d)", ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,7 +311,7 @@ static void wait_reply(struct k_work *work)
|
||||||
/* This means that we did not receive response in time. */
|
/* This means that we did not receive response in time. */
|
||||||
struct data *data = CONTAINER_OF(work, struct data, recv);
|
struct data *data = CONTAINER_OF(work, struct data, recv);
|
||||||
|
|
||||||
NET_ERR("Data packet not received");
|
LOG_ERR("Data packet not received");
|
||||||
|
|
||||||
/* Send a new packet at this point */
|
/* Send a new packet at this point */
|
||||||
send_udp_data(data->udp, data);
|
send_udp_data(data->udp, data);
|
||||||
|
|
@ -331,7 +331,7 @@ void start_udp(void)
|
||||||
K_THREAD_STACK_SIZEOF(
|
K_THREAD_STACK_SIZEOF(
|
||||||
net_app_dtls_stack_ipv6));
|
net_app_dtls_stack_ipv6));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init IPv6 UDP client (%d)", ret);
|
LOG_ERR("Cannot init IPv6 UDP client (%d)", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -345,7 +345,7 @@ void start_udp(void)
|
||||||
K_THREAD_STACK_SIZEOF(
|
K_THREAD_STACK_SIZEOF(
|
||||||
net_app_dtls_stack_ipv4));
|
net_app_dtls_stack_ipv4));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init IPv4 UDP client (%d)", ret);
|
LOG_ERR("Cannot init IPv4 UDP client (%d)", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,32 +52,32 @@ static int setup_iface(struct net_if *iface, const char *ipv6_addr,
|
||||||
|
|
||||||
ret = net_eth_vlan_enable(iface, vlan_tag);
|
ret = net_eth_vlan_enable(iface, vlan_tag);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
LOG_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
LOG_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ static struct k_sem quit_lock;
|
||||||
void panic(const char *msg)
|
void panic(const char *msg)
|
||||||
{
|
{
|
||||||
if (msg) {
|
if (msg) {
|
||||||
NET_ERR("%s", msg);
|
LOG_ERR("%s", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
@ -58,7 +58,7 @@ struct net_pkt *build_reply_pkt(const char *name,
|
||||||
int recv_len;
|
int recv_len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
NET_INFO("%s received %d bytes", name, net_pkt_appdatalen(pkt));
|
LOG_INF("%s received %d bytes", name, net_pkt_appdatalen(pkt));
|
||||||
|
|
||||||
if (net_pkt_appdatalen(pkt) == 0) {
|
if (net_pkt_appdatalen(pkt) == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -93,7 +93,7 @@ struct net_pkt *build_reply_pkt(const char *name,
|
||||||
|
|
||||||
frag = net_pkt_copy_all(pkt, 0, BUF_TIMEOUT);
|
frag = net_pkt_copy_all(pkt, 0, BUF_TIMEOUT);
|
||||||
if (!frag) {
|
if (!frag) {
|
||||||
NET_ERR("Failed to copy all data");
|
LOG_ERR("Failed to copy all data");
|
||||||
net_pkt_unref(reply_pkt);
|
net_pkt_unref(reply_pkt);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +109,7 @@ void pkt_sent(struct net_app_ctx *ctx,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
if (!status) {
|
if (!status) {
|
||||||
NET_INFO("Sent %d bytes", POINTER_TO_UINT(user_data_send));
|
LOG_INF("Sent %d bytes", POINTER_TO_UINT(user_data_send));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ void main(void)
|
||||||
|
|
||||||
k_sem_take(&quit_lock, K_FOREVER);
|
k_sem_take(&quit_lock, K_FOREVER);
|
||||||
|
|
||||||
NET_INFO("Stopping...");
|
LOG_INF("Stopping...");
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_NET_TCP)) {
|
if (IS_ENABLED(CONFIG_NET_TCP)) {
|
||||||
stop_tcp();
|
stop_tcp();
|
||||||
|
|
|
||||||
|
|
@ -85,14 +85,14 @@ static int setup_cert(struct net_app_ctx *ctx,
|
||||||
ret = mbedtls_x509_crt_parse(cert, rsa_example_cert_der,
|
ret = mbedtls_x509_crt_parse(cert, rsa_example_cert_der,
|
||||||
rsa_example_cert_der_len);
|
rsa_example_cert_der_len);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
LOG_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mbedtls_pk_parse_key(pkey, rsa_example_keypair_der,
|
ret = mbedtls_pk_parse_key(pkey, rsa_example_keypair_der,
|
||||||
rsa_example_keypair_der_len, NULL, 0);
|
rsa_example_keypair_der_len, NULL, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_pk_parse_key returned %d", ret);
|
LOG_ERR("mbedtls_pk_parse_key returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,7 +131,7 @@ static void tcp_received(struct net_app_ctx *ctx,
|
||||||
ret = net_app_send_pkt(ctx, reply_pkt, NULL, 0, K_NO_WAIT,
|
ret = net_app_send_pkt(ctx, reply_pkt, NULL, 0, K_NO_WAIT,
|
||||||
UINT_TO_POINTER(net_pkt_get_len(reply_pkt)));
|
UINT_TO_POINTER(net_pkt_get_len(reply_pkt)));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send data to peer (%d)", ret);
|
LOG_ERR("Cannot send data to peer (%d)", ret);
|
||||||
net_pkt_unref(reply_pkt);
|
net_pkt_unref(reply_pkt);
|
||||||
|
|
||||||
quit();
|
quit();
|
||||||
|
|
@ -144,7 +144,7 @@ void start_tcp(void)
|
||||||
|
|
||||||
ret = net_app_init_tcp_server(&tcp, NULL, MY_PORT, NULL);
|
ret = net_app_init_tcp_server(&tcp, NULL, MY_PORT, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init TCP service at port %d", MY_PORT);
|
LOG_ERR("Cannot init TCP service at port %d", MY_PORT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ void start_tcp(void)
|
||||||
|
|
||||||
ret = net_app_set_cb(&tcp, NULL, tcp_received, NULL, NULL);
|
ret = net_app_set_cb(&tcp, NULL, tcp_received, NULL, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot set callbacks (%d)", ret);
|
LOG_ERR("Cannot set callbacks (%d)", ret);
|
||||||
net_app_release(&tcp);
|
net_app_release(&tcp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +172,7 @@ void start_tcp(void)
|
||||||
net_app_tls_stack,
|
net_app_tls_stack,
|
||||||
K_THREAD_STACK_SIZEOF(net_app_tls_stack));
|
K_THREAD_STACK_SIZEOF(net_app_tls_stack));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init TLS");
|
LOG_ERR("Cannot init TLS");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -180,7 +180,7 @@ void start_tcp(void)
|
||||||
|
|
||||||
ret = net_app_listen(&tcp);
|
ret = net_app_listen(&tcp);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot wait connection (%d)", ret);
|
LOG_ERR("Cannot wait connection (%d)", ret);
|
||||||
net_app_release(&tcp);
|
net_app_release(&tcp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,14 +82,14 @@ static int setup_cert(struct net_app_ctx *ctx,
|
||||||
ret = mbedtls_x509_crt_parse(cert, rsa_example_cert_der,
|
ret = mbedtls_x509_crt_parse(cert, rsa_example_cert_der,
|
||||||
rsa_example_cert_der_len);
|
rsa_example_cert_der_len);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
LOG_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mbedtls_pk_parse_key(pkey, rsa_example_keypair_der,
|
ret = mbedtls_pk_parse_key(pkey, rsa_example_keypair_der,
|
||||||
rsa_example_keypair_der_len, NULL, 0);
|
rsa_example_keypair_der_len, NULL, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_pk_parse_key returned %d", ret);
|
LOG_ERR("mbedtls_pk_parse_key returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,7 +168,7 @@ static void udp_received(struct net_app_ctx *ctx,
|
||||||
ret = net_app_send_pkt(ctx, reply_pkt, &dst_addr, dst_len, K_NO_WAIT,
|
ret = net_app_send_pkt(ctx, reply_pkt, &dst_addr, dst_len, K_NO_WAIT,
|
||||||
UINT_TO_POINTER(pkt_len));
|
UINT_TO_POINTER(pkt_len));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send data to peer (%d)", ret);
|
LOG_ERR("Cannot send data to peer (%d)", ret);
|
||||||
net_pkt_unref(reply_pkt);
|
net_pkt_unref(reply_pkt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -179,7 +179,7 @@ void start_udp(void)
|
||||||
|
|
||||||
ret = net_app_init_udp_server(&udp, NULL, MY_PORT, NULL);
|
ret = net_app_init_udp_server(&udp, NULL, MY_PORT, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init UDP service at port %d", MY_PORT);
|
LOG_ERR("Cannot init UDP service at port %d", MY_PORT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,7 +189,7 @@ void start_udp(void)
|
||||||
|
|
||||||
ret = net_app_set_cb(&udp, NULL, udp_received, pkt_sent, NULL);
|
ret = net_app_set_cb(&udp, NULL, udp_received, pkt_sent, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot set callbacks (%d)", ret);
|
LOG_ERR("Cannot set callbacks (%d)", ret);
|
||||||
net_app_release(&udp);
|
net_app_release(&udp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -207,7 +207,7 @@ void start_udp(void)
|
||||||
net_app_dtls_stack,
|
net_app_dtls_stack,
|
||||||
K_THREAD_STACK_SIZEOF(net_app_dtls_stack));
|
K_THREAD_STACK_SIZEOF(net_app_dtls_stack));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init DTLS");
|
LOG_ERR("Cannot init DTLS");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -215,7 +215,7 @@ void start_udp(void)
|
||||||
|
|
||||||
ret = net_app_listen(&udp);
|
ret = net_app_listen(&udp);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot wait connection (%d)", ret);
|
LOG_ERR("Cannot wait connection (%d)", ret);
|
||||||
net_app_release(&udp);
|
net_app_release(&udp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,32 +52,32 @@ static int setup_iface(struct net_if *iface, const char *ipv6_addr,
|
||||||
|
|
||||||
ret = net_eth_vlan_enable(iface, vlan_tag);
|
ret = net_eth_vlan_enable(iface, vlan_tag);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
LOG_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
LOG_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,5 @@ LOG_MODULE_REGISTER(net_native_posix_sample, LOG_LEVEL_DBG);
|
||||||
*/
|
*/
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
NET_INFO("Start application");
|
LOG_INF("Start application");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,32 +60,32 @@ static int setup_iface(struct net_if *iface, const char *ipv6_addr,
|
||||||
|
|
||||||
ret = net_eth_vlan_enable(iface, vlan_tag);
|
ret = net_eth_vlan_enable(iface, vlan_tag);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
LOG_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
LOG_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +134,7 @@ static void gptp_phase_dis_cb(u8_t *gm_identity,
|
||||||
if (memcmp(id, gm_identity, sizeof(id))) {
|
if (memcmp(id, gm_identity, sizeof(id))) {
|
||||||
memcpy(id, gm_identity, sizeof(id));
|
memcpy(id, gm_identity, sizeof(id));
|
||||||
|
|
||||||
NET_DBG("GM %s last phase %d.%lld",
|
LOG_DBG("GM %s last phase %d.%lld",
|
||||||
log_strdup(gptp_sprint_clock_id(gm_identity, output,
|
log_strdup(gptp_sprint_clock_id(gm_identity, output,
|
||||||
sizeof(output))),
|
sizeof(output))),
|
||||||
last_gm_ph_change->high,
|
last_gm_ph_change->high,
|
||||||
|
|
@ -146,7 +146,7 @@ static int init_app(void)
|
||||||
{
|
{
|
||||||
#if defined(CONFIG_NET_GPTP_VLAN)
|
#if defined(CONFIG_NET_GPTP_VLAN)
|
||||||
if (init_vlan() < 0) {
|
if (init_vlan() < 0) {
|
||||||
NET_ERR("Cannot setup VLAN");
|
LOG_ERR("Cannot setup VLAN");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ static int setup_cert(struct net_app_ctx *ctx, void *cert)
|
||||||
echo_apps_cert_der,
|
echo_apps_cert_der,
|
||||||
sizeof(echo_apps_cert_der));
|
sizeof(echo_apps_cert_der));
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_x509_crt_parse_der failed "
|
LOG_ERR("mbedtls_x509_crt_parse_der failed "
|
||||||
"(-0x%x)", -ret);
|
"(-0x%x)", -ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -159,24 +159,24 @@ static int do_sync_http_req(struct http_ctx *ctx,
|
||||||
req.url = url;
|
req.url = url;
|
||||||
req.protocol = " " HTTP_PROTOCOL;
|
req.protocol = " " HTTP_PROTOCOL;
|
||||||
|
|
||||||
NET_INFO("[%d] Send %s", count, url);
|
LOG_INF("[%d] Send %s", count, url);
|
||||||
|
|
||||||
ret = http_client_send_req(ctx, &req, NULL, result, sizeof(result),
|
ret = http_client_send_req(ctx, &req, NULL, result, sizeof(result),
|
||||||
NULL, APP_REQ_TIMEOUT);
|
NULL, APP_REQ_TIMEOUT);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send %s request (%d)", http_method_str(method),
|
LOG_ERR("Cannot send %s request (%d)", http_method_str(method),
|
||||||
ret);
|
ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->http.rsp.data_len > sizeof(result)) {
|
if (ctx->http.rsp.data_len > sizeof(result)) {
|
||||||
NET_ERR("Result buffer overflow by %zd bytes",
|
LOG_ERR("Result buffer overflow by %zd bytes",
|
||||||
ctx->http.rsp.data_len - sizeof(result));
|
ctx->http.rsp.data_len - sizeof(result));
|
||||||
|
|
||||||
ret = -E2BIG;
|
ret = -E2BIG;
|
||||||
} else {
|
} else {
|
||||||
NET_INFO("HTTP server response status: %s",
|
LOG_INF("HTTP server response status: %s",
|
||||||
ctx->http.rsp.http_status);
|
ctx->http.rsp.http_status);
|
||||||
|
|
||||||
if (ctx->http.parser.http_errno) {
|
if (ctx->http.parser.http_errno) {
|
||||||
if (method == HTTP_OPTIONS) {
|
if (method == HTTP_OPTIONS) {
|
||||||
|
|
@ -184,21 +184,21 @@ static int do_sync_http_req(struct http_ctx *ctx,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("HTTP parser status: %s",
|
LOG_INF("HTTP parser status: %s",
|
||||||
http_errno_description(
|
http_errno_description(
|
||||||
ctx->http.parser.http_errno));
|
ctx->http.parser.http_errno));
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method != HTTP_HEAD) {
|
if (method != HTTP_HEAD) {
|
||||||
if (ctx->http.rsp.body_found) {
|
if (ctx->http.rsp.body_found) {
|
||||||
NET_INFO("HTTP body: %zd bytes, "
|
LOG_INF("HTTP body: %zd bytes, "
|
||||||
"expected: %zd bytes",
|
"expected: %zd bytes",
|
||||||
ctx->http.rsp.processed,
|
ctx->http.rsp.processed,
|
||||||
ctx->http.rsp.content_length);
|
ctx->http.rsp.content_length);
|
||||||
} else {
|
} else {
|
||||||
NET_ERR("Error detected during HTTP msg "
|
LOG_ERR("Error detected during HTTP msg "
|
||||||
"processing");
|
"processing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -220,7 +220,7 @@ void response(struct http_ctx *ctx,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (data_end == HTTP_DATA_MORE) {
|
if (data_end == HTTP_DATA_MORE) {
|
||||||
NET_INFO("Received %zd bytes piece of data", datalen);
|
LOG_INF("Received %zd bytes piece of data", datalen);
|
||||||
|
|
||||||
/* Do something with the data here. For this example
|
/* Do something with the data here. For this example
|
||||||
* we just ignore the received data.
|
* we just ignore the received data.
|
||||||
|
|
@ -242,7 +242,7 @@ void response(struct http_ctx *ctx,
|
||||||
|
|
||||||
waiter->total_len += datalen;
|
waiter->total_len += datalen;
|
||||||
|
|
||||||
NET_INFO("HTTP server response status: %s", ctx->http.rsp.http_status);
|
LOG_INF("HTTP server response status: %s", ctx->http.rsp.http_status);
|
||||||
|
|
||||||
if (ctx->http.parser.http_errno) {
|
if (ctx->http.parser.http_errno) {
|
||||||
if (ctx->http.req.method == HTTP_OPTIONS) {
|
if (ctx->http.req.method == HTTP_OPTIONS) {
|
||||||
|
|
@ -250,8 +250,8 @@ void response(struct http_ctx *ctx,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("HTTP parser status: %s",
|
LOG_INF("HTTP parser status: %s",
|
||||||
http_errno_description(ctx->http.parser.http_errno));
|
http_errno_description(ctx->http.parser.http_errno));
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
@ -259,16 +259,16 @@ void response(struct http_ctx *ctx,
|
||||||
if (ctx->http.req.method != HTTP_HEAD &&
|
if (ctx->http.req.method != HTTP_HEAD &&
|
||||||
ctx->http.req.method != HTTP_OPTIONS) {
|
ctx->http.req.method != HTTP_OPTIONS) {
|
||||||
if (ctx->http.rsp.body_found) {
|
if (ctx->http.rsp.body_found) {
|
||||||
NET_INFO("HTTP body: %zd bytes, expected: %zd bytes",
|
LOG_INF("HTTP body: %zd bytes, expected: %zd bytes",
|
||||||
ctx->http.rsp.processed,
|
ctx->http.rsp.processed,
|
||||||
ctx->http.rsp.content_length);
|
ctx->http.rsp.content_length);
|
||||||
} else {
|
} else {
|
||||||
NET_ERR("Error detected during HTTP msg processing");
|
LOG_ERR("Error detected during HTTP msg processing");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (waiter->total_len !=
|
if (waiter->total_len !=
|
||||||
waiter->header_len + ctx->http.rsp.content_length) {
|
waiter->header_len + ctx->http.rsp.content_length) {
|
||||||
NET_ERR("Error while receiving data, "
|
LOG_ERR("Error while receiving data, "
|
||||||
"received %zd expected %zd bytes",
|
"received %zd expected %zd bytes",
|
||||||
waiter->total_len, waiter->header_len +
|
waiter->total_len, waiter->header_len +
|
||||||
ctx->http.rsp.content_length);
|
ctx->http.rsp.content_length);
|
||||||
|
|
@ -298,18 +298,18 @@ static int do_async_http_req(struct http_ctx *ctx,
|
||||||
|
|
||||||
waiter.total_len = 0;
|
waiter.total_len = 0;
|
||||||
|
|
||||||
NET_INFO("[%d] Send %s", count, url);
|
LOG_INF("[%d] Send %s", count, url);
|
||||||
|
|
||||||
ret = http_client_send_req(ctx, &req, response, result, sizeof(result),
|
ret = http_client_send_req(ctx, &req, response, result, sizeof(result),
|
||||||
&waiter, APP_REQ_TIMEOUT);
|
&waiter, APP_REQ_TIMEOUT);
|
||||||
if (ret < 0 && ret != -EINPROGRESS) {
|
if (ret < 0 && ret != -EINPROGRESS) {
|
||||||
NET_ERR("Cannot send %s request (%d)", http_method_str(method),
|
LOG_ERR("Cannot send %s request (%d)", http_method_str(method),
|
||||||
ret);
|
ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (k_sem_take(&waiter.wait, WAIT_TIME)) {
|
if (k_sem_take(&waiter.wait, WAIT_TIME)) {
|
||||||
NET_ERR("Timeout while waiting HTTP response");
|
LOG_ERR("Timeout while waiting HTTP response");
|
||||||
ret = -ETIMEDOUT;
|
ret = -ETIMEDOUT;
|
||||||
http_request_cancel(ctx);
|
http_request_cancel(ctx);
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -426,12 +426,12 @@ static void http_received(struct http_ctx *ctx,
|
||||||
{
|
{
|
||||||
if (!status) {
|
if (!status) {
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
NET_DBG("Received %d bytes data",
|
LOG_DBG("Received %d bytes data",
|
||||||
net_pkt_appdatalen(pkt));
|
net_pkt_appdatalen(pkt));
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
NET_ERR("Receive error (%d)", status);
|
LOG_ERR("Receive error (%d)", status);
|
||||||
|
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
|
|
@ -446,7 +446,7 @@ void main(void)
|
||||||
ret = http_client_init(&http_ctx, SERVER_ADDR, SERVER_PORT, NULL,
|
ret = http_client_init(&http_ctx, SERVER_ADDR, SERVER_PORT, NULL,
|
||||||
K_FOREVER);
|
K_FOREVER);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("HTTP init failed (%d)", ret);
|
LOG_ERR("HTTP init failed (%d)", ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -469,19 +469,19 @@ void main(void)
|
||||||
https_stack,
|
https_stack,
|
||||||
K_THREAD_STACK_SIZEOF(https_stack));
|
K_THREAD_STACK_SIZEOF(https_stack));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("HTTPS init failed (%d)", ret);
|
LOG_ERR("HTTPS init failed (%d)", ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NET_INFO("--------Sending %d sync request--------", MAX_ITERATIONS);
|
LOG_INF("--------Sending %d sync request--------", MAX_ITERATIONS);
|
||||||
|
|
||||||
ret = do_sync_reqs(&http_ctx, MAX_ITERATIONS);
|
ret = do_sync_reqs(&http_ctx, MAX_ITERATIONS);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("--------Sending %d async request--------", MAX_ITERATIONS);
|
LOG_INF("--------Sending %d async request--------", MAX_ITERATIONS);
|
||||||
|
|
||||||
ret = do_async_reqs(&http_ctx, MAX_ITERATIONS);
|
ret = do_async_reqs(&http_ctx, MAX_ITERATIONS);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
@ -491,5 +491,5 @@ void main(void)
|
||||||
out:
|
out:
|
||||||
http_release(&http_ctx);
|
http_release(&http_ctx);
|
||||||
|
|
||||||
NET_INFO("Done!");
|
LOG_INF("Done!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ static struct http_server_urls http_urls;
|
||||||
void panic(const char *msg)
|
void panic(const char *msg)
|
||||||
{
|
{
|
||||||
if (msg) {
|
if (msg) {
|
||||||
NET_ERR("%s", msg);
|
LOG_ERR("%s", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
@ -113,7 +113,7 @@ static int http_response(struct http_ctx *ctx, const char *header,
|
||||||
|
|
||||||
ret = http_add_header(ctx, header, dst, str);
|
ret = http_add_header(ctx, header, dst, str);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot add HTTP header (%d)", ret);
|
LOG_ERR("Cannot add HTTP header (%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,13 +124,13 @@ static int http_response(struct http_ctx *ctx, const char *header,
|
||||||
|
|
||||||
ret = http_send_chunk(ctx, payload, payload_len, dst, str);
|
ret = http_send_chunk(ctx, payload, payload_len, dst, str);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send data to peer (%d)", ret);
|
LOG_ERR("Cannot send data to peer (%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = http_send_chunk(ctx, NULL, 0, dst, NULL);
|
ret = http_send_chunk(ctx, NULL, 0, dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send data to peer (%d)", ret);
|
LOG_ERR("Cannot send data to peer (%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -227,7 +227,7 @@ static int http_serve_index_html(struct http_ctx *ctx,
|
||||||
#include "index.html.inc"
|
#include "index.html.inc"
|
||||||
};
|
};
|
||||||
|
|
||||||
NET_DBG("Sending index.html (%zd bytes) to client",
|
LOG_DBG("Sending index.html (%zd bytes) to client",
|
||||||
sizeof(index_html));
|
sizeof(index_html));
|
||||||
|
|
||||||
return http_response(ctx, HTTP_STATUS_200_OK, index_html,
|
return http_response(ctx, HTTP_STATUS_200_OK, index_html,
|
||||||
|
|
@ -245,7 +245,7 @@ static void http_connected(struct http_ctx *ctx,
|
||||||
memcpy(url, ctx->http.url, len);
|
memcpy(url, ctx->http.url, len);
|
||||||
url[len] = '\0';
|
url[len] = '\0';
|
||||||
|
|
||||||
NET_DBG("%s connect attempt URL %s",
|
LOG_DBG("%s connect attempt URL %s",
|
||||||
type == HTTP_CONNECTION ? "HTTP" : "WS", url);
|
type == HTTP_CONNECTION ? "HTTP" : "WS", url);
|
||||||
|
|
||||||
if (type == HTTP_CONNECTION) {
|
if (type == HTTP_CONNECTION) {
|
||||||
|
|
@ -287,12 +287,12 @@ static void http_received(struct http_ctx *ctx,
|
||||||
{
|
{
|
||||||
if (!status) {
|
if (!status) {
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
NET_DBG("Received %d bytes data",
|
LOG_DBG("Received %d bytes data",
|
||||||
net_pkt_appdatalen(pkt));
|
net_pkt_appdatalen(pkt));
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
NET_ERR("Receive error (%d)", status);
|
LOG_ERR("Receive error (%d)", status);
|
||||||
|
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
|
|
@ -305,14 +305,14 @@ static void http_sent(struct http_ctx *ctx,
|
||||||
void *user_data_send,
|
void *user_data_send,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
NET_DBG("%s sent", (char *)user_data_send);
|
LOG_DBG("%s sent", (char *)user_data_send);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void http_closed(struct http_ctx *ctx,
|
static void http_closed(struct http_ctx *ctx,
|
||||||
int status,
|
int status,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
NET_DBG("Connection %p closed", ctx);
|
LOG_DBG("Connection %p closed", ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *get_string(int str_len, const char *str)
|
static const char *get_string(int str_len, const char *str)
|
||||||
|
|
@ -330,7 +330,7 @@ static enum http_verdict default_handler(struct http_ctx *ctx,
|
||||||
enum http_connection_type type,
|
enum http_connection_type type,
|
||||||
const struct sockaddr *dst)
|
const struct sockaddr *dst)
|
||||||
{
|
{
|
||||||
NET_DBG("No handler for %s URL %s",
|
LOG_DBG("No handler for %s URL %s",
|
||||||
type == HTTP_CONNECTION ? "HTTP" : "WS",
|
type == HTTP_CONNECTION ? "HTTP" : "WS",
|
||||||
get_string(ctx->http.url_len, ctx->http.url));
|
get_string(ctx->http.url_len, ctx->http.url));
|
||||||
|
|
||||||
|
|
@ -362,7 +362,7 @@ static int setup_cert(struct net_app_ctx *app_ctx,
|
||||||
ret = mbedtls_x509_crt_parse(cert, echo_apps_cert_der,
|
ret = mbedtls_x509_crt_parse(cert, echo_apps_cert_der,
|
||||||
sizeof(echo_apps_cert_der));
|
sizeof(echo_apps_cert_der));
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
LOG_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -370,7 +370,7 @@ static int setup_cert(struct net_app_ctx *app_ctx,
|
||||||
sizeof(echo_apps_key_der),
|
sizeof(echo_apps_key_der),
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_pk_parse_key returned %d", ret);
|
LOG_ERR("mbedtls_pk_parse_key returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -422,7 +422,7 @@ void main(void)
|
||||||
|
|
||||||
ret = http_server_set_local_addr(&addr, ZEPHYR_ADDR, ZEPHYR_PORT);
|
ret = http_server_set_local_addr(&addr, ZEPHYR_ADDR, ZEPHYR_PORT);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot set local address (%d)", ret);
|
LOG_ERR("Cannot set local address (%d)", ret);
|
||||||
panic(NULL);
|
panic(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -443,7 +443,7 @@ void main(void)
|
||||||
sizeof(http_result), "Zephyr HTTP Server",
|
sizeof(http_result), "Zephyr HTTP Server",
|
||||||
NULL);
|
NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot initialize HTTP server (%d)", ret);
|
LOG_ERR("Cannot initialize HTTP server (%d)", ret);
|
||||||
panic(NULL);
|
panic(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -465,7 +465,7 @@ void main(void)
|
||||||
https_stack,
|
https_stack,
|
||||||
K_THREAD_STACK_SIZEOF(https_stack));
|
K_THREAD_STACK_SIZEOF(https_stack));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable TLS support (%d)", ret);
|
LOG_ERR("Cannot enable TLS support (%d)", ret);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@ static void handler(struct net_mgmt_event_callback *cb,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("Your address: %s",
|
LOG_INF("Your address: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET,
|
log_strdup(net_addr_ntop(AF_INET,
|
||||||
&cfg->ip.ipv4->unicast[i].address.in_addr,
|
&cfg->ip.ipv4->unicast[i].address.in_addr,
|
||||||
buf, sizeof(buf))));
|
buf, sizeof(buf))));
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +54,7 @@ static void handler(struct net_mgmt_event_callback *cb,
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
NET_INFO("Run ipv4 autoconf client");
|
LOG_INF("Run ipv4 autoconf client");
|
||||||
|
|
||||||
net_mgmt_init_event_callback(&mgmt_cb, handler,
|
net_mgmt_init_event_callback(&mgmt_cb, handler,
|
||||||
NET_EVENT_IPV4_ADDR_ADD);
|
NET_EVENT_IPV4_ADDR_ADD);
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ static struct net_buf_pool *data_pool(void)
|
||||||
static void
|
static void
|
||||||
panic(const char *msg)
|
panic(const char *msg)
|
||||||
{
|
{
|
||||||
NET_ERR("Panic: %s", msg);
|
LOG_ERR("Panic: %s", msg);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
k_sleep(K_FOREVER);
|
k_sleep(K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +95,7 @@ transmit(char buffer[], size_t len)
|
||||||
|
|
||||||
send_pkt = net_app_get_net_pkt(&app_ctx, AF_UNSPEC, BUF_ALLOC_TIMEOUT);
|
send_pkt = net_app_get_net_pkt(&app_ctx, AF_UNSPEC, BUF_ALLOC_TIMEOUT);
|
||||||
if (!send_pkt) {
|
if (!send_pkt) {
|
||||||
NET_ERR("Unable to get TX packet, not enough memory.");
|
LOG_ERR("Unable to get TX packet, not enough memory.");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,13 +121,13 @@ on_cmd_ping(char *umask, char *cmd, size_t len)
|
||||||
char pong[32];
|
char pong[32];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
NET_INFO("Got PING command from server: %s", cmd);
|
LOG_INF("Got PING command from server: %s", cmd);
|
||||||
|
|
||||||
ret = snprintk(pong, 32, "PONG :%s", cmd + 1);
|
ret = snprintk(pong, 32, "PONG :%s", cmd + 1);
|
||||||
if (ret < sizeof(pong)) {
|
if (ret < sizeof(pong)) {
|
||||||
ret = transmit(pong, ret);
|
ret = transmit(pong, ret);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_INFO("Transmit error: %d", ret);
|
LOG_INF("Transmit error: %d", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +142,7 @@ on_cmd_privmsg(char *umask, char *cmd, size_t len)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Got message from umask %s: %s", umask, cmd);
|
LOG_DBG("Got message from umask %s: %s", umask, cmd);
|
||||||
|
|
||||||
space = memchr(cmd, ' ', len);
|
space = memchr(cmd, ' ', len);
|
||||||
if (!space) {
|
if (!space) {
|
||||||
|
|
@ -153,7 +153,7 @@ on_cmd_privmsg(char *umask, char *cmd, size_t len)
|
||||||
|
|
||||||
if (*(space + 1) != ':') {
|
if (*(space + 1) != ':') {
|
||||||
/* Just ignore messages without a ':' after the space */
|
/* Just ignore messages without a ':' after the space */
|
||||||
NET_DBG("Ignoring message umask: %s: %s", umask, space);
|
LOG_DBG("Ignoring message umask: %s: %s", umask, space);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -203,11 +203,11 @@ process_command(char *cmd, size_t len)
|
||||||
|
|
||||||
cmd = space + 1;
|
cmd = space + 1;
|
||||||
|
|
||||||
NET_DBG("Received from server, umask=%s: %s", umask, cmd);
|
LOG_DBG("Received from server, umask=%s: %s", umask, cmd);
|
||||||
} else {
|
} else {
|
||||||
umask = NULL;
|
umask = NULL;
|
||||||
|
|
||||||
NET_DBG("Received from server (no umask): %s", cmd);
|
LOG_DBG("Received from server (no umask): %s", cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(commands); i++) {
|
for (i = 0; i < ARRAY_SIZE(commands); i++) {
|
||||||
|
|
@ -215,7 +215,7 @@ process_command(char *cmd, size_t len)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strncmp(cmd, commands[i].cmd, commands[i].cmd_len)) {
|
if (!strncmp(cmd, commands[i].cmd, commands[i].cmd_len)) {
|
||||||
NET_DBG("Command has handler, executing");
|
LOG_DBG("Command has handler, executing");
|
||||||
|
|
||||||
cmd += commands[i].cmd_len;
|
cmd += commands[i].cmd_len;
|
||||||
len -= commands[i].cmd_len;
|
len -= commands[i].cmd_len;
|
||||||
|
|
@ -226,7 +226,7 @@ process_command(char *cmd, size_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: handle notices, CTCP, etc */
|
/* TODO: handle notices, CTCP, etc */
|
||||||
NET_DBG("Could not find handler to handle %s, ignoring", cmd);
|
LOG_DBG("Could not find handler to handle %s, ignoring", cmd);
|
||||||
}
|
}
|
||||||
#undef CMD
|
#undef CMD
|
||||||
|
|
||||||
|
|
@ -239,13 +239,13 @@ on_context_recv(struct net_app_ctx *ctx, struct net_pkt *pkt,
|
||||||
|
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
/* TODO: notify of disconnection, maybe reconnect? */
|
/* TODO: notify of disconnection, maybe reconnect? */
|
||||||
NET_ERR("Disconnected");
|
LOG_ERR("Disconnected");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
/* TODO: handle connection error */
|
/* TODO: handle connection error */
|
||||||
NET_ERR("Connection error: %d", -status);
|
LOG_ERR("Connection error: %d", -status);
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -257,7 +257,7 @@ on_context_recv(struct net_app_ctx *ctx, struct net_pkt *pkt,
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (cmd_len >= CMD_BUFFER_SIZE) {
|
if (cmd_len >= CMD_BUFFER_SIZE) {
|
||||||
NET_WARN("cmd_buf overrun (>%d) Ignoring",
|
LOG_WRN("cmd_buf overrun (>%d) Ignoring",
|
||||||
CMD_BUFFER_SIZE);
|
CMD_BUFFER_SIZE);
|
||||||
cmd_len = 0U;
|
cmd_len = 0U;
|
||||||
}
|
}
|
||||||
|
|
@ -287,7 +287,7 @@ zirc_nick_set(const char *nick)
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
NET_INFO("Setting nickname to: %s", nick);
|
LOG_INF("Setting nickname to: %s", nick);
|
||||||
|
|
||||||
ret = snprintk(buffer, sizeof(buffer), "NICK %s\r\n", nick);
|
ret = snprintk(buffer, sizeof(buffer), "NICK %s\r\n", nick);
|
||||||
if (ret < 0 || ret >= sizeof(buffer)) {
|
if (ret < 0 || ret >= sizeof(buffer)) {
|
||||||
|
|
@ -303,7 +303,7 @@ zirc_user_set(const char *user, const char *realname)
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
NET_INFO("Setting user to: %s, real name to: %s", user, realname);
|
LOG_INF("Setting user to: %s, real name to: %s", user, realname);
|
||||||
|
|
||||||
ret = snprintk(buffer, sizeof(buffer), "USER %s * * :%s\r\n",
|
ret = snprintk(buffer, sizeof(buffer), "USER %s * * :%s\r\n",
|
||||||
user, realname);
|
user, realname);
|
||||||
|
|
@ -320,7 +320,7 @@ zirc_chan_join(const char *channel)
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
NET_INFO("Joining channel: %s", channel);
|
LOG_INF("Joining channel: %s", channel);
|
||||||
|
|
||||||
ret = snprintk(buffer, sizeof(buffer), "JOIN %s\r\n", channel);
|
ret = snprintk(buffer, sizeof(buffer), "JOIN %s\r\n", channel);
|
||||||
if (ret < 0 || ret >= sizeof(buffer)) {
|
if (ret < 0 || ret >= sizeof(buffer)) {
|
||||||
|
|
@ -337,7 +337,7 @@ zirc_chan_part(char *chan_name)
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
NET_INFO("Leaving channel: %s", chan_name);
|
LOG_INF("Leaving channel: %s", chan_name);
|
||||||
|
|
||||||
ret = snprintk(buffer, sizeof(buffer), "PART %s\r\n", chan_name);
|
ret = snprintk(buffer, sizeof(buffer), "PART %s\r\n", chan_name);
|
||||||
if (ret < 0 || ret >= sizeof(buffer)) {
|
if (ret < 0 || ret >= sizeof(buffer)) {
|
||||||
|
|
@ -357,13 +357,13 @@ zirc_connect(const char *host, int port)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
NET_INFO("Connecting to %s:%d...", host, port);
|
LOG_INF("Connecting to %s:%d...", host, port);
|
||||||
|
|
||||||
ret = net_app_init_tcp_client(&app_ctx, NULL, NULL,
|
ret = net_app_init_tcp_client(&app_ctx, NULL, NULL,
|
||||||
host, port,
|
host, port,
|
||||||
WAIT_TIMEOUT, NULL);
|
WAIT_TIMEOUT, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("net_app_init_tcp_client err:%d", ret);
|
LOG_ERR("net_app_init_tcp_client err:%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -374,13 +374,13 @@ zirc_connect(const char *host, int port)
|
||||||
/* set net_app callbacks */
|
/* set net_app callbacks */
|
||||||
ret = net_app_set_cb(&app_ctx, NULL, on_context_recv, NULL, NULL);
|
ret = net_app_set_cb(&app_ctx, NULL, on_context_recv, NULL, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Could not set receive callback (err:%d)", ret);
|
LOG_ERR("Could not set receive callback (err:%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = net_app_connect(&app_ctx, CONNECT_TIMEOUT);
|
ret = net_app_connect(&app_ctx, CONNECT_TIMEOUT);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot connect (%d)", ret);
|
LOG_ERR("Cannot connect (%d)", ret);
|
||||||
panic("Can't init network");
|
panic("Can't init network");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -401,7 +401,7 @@ zirc_connect(const char *host, int port)
|
||||||
static int
|
static int
|
||||||
zirc_disconnect(void)
|
zirc_disconnect(void)
|
||||||
{
|
{
|
||||||
NET_INFO("Disconnecting");
|
LOG_INF("Disconnecting");
|
||||||
cmd_len = 0U;
|
cmd_len = 0U;
|
||||||
net_app_close(&app_ctx);
|
net_app_close(&app_ctx);
|
||||||
return net_app_release(&app_ctx);
|
return net_app_release(&app_ctx);
|
||||||
|
|
@ -412,7 +412,7 @@ zirc_chan_send_msg(const char *chan_name, const char *msg)
|
||||||
{
|
{
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
|
|
||||||
NET_INFO("Sending to channel/user %s: %s", chan_name, msg);
|
LOG_INF("Sending to channel/user %s: %s", chan_name, msg);
|
||||||
|
|
||||||
while (*msg) {
|
while (*msg) {
|
||||||
int msglen, txret;
|
int msglen, txret;
|
||||||
|
|
@ -592,7 +592,7 @@ on_msg_rcvd(char *chan_name, char *umask, char *msg)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Received from umask %s: %s", umask, msg);
|
LOG_DBG("Received from umask %s: %s", umask, msg);
|
||||||
|
|
||||||
end = strchr(umask, '!');
|
end = strchr(umask, '!');
|
||||||
if (!end) {
|
if (!end) {
|
||||||
|
|
@ -636,7 +636,7 @@ void main(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
NET_INFO(APP_BANNER);
|
LOG_INF(APP_BANNER);
|
||||||
|
|
||||||
led0 = device_get_binding(LED_GPIO_NAME);
|
led0 = device_get_binding(LED_GPIO_NAME);
|
||||||
if (led0) {
|
if (led0) {
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ static int well_known_core_get(struct coap_resource *resource,
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
NET_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(context, K_FOREVER);
|
pkt = net_pkt_get_tx(context, K_FOREVER);
|
||||||
frag = net_pkt_get_data(context, K_FOREVER);
|
frag = net_pkt_get_data(context, K_FOREVER);
|
||||||
|
|
@ -468,14 +468,14 @@ static void udp_receive(struct net_context *context,
|
||||||
|
|
||||||
r = coap_packet_parse(&request, pkt, options, opt_num);
|
r = coap_packet_parse(&request, pkt, options, opt_num);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Invalid data received (%d)\n", r);
|
LOG_ERR("Invalid data received (%d)\n", r);
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = coap_handle_request(&request, resources, options, opt_num);
|
r = coap_handle_request(&request, resources, options, opt_num);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("No handler for such request (%d)\n", r);
|
LOG_ERR("No handler for such request (%d)\n", r);
|
||||||
}
|
}
|
||||||
|
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
|
|
@ -494,21 +494,21 @@ static bool join_coap_multicast_group(void)
|
||||||
|
|
||||||
iface = net_if_get_default();
|
iface = net_if_get_default();
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
NET_ERR("Could not get default interface");
|
LOG_ERR("Could not get default interface");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv6_addr_add(net_if_get_default(),
|
ifaddr = net_if_ipv6_addr_add(net_if_get_default(),
|
||||||
&my_addr, NET_ADDR_MANUAL, 0);
|
&my_addr, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Could not add IPv6 address to default interface");
|
LOG_ERR("Could not add IPv6 address to default interface");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ifaddr->addr_state = NET_ADDR_PREFERRED;
|
ifaddr->addr_state = NET_ADDR_PREFERRED;
|
||||||
|
|
||||||
mcast = net_if_ipv6_maddr_add(iface, &mcast_addr.sin6_addr);
|
mcast = net_if_ipv6_maddr_add(iface, &mcast_addr.sin6_addr);
|
||||||
if (!mcast) {
|
if (!mcast) {
|
||||||
NET_ERR("Could not add multicast address to interface\n");
|
LOG_ERR("Could not add multicast address to interface\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -531,26 +531,26 @@ void main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!join_coap_multicast_group()) {
|
if (!join_coap_multicast_group()) {
|
||||||
NET_ERR("Could not join CoAP multicast group\n");
|
LOG_ERR("Could not join CoAP multicast group\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_get(PF_INET6, SOCK_DGRAM, IPPROTO_UDP, &context);
|
r = net_context_get(PF_INET6, SOCK_DGRAM, IPPROTO_UDP, &context);
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not get an UDP context\n");
|
LOG_ERR("Could not get an UDP context\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_bind(context, (struct sockaddr *) &any_addr,
|
r = net_context_bind(context, (struct sockaddr *) &any_addr,
|
||||||
sizeof(any_addr));
|
sizeof(any_addr));
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not bind the context\n");
|
LOG_ERR("Could not bind the context\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_recv(context, udp_receive, 0, NULL);
|
r = net_context_recv(context, udp_receive, 0, NULL);
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not receive in the context\n");
|
LOG_ERR("Could not receive in the context\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,32 +58,32 @@ static int setup_iface(struct net_if *iface, const char *ipv6_addr,
|
||||||
|
|
||||||
ret = net_eth_vlan_enable(iface, vlan_tag);
|
ret = net_eth_vlan_enable(iface, vlan_tag);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
LOG_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
LOG_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +127,7 @@ static enum net_verdict parse_lldp(struct net_if *iface, struct net_pkt *pkt)
|
||||||
struct net_buf *frag = pkt->frags;
|
struct net_buf *frag = pkt->frags;
|
||||||
u16_t pos = 0U;
|
u16_t pos = 0U;
|
||||||
|
|
||||||
NET_DBG("iface %p Parsing LLDP, len %u", iface, len);
|
LOG_DBG("iface %p Parsing LLDP, len %u", iface, len);
|
||||||
|
|
||||||
while (frag) {
|
while (frag) {
|
||||||
u16_t type_length;
|
u16_t type_length;
|
||||||
|
|
@ -135,11 +135,11 @@ static enum net_verdict parse_lldp(struct net_if *iface, struct net_pkt *pkt)
|
||||||
frag = net_frag_read_be16(frag, pos, &pos, &type_length);
|
frag = net_frag_read_be16(frag, pos, &pos, &type_length);
|
||||||
if (!frag) {
|
if (!frag) {
|
||||||
if (type_length == 0) {
|
if (type_length == 0) {
|
||||||
NET_DBG("End LLDP DU TLV");
|
LOG_DBG("End LLDP DU TLV");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_ERR("Parsing ended, pos %u", pos);
|
LOG_ERR("Parsing ended, pos %u", pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,20 +151,20 @@ static enum net_verdict parse_lldp(struct net_if *iface, struct net_pkt *pkt)
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case LLDP_TLV_CHASSIS_ID:
|
case LLDP_TLV_CHASSIS_ID:
|
||||||
NET_DBG("Chassis ID");
|
LOG_DBG("Chassis ID");
|
||||||
break;
|
break;
|
||||||
case LLDP_TLV_PORT_ID:
|
case LLDP_TLV_PORT_ID:
|
||||||
NET_DBG("Port ID");
|
LOG_DBG("Port ID");
|
||||||
break;
|
break;
|
||||||
case LLDP_TLV_TTL:
|
case LLDP_TLV_TTL:
|
||||||
NET_DBG("TTL");
|
LOG_DBG("TTL");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
NET_DBG("TLV Not parsed");
|
LOG_DBG("TLV Not parsed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("type_length %u type %u length %u pos %u",
|
LOG_DBG("type_length %u type %u length %u pos %u",
|
||||||
type_length, type, length, pos);
|
type_length, type, length, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,7 +175,7 @@ static enum net_verdict parse_lldp(struct net_if *iface, struct net_pkt *pkt)
|
||||||
static int init_app(void)
|
static int init_app(void)
|
||||||
{
|
{
|
||||||
if (init_vlan() < 0) {
|
if (init_vlan() < 0) {
|
||||||
NET_ERR("Cannot setup VLAN");
|
LOG_ERR("Cannot setup VLAN");
|
||||||
}
|
}
|
||||||
|
|
||||||
net_lldp_register_callback(ud.first, parse_lldp);
|
net_lldp_register_callback(ud.first, parse_lldp);
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,5 @@ LOG_MODULE_REGISTER(net_mdns_responder_sample, LOG_LEVEL_DBG);
|
||||||
*/
|
*/
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
NET_INFO("Waiting mDNS queries...");
|
LOG_INF("Waiting mDNS queries...");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ static int tls_init(void)
|
||||||
err = tls_credential_add(APP_CA_CERT_TAG, TLS_CREDENTIAL_CA_CERTIFICATE,
|
err = tls_credential_add(APP_CA_CERT_TAG, TLS_CREDENTIAL_CA_CERTIFICATE,
|
||||||
ca_certificate, sizeof(ca_certificate));
|
ca_certificate, sizeof(ca_certificate));
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
NET_ERR("Failed to register public certificate: %d", err);
|
LOG_ERR("Failed to register public certificate: %d", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -66,14 +66,14 @@ static int tls_init(void)
|
||||||
err = tls_credential_add(APP_PSK_TAG, TLS_CREDENTIAL_PSK,
|
err = tls_credential_add(APP_PSK_TAG, TLS_CREDENTIAL_PSK,
|
||||||
client_psk, sizeof(client_psk));
|
client_psk, sizeof(client_psk));
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
NET_ERR("Failed to register PSK: %d", err);
|
LOG_ERR("Failed to register PSK: %d", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tls_credential_add(APP_PSK_TAG, TLS_CREDENTIAL_PSK_ID,
|
err = tls_credential_add(APP_PSK_TAG, TLS_CREDENTIAL_PSK_ID,
|
||||||
client_psk_id, sizeof(client_psk_id) - 1);
|
client_psk_id, sizeof(client_psk_id) - 1);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
NET_ERR("Failed to register PSK ID: %d", err);
|
LOG_ERR("Failed to register PSK ID: %d", err);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ static bool fake_led;
|
||||||
|
|
||||||
static void panic(const char *msg)
|
static void panic(const char *msg)
|
||||||
{
|
{
|
||||||
NET_ERR("Panic: %s", msg);
|
LOG_ERR("Panic: %s", msg);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
k_sleep(K_FOREVER);
|
k_sleep(K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +105,7 @@ static int in_addr_set(sa_family_t family,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
NET_ERR("Invalid IP address: %s", log_strdup(ip_addr));
|
LOG_ERR("Invalid IP address: %s", log_strdup(ip_addr));
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +125,7 @@ static void initialize_network(void)
|
||||||
{
|
{
|
||||||
struct net_if *iface;
|
struct net_if *iface;
|
||||||
|
|
||||||
NET_INFO("Initializing network");
|
LOG_INF("Initializing network");
|
||||||
|
|
||||||
iface = net_if_get_default();
|
iface = net_if_get_default();
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
|
|
@ -139,26 +139,26 @@ static void initialize_network(void)
|
||||||
|
|
||||||
/* delay so DHCPv4 can assign IP */
|
/* delay so DHCPv4 can assign IP */
|
||||||
/* TODO: add a timeout/retry */
|
/* TODO: add a timeout/retry */
|
||||||
NET_INFO("Waiting for DHCP ...");
|
LOG_INF("Waiting for DHCP ...");
|
||||||
do {
|
do {
|
||||||
k_sleep(K_SECONDS(1));
|
k_sleep(K_SECONDS(1));
|
||||||
} while (net_ipv4_is_addr_unspecified(&iface->dhcpv4.requested_ip));
|
} while (net_ipv4_is_addr_unspecified(&iface->dhcpv4.requested_ip));
|
||||||
|
|
||||||
NET_INFO("Done!");
|
LOG_INF("Done!");
|
||||||
|
|
||||||
/* TODO: add a timeout */
|
/* TODO: add a timeout */
|
||||||
NET_INFO("Waiting for IP assginment ...");
|
LOG_INF("Waiting for IP assginment ...");
|
||||||
do {
|
do {
|
||||||
k_sleep(K_SECONDS(1));
|
k_sleep(K_SECONDS(1));
|
||||||
} while (!net_ipv4_is_my_addr(&iface->dhcpv4.requested_ip));
|
} while (!net_ipv4_is_my_addr(&iface->dhcpv4.requested_ip));
|
||||||
|
|
||||||
NET_INFO("Done!");
|
LOG_INF("Done!");
|
||||||
#else
|
#else
|
||||||
struct sockaddr addr;
|
struct sockaddr addr;
|
||||||
|
|
||||||
if (in_addr_set(NATS_AF_INET, NATS_LOCAL_IP_ADDR, 0,
|
if (in_addr_set(NATS_AF_INET, NATS_LOCAL_IP_ADDR, 0,
|
||||||
&addr) < 0) {
|
&addr) < 0) {
|
||||||
NET_ERR("Invalid IP address: %s",
|
LOG_ERR("Invalid IP address: %s",
|
||||||
NATS_LOCAL_IP_ADDR);
|
NATS_LOCAL_IP_ADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -241,7 +241,7 @@ static int on_msg_received(const struct nats *nats,
|
||||||
|
|
||||||
static void initialize_hardware(void)
|
static void initialize_hardware(void)
|
||||||
{
|
{
|
||||||
NET_INFO("Initializing hardware");
|
LOG_INF("Initializing hardware");
|
||||||
|
|
||||||
led0 = device_get_binding(LED_GPIO_NAME);
|
led0 = device_get_binding(LED_GPIO_NAME);
|
||||||
if (led0) {
|
if (led0) {
|
||||||
|
|
@ -257,12 +257,12 @@ static int connect(struct nats *nats, u16_t port)
|
||||||
struct sockaddr dst_addr, src_addr;
|
struct sockaddr dst_addr, src_addr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
NET_INFO("Connecting...");
|
LOG_INF("Connecting...");
|
||||||
|
|
||||||
ret = net_context_get(NATS_AF_INET, SOCK_STREAM, IPPROTO_TCP,
|
ret = net_context_get(NATS_AF_INET, SOCK_STREAM, IPPROTO_TCP,
|
||||||
&nats->conn);
|
&nats->conn);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_DBG("Could not get new context: %d", ret);
|
LOG_DBG("Could not get new context: %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -291,7 +291,7 @@ static int connect(struct nats *nats, u16_t port)
|
||||||
ret = net_context_bind(nats->conn, &src_addr,
|
ret = net_context_bind(nats->conn, &src_addr,
|
||||||
sizeof(struct NATS_SOCKADDR_IN));
|
sizeof(struct NATS_SOCKADDR_IN));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_DBG("Could not bind to local address: %d", -ret);
|
LOG_DBG("Could not bind to local address: %d", -ret);
|
||||||
goto connect_exit;
|
goto connect_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,7 +311,7 @@ static void nats_client(void)
|
||||||
.on_message = on_msg_received
|
.on_message = on_msg_received
|
||||||
};
|
};
|
||||||
|
|
||||||
NET_INFO("NATS Client Sample");
|
LOG_INF("NATS Client Sample");
|
||||||
|
|
||||||
initialize_network();
|
initialize_network();
|
||||||
initialize_hardware();
|
initialize_hardware();
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,12 @@ static void iface_cb(struct net_if *iface, void *user_data)
|
||||||
|
|
||||||
ret = net_promisc_mode_on(iface);
|
ret = net_promisc_mode_on(iface);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_INFO("Cannot set promiscuous mode for interface %p (%d)",
|
LOG_INF("Cannot set promiscuous mode for interface %p (%d)",
|
||||||
iface, ret);
|
iface, ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("Promiscuous mode enabled for interface %p", iface);
|
LOG_INF("Promiscuous mode enabled for interface %p", iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_ports(struct net_pkt *pkt, u16_t *src, u16_t *dst)
|
static int get_ports(struct net_pkt *pkt, u16_t *src, u16_t *dst)
|
||||||
|
|
@ -77,8 +77,8 @@ static void print_info(struct net_pkt *pkt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (family == AF_UNSPEC) {
|
if (family == AF_UNSPEC) {
|
||||||
NET_INFO("Recv %p len %d (unknown address family)",
|
LOG_INF("Recv %p len %d (unknown address family)",
|
||||||
pkt, net_pkt_get_len(pkt));
|
pkt, net_pkt_get_len(pkt));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,7 +103,7 @@ static void print_info(struct net_pkt *pkt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot get port numbers for pkt %p", pkt);
|
LOG_ERR("Cannot get port numbers for pkt %p", pkt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,25 +116,25 @@ static void print_info(struct net_pkt *pkt)
|
||||||
|
|
||||||
if (family == AF_INET) {
|
if (family == AF_INET) {
|
||||||
if (next_hdr == IPPROTO_TCP || next_hdr == IPPROTO_UDP) {
|
if (next_hdr == IPPROTO_TCP || next_hdr == IPPROTO_UDP) {
|
||||||
NET_INFO("%s %s (%zd) %s:%u -> %s:%u",
|
LOG_INF("%s %s (%zd) %s:%u -> %s:%u",
|
||||||
"IPv4", proto, len,
|
"IPv4", proto, len,
|
||||||
log_strdup(src_addr), src_port,
|
log_strdup(src_addr), src_port,
|
||||||
log_strdup(dst_addr), dst_port);
|
log_strdup(dst_addr), dst_port);
|
||||||
} else {
|
} else {
|
||||||
NET_INFO("%s %s (%zd) %s -> %s", "IPv4", proto,
|
LOG_INF("%s %s (%zd) %s -> %s", "IPv4", proto,
|
||||||
len, log_strdup(src_addr),
|
len, log_strdup(src_addr),
|
||||||
log_strdup(dst_addr));
|
log_strdup(dst_addr));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (next_hdr == IPPROTO_TCP || next_hdr == IPPROTO_UDP) {
|
if (next_hdr == IPPROTO_TCP || next_hdr == IPPROTO_UDP) {
|
||||||
NET_INFO("%s %s (%zd) [%s]:%u -> [%s]:%u",
|
LOG_INF("%s %s (%zd) [%s]:%u -> [%s]:%u",
|
||||||
"IPv6", proto, len,
|
"IPv6", proto, len,
|
||||||
log_strdup(src_addr), src_port,
|
log_strdup(src_addr), src_port,
|
||||||
log_strdup(dst_addr), dst_port);
|
log_strdup(dst_addr), dst_port);
|
||||||
} else {
|
} else {
|
||||||
NET_INFO("%s %s (%zd) %s -> %s", "IPv6", proto,
|
LOG_INF("%s %s (%zd) %s -> %s", "IPv6", proto,
|
||||||
len, log_strdup(src_addr),
|
len, log_strdup(src_addr),
|
||||||
log_strdup(dst_addr));
|
log_strdup(dst_addr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -161,13 +161,13 @@ static bool toggle_led(const struct sockaddr_in6 *peer, u16_t id)
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(coap, PKT_WAIT_TIME);
|
pkt = net_pkt_get_tx(coap, PKT_WAIT_TIME);
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
NET_ERR("Ran out of network packets");
|
LOG_ERR("Ran out of network packets");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = net_pkt_get_data(coap, PKT_WAIT_TIME);
|
frag = net_pkt_get_data(coap, PKT_WAIT_TIME);
|
||||||
if (!frag) {
|
if (!frag) {
|
||||||
NET_ERR("Ran out of network buffers");
|
LOG_ERR("Ran out of network buffers");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,7 +176,7 @@ static bool toggle_led(const struct sockaddr_in6 *peer, u16_t id)
|
||||||
r = coap_packet_init(&request, pkt, 1, COAP_TYPE_NON_CON,
|
r = coap_packet_init(&request, pkt, 1, COAP_TYPE_NON_CON,
|
||||||
0, NULL, COAP_METHOD_POST, id);
|
0, NULL, COAP_METHOD_POST, id);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to initialize CoAP packet");
|
LOG_ERR("Failed to initialize CoAP packet");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,7 +184,7 @@ static bool toggle_led(const struct sockaddr_in6 *peer, u16_t id)
|
||||||
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
||||||
*p, strlen(*p));
|
*p, strlen(*p));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Unable add option to request.\n");
|
LOG_ERR("Unable add option to request.\n");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +193,7 @@ static bool toggle_led(const struct sockaddr_in6 *peer, u16_t id)
|
||||||
sizeof(struct sockaddr_in6),
|
sizeof(struct sockaddr_in6),
|
||||||
NULL, 0, NULL, NULL);
|
NULL, 0, NULL, NULL);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Cannot send data to peer (%d)", r);
|
LOG_ERR("Cannot send data to peer (%d)", r);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -214,13 +214,13 @@ static bool set_rpl_observer(const struct sockaddr_in6 *peer, u16_t id)
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(coap, PKT_WAIT_TIME);
|
pkt = net_pkt_get_tx(coap, PKT_WAIT_TIME);
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
NET_ERR("Ran out of network packets");
|
LOG_ERR("Ran out of network packets");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = net_pkt_get_data(coap, PKT_WAIT_TIME);
|
frag = net_pkt_get_data(coap, PKT_WAIT_TIME);
|
||||||
if (!frag) {
|
if (!frag) {
|
||||||
NET_ERR("Ran out of network buffers");
|
LOG_ERR("Ran out of network buffers");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -230,13 +230,13 @@ static bool set_rpl_observer(const struct sockaddr_in6 *peer, u16_t id)
|
||||||
8, coap_next_token(),
|
8, coap_next_token(),
|
||||||
COAP_METHOD_GET, id);
|
COAP_METHOD_GET, id);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to initialize CoAP packet");
|
LOG_ERR("Failed to initialize CoAP packet");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = coap_append_option_int(&request, COAP_OPTION_OBSERVE, 0);
|
r = coap_append_option_int(&request, COAP_OPTION_OBSERVE, 0);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Unable add option to request");
|
LOG_ERR("Unable add option to request");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,7 +244,7 @@ static bool set_rpl_observer(const struct sockaddr_in6 *peer, u16_t id)
|
||||||
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
||||||
*p, strlen(*p));
|
*p, strlen(*p));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Unable add option to request");
|
LOG_ERR("Unable add option to request");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -253,7 +253,7 @@ static bool set_rpl_observer(const struct sockaddr_in6 *peer, u16_t id)
|
||||||
sizeof(struct sockaddr_in6),
|
sizeof(struct sockaddr_in6),
|
||||||
NULL, 0, NULL, NULL);
|
NULL, 0, NULL, NULL);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Cannot send data to peer (%d)", r);
|
LOG_ERR("Cannot send data to peer (%d)", r);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -387,12 +387,12 @@ static void node_obs_reply(struct coap_packet *response, void *user_data)
|
||||||
|
|
||||||
frag = coap_packet_get_payload(response, &offset, &len);
|
frag = coap_packet_get_payload(response, &offset, &len);
|
||||||
if (!frag && offset == 0xffff) {
|
if (!frag && offset == 0xffff) {
|
||||||
NET_ERR("Error while getting payload");
|
LOG_ERR("Error while getting payload");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!len) {
|
if (!len) {
|
||||||
NET_ERR("Invalid response");
|
LOG_ERR("Invalid response");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -441,7 +441,7 @@ static void node_obs_reply(struct coap_packet *response, void *user_data)
|
||||||
rank_str[i] = '\0';
|
rank_str[i] = '\0';
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, parent_str, &parent) < 0) {
|
if (net_addr_pton(AF_INET6, parent_str, &parent) < 0) {
|
||||||
NET_ERR("Failed to convert parent address");
|
LOG_ERR("Failed to convert parent address");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -468,7 +468,7 @@ static void pkt_receive(struct net_context *context,
|
||||||
|
|
||||||
r = coap_packet_parse(&response, pkt, options, opt_num);
|
r = coap_packet_parse(&response, pkt, options, opt_num);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Invalid data received (%d)\n", r);
|
LOG_ERR("Invalid data received (%d)\n", r);
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -479,12 +479,12 @@ static void pkt_receive(struct net_context *context,
|
||||||
get_from_ip_addr(&response, &from);
|
get_from_ip_addr(&response, &from);
|
||||||
|
|
||||||
if (type != COAP_TYPE_ACK) {
|
if (type != COAP_TYPE_ACK) {
|
||||||
NET_ERR("Invalid response, type %d", type);
|
LOG_ERR("Invalid response, type %d", type);
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Received %d bytes coap payload",
|
LOG_DBG("Received %d bytes coap payload",
|
||||||
net_pkt_appdatalen(pkt) - response.hdr_len - response.opt_len);
|
net_pkt_appdatalen(pkt) - response.hdr_len - response.opt_len);
|
||||||
|
|
||||||
coap_req = get_coap_request_by_id(&from, id);
|
coap_req = get_coap_request_by_id(&from, id);
|
||||||
|
|
@ -494,7 +494,7 @@ static void pkt_receive(struct net_context *context,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code != coap_req->code) {
|
if (code != coap_req->code) {
|
||||||
NET_ERR("Invalid response, code %d", code);
|
LOG_ERR("Invalid response, code %d", code);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -555,7 +555,7 @@ void coap_send_request(struct in6_addr *peer_addr,
|
||||||
|
|
||||||
request = get_free_coap_request();
|
request = get_free_coap_request();
|
||||||
if (!request) {
|
if (!request) {
|
||||||
NET_ERR("Failed to get free coap request");
|
LOG_ERR("Failed to get free coap request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -591,7 +591,7 @@ int coap_init(void)
|
||||||
|
|
||||||
iface = net_if_get_ieee802154();
|
iface = net_if_get_ieee802154();
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
NET_ERR("No IEEE 802.15.4 network interface found.");
|
LOG_ERR("No IEEE 802.15.4 network interface found.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -612,20 +612,20 @@ int coap_init(void)
|
||||||
|
|
||||||
r = net_context_get(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, &coap);
|
r = net_context_get(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, &coap);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Could not get UDP context");
|
LOG_ERR("Could not get UDP context");
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_bind(coap, (struct sockaddr *) &my_addr,
|
r = net_context_bind(coap, (struct sockaddr *) &my_addr,
|
||||||
sizeof(my_addr));
|
sizeof(my_addr));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Could not bind to the context");
|
LOG_ERR("Could not bind to the context");
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_recv(coap, pkt_receive, 0, NULL);
|
r = net_context_recv(coap, pkt_receive, 0, NULL);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Could not set recv callback in the context");
|
LOG_ERR("Could not set recv callback in the context");
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,17 +156,17 @@ static struct http_server_urls http_urls;
|
||||||
static bool check_file_size(const char *file, size_t size)
|
static bool check_file_size(const char *file, size_t size)
|
||||||
{
|
{
|
||||||
if (size > MBEDTLS_SSL_MAX_CONTENT_LEN) {
|
if (size > MBEDTLS_SSL_MAX_CONTENT_LEN) {
|
||||||
NET_ERR("The MBEDTLS_SSL_MAX_CONTENT_LEN (%d) is too small.",
|
LOG_ERR("The MBEDTLS_SSL_MAX_CONTENT_LEN (%d) is too small.",
|
||||||
MBEDTLS_SSL_MAX_CONTENT_LEN);
|
MBEDTLS_SSL_MAX_CONTENT_LEN);
|
||||||
NET_ERR("Cannot send %s (len %zd)", file, size);
|
LOG_ERR("Cannot send %s (len %zd)", file, size);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size > RESULT_BUF_SIZE) {
|
if (size > RESULT_BUF_SIZE) {
|
||||||
NET_ERR("The RESULT_BUF_SIZE (%d) is too small.",
|
LOG_ERR("The RESULT_BUF_SIZE (%d) is too small.",
|
||||||
RESULT_BUF_SIZE);
|
RESULT_BUF_SIZE);
|
||||||
NET_ERR("Cannot send %s (len %zd)", file, size);
|
LOG_ERR("Cannot send %s (len %zd)", file, size);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +193,7 @@ static int setup_cert(struct net_app_ctx *ctx,
|
||||||
ret = mbedtls_x509_crt_parse(cert, echo_apps_cert_der,
|
ret = mbedtls_x509_crt_parse(cert, echo_apps_cert_der,
|
||||||
sizeof(echo_apps_cert_der));
|
sizeof(echo_apps_cert_der));
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
LOG_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,7 +201,7 @@ static int setup_cert(struct net_app_ctx *ctx,
|
||||||
sizeof(echo_apps_key_der),
|
sizeof(echo_apps_key_der),
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_pk_parse_key returned %d", ret);
|
LOG_ERR("mbedtls_pk_parse_key returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -222,7 +222,7 @@ static int http_response(struct http_ctx *ctx, const char *header,
|
||||||
|
|
||||||
ret = http_add_header(ctx, header, dst, NULL);
|
ret = http_add_header(ctx, header, dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot add HTTP header (%d)", ret);
|
LOG_ERR("Cannot add HTTP header (%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,7 +233,7 @@ static int http_response(struct http_ctx *ctx, const char *header,
|
||||||
|
|
||||||
ret = http_send_chunk(ctx, payload, payload_len, dst, NULL);
|
ret = http_send_chunk(ctx, payload, payload_len, dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send data to peer (%d)", ret);
|
LOG_ERR("Cannot send data to peer (%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,7 +266,7 @@ static int http_basic_auth(struct http_ctx *ctx,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
NET_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
ptr = strstr(ctx->http.field_values[0].key, auth_str);
|
ptr = strstr(ctx->http.field_values[0].key, auth_str);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
|
|
@ -333,7 +333,7 @@ static int http_serve_index_html(struct http_ctx *ctx,
|
||||||
|
|
||||||
check_file_size("index.html", sizeof(index_html_gz));
|
check_file_size("index.html", sizeof(index_html_gz));
|
||||||
|
|
||||||
NET_DBG("Sending index.html (%zd bytes) to client",
|
LOG_DBG("Sending index.html (%zd bytes) to client",
|
||||||
sizeof(index_html_gz));
|
sizeof(index_html_gz));
|
||||||
return http_response(ctx, HTTP_STATUS_200_OK_GZ, index_html_gz,
|
return http_response(ctx, HTTP_STATUS_200_OK_GZ, index_html_gz,
|
||||||
sizeof(index_html_gz), dst);
|
sizeof(index_html_gz), dst);
|
||||||
|
|
@ -348,7 +348,7 @@ static int http_serve_style_css(struct http_ctx *ctx,
|
||||||
|
|
||||||
check_file_size("style.css", sizeof(style_css_gz));
|
check_file_size("style.css", sizeof(style_css_gz));
|
||||||
|
|
||||||
NET_DBG("Sending style.css (%zd bytes) to client",
|
LOG_DBG("Sending style.css (%zd bytes) to client",
|
||||||
sizeof(style_css_gz));
|
sizeof(style_css_gz));
|
||||||
return http_response(ctx, HTTP_STATUS_200_OK_GZ_CSS,
|
return http_response(ctx, HTTP_STATUS_200_OK_GZ_CSS,
|
||||||
style_css_gz,
|
style_css_gz,
|
||||||
|
|
@ -365,7 +365,7 @@ static int http_serve_br_js(struct http_ctx *ctx,
|
||||||
|
|
||||||
check_file_size("br.js", sizeof(br_js_gz));
|
check_file_size("br.js", sizeof(br_js_gz));
|
||||||
|
|
||||||
NET_DBG("Sending br.js (%zd bytes) to client",
|
LOG_DBG("Sending br.js (%zd bytes) to client",
|
||||||
sizeof(br_js_gz));
|
sizeof(br_js_gz));
|
||||||
return http_response(ctx, HTTP_STATUS_200_OK_GZ_CSS,
|
return http_response(ctx, HTTP_STATUS_200_OK_GZ_CSS,
|
||||||
br_js_gz,
|
br_js_gz,
|
||||||
|
|
@ -381,7 +381,7 @@ static int http_serve_favicon_ico(struct http_ctx *ctx,
|
||||||
|
|
||||||
check_file_size("favicon.ico", sizeof(favicon_ico_gz));
|
check_file_size("favicon.ico", sizeof(favicon_ico_gz));
|
||||||
|
|
||||||
NET_DBG("Sending favicon.ico (%zd bytes) to client",
|
LOG_DBG("Sending favicon.ico (%zd bytes) to client",
|
||||||
sizeof(favicon_ico_gz));
|
sizeof(favicon_ico_gz));
|
||||||
return http_response(ctx, HTTP_STATUS_200_OK_GZ, favicon_ico_gz,
|
return http_response(ctx, HTTP_STATUS_200_OK_GZ, favicon_ico_gz,
|
||||||
sizeof(favicon_ico_gz), dst);
|
sizeof(favicon_ico_gz), dst);
|
||||||
|
|
@ -465,10 +465,10 @@ static int append_and_send_data(struct user_data *data,
|
||||||
ret = ws_send_msg_to_client(data->ctx, data->buf, len,
|
ret = ws_send_msg_to_client(data->ctx, data->buf, len,
|
||||||
opcode, final, data->dst, NULL);
|
opcode, final, data->dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_DBG("Could not send %d bytes data to client", len);
|
LOG_DBG("Could not send %d bytes data to client", len);
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
NET_DBG("Sent %d bytes to client", len);
|
LOG_DBG("Sent %d bytes to client", len);
|
||||||
}
|
}
|
||||||
|
|
||||||
data->msg_count = 0;
|
data->msg_count = 0;
|
||||||
|
|
@ -483,10 +483,10 @@ static int append_and_send_data(struct user_data *data,
|
||||||
ret = ws_send_msg_to_client(data->ctx, data->buf, len,
|
ret = ws_send_msg_to_client(data->ctx, data->buf, len,
|
||||||
opcode, final, data->dst, NULL);
|
opcode, final, data->dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_DBG("Could not send %d bytes data to client", len);
|
LOG_DBG("Could not send %d bytes data to client", len);
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
NET_DBG("Sent %d bytes to client", len);
|
LOG_DBG("Sent %d bytes to client", len);
|
||||||
}
|
}
|
||||||
|
|
||||||
data->msg_count++;
|
data->msg_count++;
|
||||||
|
|
@ -567,7 +567,7 @@ static void append_unicast_addr(struct net_if *iface, struct user_data *data)
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Out of mem");
|
LOG_ERR("Out of mem");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -612,7 +612,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!net_if_is_up(iface)) {
|
if (!net_if_is_up(iface)) {
|
||||||
NET_DBG("Interface %p is down", iface);
|
LOG_DBG("Interface %p is down", iface);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -654,7 +654,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Out of mem");
|
LOG_ERR("Out of mem");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -977,7 +977,7 @@ static int send_rpl_configuration(struct http_ctx *ctx,
|
||||||
|
|
||||||
ret = add_rpl_config(&data);
|
ret = add_rpl_config(&data);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Could not send RPL configuration");
|
LOG_ERR("Could not send RPL configuration");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1110,7 +1110,7 @@ static int send_ipv6_neighbors(struct http_ctx *ctx,
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
NET_DBG("Cannot send neighbor information");
|
LOG_DBG("Cannot send neighbor information");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -1156,7 +1156,7 @@ static int send_ipv6_neighbor_deletion(struct http_ctx *ctx,
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
NET_DBG("Cannot send neighbor information");
|
LOG_DBG("Cannot send neighbor information");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -1234,7 +1234,7 @@ static void append_route_iface(struct net_if *iface,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!net_if_is_up(iface)) {
|
if (!net_if_is_up(iface)) {
|
||||||
NET_DBG("Interface %p is down", iface);
|
LOG_DBG("Interface %p is down", iface);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1263,7 +1263,7 @@ static void append_route_iface(struct net_if *iface,
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Out of mem");
|
LOG_ERR("Out of mem");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1491,29 +1491,29 @@ static void ws_send_info(struct http_ctx *ctx,
|
||||||
|
|
||||||
ret = send_iface_configuration(ctx, dst);
|
ret = send_iface_configuration(ctx, dst);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send interface configuration (%d)", ret);
|
LOG_ERR("Cannot send interface configuration (%d)", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = send_rpl_configuration(ctx, dst);
|
ret = send_rpl_configuration(ctx, dst);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send RPL configuration (%d)", ret);
|
LOG_ERR("Cannot send RPL configuration (%d)", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = send_ipv6_neighbors(ctx, dst, NULL);
|
ret = send_ipv6_neighbors(ctx, dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send neighbor information (%d)", ret);
|
LOG_ERR("Cannot send neighbor information (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = send_ipv6_routes(ctx, dst, NULL, NULL);
|
ret = send_ipv6_routes(ctx, dst, NULL, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send route information (%d)", ret);
|
LOG_ERR("Cannot send route information (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = send_topology_information(ctx, dst);
|
ret = send_topology_information(ctx, dst);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send topology information (%d)", ret);
|
LOG_ERR("Cannot send topology information (%d)", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1540,7 +1540,7 @@ static void http_connected(struct http_ctx *ctx,
|
||||||
char url[32];
|
char url[32];
|
||||||
size_t len = min(sizeof(url) - 1, ctx->http.url_len);
|
size_t len = min(sizeof(url) - 1, ctx->http.url_len);
|
||||||
|
|
||||||
NET_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
if (0 && (!rpl.auth_ok || !check_addr(ctx))) {
|
if (0 && (!rpl.auth_ok || !check_addr(ctx))) {
|
||||||
rpl.auth_ok = false;
|
rpl.auth_ok = false;
|
||||||
|
|
@ -1551,7 +1551,7 @@ static void http_connected(struct http_ctx *ctx,
|
||||||
memcpy(url, ctx->http.url, len);
|
memcpy(url, ctx->http.url, len);
|
||||||
url[len] = '\0';
|
url[len] = '\0';
|
||||||
|
|
||||||
NET_DBG("%s connect attempt URL %s",
|
LOG_DBG("%s connect attempt URL %s",
|
||||||
type == HTTP_CONNECTION ? "HTTP" :
|
type == HTTP_CONNECTION ? "HTTP" :
|
||||||
(type == WS_CONNECTION ? "WS" : "<unknown>"), url);
|
(type == WS_CONNECTION ? "WS" : "<unknown>"), url);
|
||||||
|
|
||||||
|
|
@ -1642,7 +1642,7 @@ static void handle_coap_request(struct http_ctx *ctx,
|
||||||
|
|
||||||
len = net_pkt_appdatalen(pkt);
|
len = net_pkt_appdatalen(pkt);
|
||||||
if (len > MAX_PAYLOAD_LEN - 1) {
|
if (len > MAX_PAYLOAD_LEN - 1) {
|
||||||
NET_ERR("Can't handle payload more than %d(%d)",
|
LOG_ERR("Can't handle payload more than %d(%d)",
|
||||||
MAX_PAYLOAD_LEN, len);
|
MAX_PAYLOAD_LEN, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1654,7 +1654,7 @@ static void handle_coap_request(struct http_ctx *ctx,
|
||||||
|
|
||||||
frag = net_frag_read(frag, pos, &pos, len, &payload[0]);
|
frag = net_frag_read(frag, pos, &pos, len, &payload[0]);
|
||||||
if (!frag && pos == 0xffff) {
|
if (!frag && pos == 0xffff) {
|
||||||
NET_WARN("Failed to read payload");
|
LOG_WRN("Failed to read payload");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1663,25 +1663,25 @@ static void handle_coap_request(struct http_ctx *ctx,
|
||||||
ret = json_obj_parse((char *)payload, len, coap_descr,
|
ret = json_obj_parse((char *)payload, len, coap_descr,
|
||||||
ARRAY_SIZE(coap_descr), &req);
|
ARRAY_SIZE(coap_descr), &req);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Failed to parse JSON string %d", ret);
|
LOG_ERR("Failed to parse JSON string %d", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = net_addr_pton(AF_INET6, req.coap.ipv6_addr, &peer_addr);
|
ret = net_addr_pton(AF_INET6, req.coap.ipv6_addr, &peer_addr);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_WARN("Invalid peer address %s", req.coap.ipv6_addr);
|
LOG_WRN("Invalid peer address %s", req.coap.ipv6_addr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(req.coap.command, "toggle") == 0) {
|
if (strcmp(req.coap.command, "toggle") == 0) {
|
||||||
type = COAP_REQ_TOGGLE_LED;
|
type = COAP_REQ_TOGGLE_LED;
|
||||||
} else {
|
} else {
|
||||||
NET_WARN("Invalid coap command %s", req.coap.command);
|
LOG_WRN("Invalid coap command %s", req.coap.command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
coap_send_request(&peer_addr, type, NULL, NULL);
|
coap_send_request(&peer_addr, type, NULL, NULL);
|
||||||
NET_DBG("Send CoAP request '%s'-'%s'", req.coap.command,
|
LOG_DBG("Send CoAP request '%s'-'%s'", req.coap.command,
|
||||||
req.coap.ipv6_addr);
|
req.coap.ipv6_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1693,19 +1693,19 @@ static void http_received(struct http_ctx *ctx,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
NET_DBG("Received NULL packet for unknown reason");
|
LOG_DBG("Received NULL packet for unknown reason");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
NET_DBG("Received %d bytes data", net_pkt_appdatalen(pkt));
|
LOG_DBG("Received %d bytes data", net_pkt_appdatalen(pkt));
|
||||||
|
|
||||||
if (!strncmp((char *)net_pkt_appdata(pkt), JSON_COAP_PREFIX,
|
if (!strncmp((char *)net_pkt_appdata(pkt), JSON_COAP_PREFIX,
|
||||||
sizeof(JSON_COAP_PREFIX) - 1)) {
|
sizeof(JSON_COAP_PREFIX) - 1)) {
|
||||||
handle_coap_request(ctx, pkt, user_data);
|
handle_coap_request(ctx, pkt, user_data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
NET_ERR("Receive error (%d)", status);
|
LOG_ERR("Receive error (%d)", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
|
|
@ -1716,14 +1716,14 @@ static void http_sent(struct http_ctx *ctx,
|
||||||
void *user_data_send,
|
void *user_data_send,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
NET_DBG("Data sent status %d", status);
|
LOG_DBG("Data sent status %d", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void http_closed(struct http_ctx *ctx,
|
static void http_closed(struct http_ctx *ctx,
|
||||||
int status,
|
int status,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
NET_DBG("Connection %p closed", ctx);
|
LOG_DBG("Connection %p closed", ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *get_string(int str_len, const char *str)
|
static const char *get_string(int str_len, const char *str)
|
||||||
|
|
@ -1741,7 +1741,7 @@ static enum http_verdict default_handler(struct http_ctx *ctx,
|
||||||
enum http_connection_type type,
|
enum http_connection_type type,
|
||||||
const struct sockaddr *dst)
|
const struct sockaddr *dst)
|
||||||
{
|
{
|
||||||
NET_DBG("No handler for %s URL %s",
|
LOG_DBG("No handler for %s URL %s",
|
||||||
type == HTTP_CONNECTION ? "HTTP" : "WS",
|
type == HTTP_CONNECTION ? "HTTP" : "WS",
|
||||||
get_string(ctx->http.url_len, ctx->http.url));
|
get_string(ctx->http.url_len, ctx->http.url));
|
||||||
|
|
||||||
|
|
@ -1758,7 +1758,7 @@ static void coap_obs_cb(struct coap_packet *response, void *user_data)
|
||||||
|
|
||||||
ret = send_topology_information(&http_ctx, ws_dst);
|
ret = send_topology_information(&http_ctx, ws_dst);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send topology (%d)", ret);
|
LOG_ERR("Cannot send topology (%d)", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1767,7 +1767,7 @@ static void mgmt_cb(struct net_mgmt_event_callback *cb,
|
||||||
u32_t mgmt_event, struct net_if *iface)
|
u32_t mgmt_event, struct net_if *iface)
|
||||||
{
|
{
|
||||||
#if !defined(CONFIG_NET_L2_IEEE802154)
|
#if !defined(CONFIG_NET_L2_IEEE802154)
|
||||||
NET_DBG("CONFIG_NET_L2_IEEE802154 not enabled");
|
LOG_DBG("CONFIG_NET_L2_IEEE802154 not enabled");
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
struct net_if *iface_802154 = net_if_get_ieee802154();
|
struct net_if *iface_802154 = net_if_get_ieee802154();
|
||||||
|
|
@ -1788,58 +1788,58 @@ static void mgmt_cb(struct net_mgmt_event_callback *cb,
|
||||||
if (mgmt_event == NET_EVENT_IPV6_NBR_ADD) {
|
if (mgmt_event == NET_EVENT_IPV6_NBR_ADD) {
|
||||||
nbr_info = (struct net_event_ipv6_nbr *)cb->info;
|
nbr_info = (struct net_event_ipv6_nbr *)cb->info;
|
||||||
if (!nbr_info) {
|
if (!nbr_info) {
|
||||||
NET_ERR("Invalid info received on event");
|
LOG_ERR("Invalid info received on event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbr = net_ipv6_nbr_lookup(iface, &nbr_info->addr);
|
nbr = net_ipv6_nbr_lookup(iface, &nbr_info->addr);
|
||||||
if (!nbr || !net_ipv6_nbr_data(nbr)) {
|
if (!nbr || !net_ipv6_nbr_data(nbr)) {
|
||||||
NET_ERR("Invalid neighbor data received");
|
LOG_ERR("Invalid neighbor data received");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("NBR add %s",
|
LOG_DBG("NBR add %s",
|
||||||
log_strdup(net_sprint_ipv6_addr(&nbr_info->addr)));
|
log_strdup(net_sprint_ipv6_addr(&nbr_info->addr)));
|
||||||
|
|
||||||
ret = send_ipv6_neighbors(&http_ctx, ws_dst, nbr);
|
ret = send_ipv6_neighbors(&http_ctx, ws_dst, nbr);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send neighbor information (%d)", ret);
|
LOG_ERR("Cannot send neighbor information (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (mgmt_event == NET_EVENT_IPV6_NBR_DEL) {
|
} else if (mgmt_event == NET_EVENT_IPV6_NBR_DEL) {
|
||||||
nbr_info = (struct net_event_ipv6_nbr *)cb->info;
|
nbr_info = (struct net_event_ipv6_nbr *)cb->info;
|
||||||
if (!nbr_info) {
|
if (!nbr_info) {
|
||||||
NET_ERR("Invalid info received on event");
|
LOG_ERR("Invalid info received on event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("NBR del %s",
|
LOG_DBG("NBR del %s",
|
||||||
log_strdup(net_sprint_ipv6_addr(&nbr_info->addr)));
|
log_strdup(net_sprint_ipv6_addr(&nbr_info->addr)));
|
||||||
|
|
||||||
ret = send_ipv6_neighbor_deletion(&http_ctx, ws_dst, iface,
|
ret = send_ipv6_neighbor_deletion(&http_ctx, ws_dst, iface,
|
||||||
&nbr_info->addr);
|
&nbr_info->addr);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send neighbor information (%d)", ret);
|
LOG_ERR("Cannot send neighbor information (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (mgmt_event == NET_EVENT_IPV6_ROUTE_ADD) {
|
} else if (mgmt_event == NET_EVENT_IPV6_ROUTE_ADD) {
|
||||||
route_info = (struct net_event_ipv6_route *)cb->info;
|
route_info = (struct net_event_ipv6_route *)cb->info;
|
||||||
if (!route_info) {
|
if (!route_info) {
|
||||||
NET_ERR("Invalid info received on event");
|
LOG_ERR("Invalid info received on event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
route = net_route_lookup(iface, &route_info->addr);
|
route = net_route_lookup(iface, &route_info->addr);
|
||||||
if (!route) {
|
if (!route) {
|
||||||
NET_ERR("Invalid route entry received");
|
LOG_ERR("Invalid route entry received");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("ROUTE add addr %s/%d",
|
LOG_DBG("ROUTE add addr %s/%d",
|
||||||
log_strdup(net_sprint_ipv6_addr(&route_info->addr)),
|
log_strdup(net_sprint_ipv6_addr(&route_info->addr)),
|
||||||
route_info->prefix_len);
|
route_info->prefix_len);
|
||||||
{
|
{
|
||||||
NET_DBG("ROUTE add nexthop %s",
|
LOG_DBG("ROUTE add nexthop %s",
|
||||||
log_strdup(net_sprint_ipv6_addr(
|
log_strdup(net_sprint_ipv6_addr(
|
||||||
&route_info->nexthop)));
|
&route_info->nexthop)));
|
||||||
|
|
||||||
|
|
@ -1850,27 +1850,27 @@ static void mgmt_cb(struct net_mgmt_event_callback *cb,
|
||||||
|
|
||||||
ret = send_ipv6_routes(&http_ctx, ws_dst, iface, route);
|
ret = send_ipv6_routes(&http_ctx, ws_dst, iface, route);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send route information (%d)", ret);
|
LOG_ERR("Cannot send route information (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (mgmt_event == NET_EVENT_IPV6_ROUTE_DEL) {
|
} else if (mgmt_event == NET_EVENT_IPV6_ROUTE_DEL) {
|
||||||
route_info = (struct net_event_ipv6_route *)cb->info;
|
route_info = (struct net_event_ipv6_route *)cb->info;
|
||||||
if (!route_info) {
|
if (!route_info) {
|
||||||
NET_ERR("Invalid info received on event");
|
LOG_ERR("Invalid info received on event");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("ROUTE del addr %s/%d",
|
LOG_DBG("ROUTE del addr %s/%d",
|
||||||
log_strdup(net_sprint_ipv6_addr(&route_info->addr)),
|
log_strdup(net_sprint_ipv6_addr(&route_info->addr)),
|
||||||
route_info->prefix_len);
|
route_info->prefix_len);
|
||||||
NET_DBG("ROUTE del nexthop %s",
|
LOG_DBG("ROUTE del nexthop %s",
|
||||||
log_strdup(net_sprint_ipv6_addr(
|
log_strdup(net_sprint_ipv6_addr(
|
||||||
&route_info->nexthop)));
|
&route_info->nexthop)));
|
||||||
|
|
||||||
ret = send_ipv6_route_deletion(&http_ctx, ws_dst, iface,
|
ret = send_ipv6_route_deletion(&http_ctx, ws_dst, iface,
|
||||||
route_info);
|
route_info);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send route information (%d)", ret);
|
LOG_ERR("Cannot send route information (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1878,7 +1878,7 @@ static void mgmt_cb(struct net_mgmt_event_callback *cb,
|
||||||
|
|
||||||
ret = send_topology_information(&http_ctx, ws_dst);
|
ret = send_topology_information(&http_ctx, ws_dst);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send topology information (%d)", ret);
|
LOG_ERR("Cannot send topology information (%d)", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1943,7 +1943,7 @@ void start_http_server(struct net_if *iface)
|
||||||
|
|
||||||
ret = net_ipaddr_parse(ZEPHYR_ADDR, strlen(ZEPHYR_ADDR), &addr);
|
ret = net_ipaddr_parse(ZEPHYR_ADDR, strlen(ZEPHYR_ADDR), &addr);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot set local address (%d)", ret);
|
LOG_ERR("Cannot set local address (%d)", ret);
|
||||||
panic(NULL);
|
panic(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1967,7 +1967,7 @@ void start_http_server(struct net_if *iface)
|
||||||
result, sizeof(result),
|
result, sizeof(result),
|
||||||
"Zephyr HTTP Server for border router", NULL);
|
"Zephyr HTTP Server for border router", NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init web server (%d)", ret);
|
LOG_ERR("Cannot init web server (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1990,7 +1990,7 @@ void start_http_server(struct net_if *iface)
|
||||||
https_stack,
|
https_stack,
|
||||||
K_THREAD_STACK_SIZEOF(https_stack));
|
K_THREAD_STACK_SIZEOF(https_stack));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable TLS support (%d)", ret);
|
LOG_ERR("Cannot enable TLS support (%d)", ret);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,12 @@ void main(void)
|
||||||
{
|
{
|
||||||
struct net_if *iface = NULL, *mgmt_iface = NULL;
|
struct net_if *iface = NULL, *mgmt_iface = NULL;
|
||||||
|
|
||||||
NET_DBG("RPL border router starting");
|
LOG_DBG("RPL border router starting");
|
||||||
|
|
||||||
#if defined(CONFIG_NET_L2_IEEE802154)
|
#if defined(CONFIG_NET_L2_IEEE802154)
|
||||||
iface = net_if_get_ieee802154();
|
iface = net_if_get_ieee802154();
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
NET_INFO("No IEEE 802.15.4 network interface found.");
|
LOG_INF("No IEEE 802.15.4 network interface found.");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#if defined(CONFIG_QEMU_TARGET)
|
#if defined(CONFIG_QEMU_TARGET)
|
||||||
|
|
@ -37,14 +37,14 @@ void main(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
NET_INFO("Cannot continue because no suitable network "
|
LOG_INF("Cannot continue because no suitable network "
|
||||||
"interface exists.");
|
"interface exists.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mgmt_iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET));
|
mgmt_iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET));
|
||||||
if (!mgmt_iface) {
|
if (!mgmt_iface) {
|
||||||
NET_INFO("No management network interface found.");
|
LOG_INF("No management network interface found.");
|
||||||
} else {
|
} else {
|
||||||
start_http_server(mgmt_iface);
|
start_http_server(mgmt_iface);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ static bool br_join_dag(struct net_rpl_dio *dio)
|
||||||
if (net_ipv6_addr_cmp(&dio->dag_id, &rpl.dag_id)) {
|
if (net_ipv6_addr_cmp(&dio->dag_id, &rpl.dag_id)) {
|
||||||
if (rpl.dag_init_version != dio->version &&
|
if (rpl.dag_init_version != dio->version &&
|
||||||
last_version != dio->version) {
|
last_version != dio->version) {
|
||||||
NET_DBG("Me root, DIO version %d instance %d",
|
LOG_DBG("Me root, DIO version %d instance %d",
|
||||||
dio->version, dio->instance_id);
|
dio->version, dio->instance_id);
|
||||||
last_version = dio->version;
|
last_version = dio->version;
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +53,7 @@ static bool br_join_dag(struct net_rpl_dio *dio)
|
||||||
net_addr_ntop(AF_INET6, &rpl.dag_id, me,
|
net_addr_ntop(AF_INET6, &rpl.dag_id, me,
|
||||||
NET_IPV6_ADDR_LEN);
|
NET_IPV6_ADDR_LEN);
|
||||||
|
|
||||||
NET_DBG("Other root %s, me %s, "
|
LOG_DBG("Other root %s, me %s, "
|
||||||
"DIO version %d instance %d",
|
"DIO version %d instance %d",
|
||||||
log_strdup(other), log_strdup(me),
|
log_strdup(other), log_strdup(me),
|
||||||
dio->version, dio->instance_id);
|
dio->version, dio->instance_id);
|
||||||
|
|
@ -86,12 +86,12 @@ bool setup_rpl(struct net_if *iface, const char *addr_prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rpl.prefix_len == 0) {
|
if (rpl.prefix_len == 0) {
|
||||||
NET_ERR("Invalid prefix length %s", log_strdup(slash + 1));
|
LOG_ERR("Invalid prefix length %s", log_strdup(slash + 1));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, prefix, &rpl.prefix) < 0) {
|
if (net_addr_pton(AF_INET6, prefix, &rpl.prefix) < 0) {
|
||||||
NET_ERR("Invalid IPv6 prefix %s", log_strdup(prefix));
|
LOG_ERR("Invalid IPv6 prefix %s", log_strdup(prefix));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ bool setup_rpl(struct net_if *iface, const char *addr_prefix)
|
||||||
&rpl.prefix);
|
&rpl.prefix);
|
||||||
}
|
}
|
||||||
if (!dag) {
|
if (!dag) {
|
||||||
NET_ERR("Cannot set root node");
|
LOG_ERR("Cannot set root node");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,7 +116,7 @@ bool setup_rpl(struct net_if *iface, const char *addr_prefix)
|
||||||
|
|
||||||
ret = net_rpl_set_prefix(iface, dag, &rpl.prefix, rpl.prefix_len);
|
ret = net_rpl_set_prefix(iface, dag, &rpl.prefix, rpl.prefix_len);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
NET_ERR("Cannot set prefix %s/%d", log_strdup(prefix),
|
LOG_ERR("Cannot set prefix %s/%d", log_strdup(prefix),
|
||||||
rpl.prefix_len);
|
rpl.prefix_len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -127,11 +127,11 @@ bool setup_rpl(struct net_if *iface, const char *addr_prefix)
|
||||||
if (net_addr_ntop(AF_INET6, &rpl.prefix, out,
|
if (net_addr_ntop(AF_INET6, &rpl.prefix, out,
|
||||||
NET_IPV6_ADDR_LEN)) {
|
NET_IPV6_ADDR_LEN)) {
|
||||||
if (rpl.dag_has_version) {
|
if (rpl.dag_has_version) {
|
||||||
NET_DBG("New RPL dag %s/%d version %u created",
|
LOG_DBG("New RPL dag %s/%d version %u created",
|
||||||
log_strdup(out), rpl.prefix_len,
|
log_strdup(out), rpl.prefix_len,
|
||||||
rpl.dag_init_version);
|
rpl.dag_init_version);
|
||||||
} else {
|
} else {
|
||||||
NET_DBG("New RPL dag %s/%d created",
|
LOG_DBG("New RPL dag %s/%d created",
|
||||||
log_strdup(out),
|
log_strdup(out),
|
||||||
rpl.prefix_len);
|
rpl.prefix_len);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ static int well_known_core_get(struct coap_resource *resource,
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
NET_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(context, K_FOREVER);
|
pkt = net_pkt_get_tx(context, K_FOREVER);
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
|
|
@ -182,7 +182,7 @@ static void toggle_led(void)
|
||||||
static int led_post(struct coap_resource *resource,
|
static int led_post(struct coap_resource *resource,
|
||||||
struct coap_packet *request)
|
struct coap_packet *request)
|
||||||
{
|
{
|
||||||
NET_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
toggle_led();
|
toggle_led();
|
||||||
|
|
||||||
|
|
@ -419,13 +419,13 @@ static void udp_receive(struct net_context *context,
|
||||||
|
|
||||||
r = coap_packet_parse(&request, pkt, options, opt_num);
|
r = coap_packet_parse(&request, pkt, options, opt_num);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Invalid data received (%d)\n", r);
|
LOG_ERR("Invalid data received (%d)\n", r);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = coap_handle_request(&request, resources, options, opt_num);
|
r = coap_handle_request(&request, resources, options, opt_num);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("No handler for such request (%d)\n", r);
|
LOG_ERR("No handler for such request (%d)\n", r);
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
@ -443,13 +443,13 @@ static bool join_coap_multicast_group(void)
|
||||||
|
|
||||||
iface = net_if_get_default();
|
iface = net_if_get_default();
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
NET_ERR("Could not get te default interface\n");
|
LOG_ERR("Could not get te default interface\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcast = net_if_ipv6_maddr_add(iface, &mcast_addr.sin6_addr);
|
mcast = net_if_ipv6_maddr_add(iface, &mcast_addr.sin6_addr);
|
||||||
if (!mcast) {
|
if (!mcast) {
|
||||||
NET_ERR("Could not add multicast address to interface\n");
|
LOG_ERR("Could not add multicast address to interface\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -468,32 +468,32 @@ static void init_app(void)
|
||||||
if (led0) {
|
if (led0) {
|
||||||
gpio_pin_configure(led0, LED_PIN, GPIO_DIR_OUT);
|
gpio_pin_configure(led0, LED_PIN, GPIO_DIR_OUT);
|
||||||
} else {
|
} else {
|
||||||
NET_WARN("Failed to bind '%s'"
|
LOG_WRN("Failed to bind '%s'"
|
||||||
"fake_led will provide dummpy replies",
|
"fake_led will provide dummpy replies",
|
||||||
LED_GPIO_NAME);
|
LED_GPIO_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!join_coap_multicast_group()) {
|
if (!join_coap_multicast_group()) {
|
||||||
NET_ERR("Could not join CoAP multicast group");
|
LOG_ERR("Could not join CoAP multicast group");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_get(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, &context);
|
r = net_context_get(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, &context);
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not get an UDP context");
|
LOG_ERR("Could not get an UDP context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_bind(context, (struct sockaddr *) &any_addr,
|
r = net_context_bind(context, (struct sockaddr *) &any_addr,
|
||||||
sizeof(any_addr));
|
sizeof(any_addr));
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not bind the context");
|
LOG_ERR("Could not bind the context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_context_recv(context, udp_receive, 0, NULL);
|
r = net_context_recv(context, udp_receive, 0, NULL);
|
||||||
if (r) {
|
if (r) {
|
||||||
NET_ERR("Could not receive in the context");
|
LOG_ERR("Could not receive in the context");
|
||||||
}
|
}
|
||||||
|
|
||||||
k_delayed_work_init(&retransmit_work, retransmit_request);
|
k_delayed_work_init(&retransmit_work, retransmit_request);
|
||||||
|
|
@ -501,7 +501,7 @@ static void init_app(void)
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
NET_DBG("Start Demo");
|
LOG_DBG("Start Demo");
|
||||||
|
|
||||||
init_app();
|
init_app();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ static struct coap_block_context blk_ctx;
|
||||||
static void wait(void)
|
static void wait(void)
|
||||||
{
|
{
|
||||||
if (poll(fds, nfds, K_FOREVER) < 0) {
|
if (poll(fds, nfds, K_FOREVER) < 0) {
|
||||||
NET_ERR("Error in poll:%d", errno);
|
LOG_ERR("Error in poll:%d", errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,13 +67,13 @@ static int start_coap_client(void)
|
||||||
|
|
||||||
sock = socket(addr6.sin6_family, SOCK_DGRAM, IPPROTO_UDP);
|
sock = socket(addr6.sin6_family, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
NET_ERR("Failed to create UDP socket %d", errno);
|
LOG_ERR("Failed to create UDP socket %d", errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = connect(sock, (struct sockaddr *)&addr6, sizeof(addr6));
|
ret = connect(sock, (struct sockaddr *)&addr6, sizeof(addr6));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot connect to UDP remote : %d", errno);
|
LOG_ERR("Cannot connect to UDP remote : %d", errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,7 +116,7 @@ static int process_simple_coap_reply(void)
|
||||||
|
|
||||||
ret = coap_packet_parse(&reply, data, rcvd, NULL, 0);
|
ret = coap_packet_parse(&reply, data, rcvd, NULL, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Invalid data received");
|
LOG_ERR("Invalid data received");
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
@ -142,7 +142,7 @@ static int send_simple_coap_request(u8_t method)
|
||||||
1, COAP_TYPE_CON, 8, coap_next_token(),
|
1, COAP_TYPE_CON, 8, coap_next_token(),
|
||||||
method, coap_next_id());
|
method, coap_next_id());
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to init CoAP message");
|
LOG_ERR("Failed to init CoAP message");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ static int send_simple_coap_request(u8_t method)
|
||||||
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
||||||
*p, strlen(*p));
|
*p, strlen(*p));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Unable add option to request");
|
LOG_ERR("Unable add option to request");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -164,14 +164,14 @@ static int send_simple_coap_request(u8_t method)
|
||||||
case COAP_METHOD_POST:
|
case COAP_METHOD_POST:
|
||||||
r = coap_packet_append_payload_marker(&request);
|
r = coap_packet_append_payload_marker(&request);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Unable to append payload marker");
|
LOG_ERR("Unable to append payload marker");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = coap_packet_append_payload(&request, (u8_t *)payload,
|
r = coap_packet_append_payload(&request, (u8_t *)payload,
|
||||||
sizeof(payload) - 1);
|
sizeof(payload) - 1);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Not able to append payload");
|
LOG_ERR("Not able to append payload");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -284,7 +284,7 @@ static int process_large_coap_reply(void)
|
||||||
|
|
||||||
ret = coap_packet_parse(&reply, data, rcvd, NULL, 0);
|
ret = coap_packet_parse(&reply, data, rcvd, NULL, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Invalid data received");
|
LOG_ERR("Invalid data received");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -328,7 +328,7 @@ static int send_large_coap_request(void)
|
||||||
1, COAP_TYPE_CON, 8, coap_next_token(),
|
1, COAP_TYPE_CON, 8, coap_next_token(),
|
||||||
COAP_METHOD_GET, coap_next_id());
|
COAP_METHOD_GET, coap_next_id());
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to init CoAP message");
|
LOG_ERR("Failed to init CoAP message");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -336,14 +336,14 @@ static int send_large_coap_request(void)
|
||||||
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
||||||
*p, strlen(*p));
|
*p, strlen(*p));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Unable add option to request");
|
LOG_ERR("Unable add option to request");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r = coap_append_block2_option(&request, &blk_ctx);
|
r = coap_append_block2_option(&request, &blk_ctx);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Unable to add block2 option.");
|
LOG_ERR("Unable to add block2 option.");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -399,7 +399,7 @@ static int send_obs_reply_ack(u16_t id, u8_t *token, u8_t tkl)
|
||||||
r = coap_packet_init(&request, data, MAX_COAP_MSG_LEN,
|
r = coap_packet_init(&request, data, MAX_COAP_MSG_LEN,
|
||||||
1, COAP_TYPE_ACK, tkl, token, 0, id);
|
1, COAP_TYPE_ACK, tkl, token, 0, id);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to init CoAP message");
|
LOG_ERR("Failed to init CoAP message");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -450,7 +450,7 @@ static int process_obs_coap_reply(void)
|
||||||
|
|
||||||
ret = coap_packet_parse(&reply, data, rcvd, NULL, 0);
|
ret = coap_packet_parse(&reply, data, rcvd, NULL, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Invalid data received");
|
LOG_ERR("Invalid data received");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -485,13 +485,13 @@ static int send_obs_coap_request(void)
|
||||||
1, COAP_TYPE_CON, 8, coap_next_token(),
|
1, COAP_TYPE_CON, 8, coap_next_token(),
|
||||||
COAP_METHOD_GET, coap_next_id());
|
COAP_METHOD_GET, coap_next_id());
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to init CoAP message");
|
LOG_ERR("Failed to init CoAP message");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = coap_append_option_int(&request, COAP_OPTION_OBSERVE, 0);
|
r = coap_append_option_int(&request, COAP_OPTION_OBSERVE, 0);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to append Observe option");
|
LOG_ERR("Failed to append Observe option");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -499,7 +499,7 @@ static int send_obs_coap_request(void)
|
||||||
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
||||||
*p, strlen(*p));
|
*p, strlen(*p));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Unable add option to request");
|
LOG_ERR("Unable add option to request");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -530,13 +530,13 @@ static int send_obs_reset_coap_request(void)
|
||||||
1, COAP_TYPE_RESET, 8, coap_next_token(),
|
1, COAP_TYPE_RESET, 8, coap_next_token(),
|
||||||
0, coap_next_id());
|
0, coap_next_id());
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to init CoAP message");
|
LOG_ERR("Failed to init CoAP message");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = coap_append_option_int(&request, COAP_OPTION_OBSERVE, 0);
|
r = coap_append_option_int(&request, COAP_OPTION_OBSERVE, 0);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to append Observe option");
|
LOG_ERR("Failed to append Observe option");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -544,7 +544,7 @@ static int send_obs_reset_coap_request(void)
|
||||||
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
r = coap_packet_append_option(&request, COAP_OPTION_URI_PATH,
|
||||||
*p, strlen(*p));
|
*p, strlen(*p));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Unable add option to request");
|
LOG_ERR("Unable add option to request");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -601,7 +601,7 @@ void main(void)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
NET_DBG("Start CoAP-client sample");
|
LOG_DBG("Start CoAP-client sample");
|
||||||
r = start_coap_client();
|
r = start_coap_client();
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
goto quit;
|
goto quit;
|
||||||
|
|
@ -628,12 +628,12 @@ void main(void)
|
||||||
/* Close the socket */
|
/* Close the socket */
|
||||||
close(sock);
|
close(sock);
|
||||||
|
|
||||||
NET_DBG("Done");
|
LOG_DBG("Done");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
quit:
|
quit:
|
||||||
close(sock);
|
close(sock);
|
||||||
|
|
||||||
NET_ERR("quit");
|
LOG_ERR("quit");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ static bool join_coap_multicast_group(void)
|
||||||
|
|
||||||
iface = net_if_get_default();
|
iface = net_if_get_default();
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
NET_ERR("Could not get te default interface\n");
|
LOG_ERR("Could not get te default interface\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,14 +83,14 @@ static bool join_coap_multicast_group(void)
|
||||||
if (net_addr_pton(AF_INET6,
|
if (net_addr_pton(AF_INET6,
|
||||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR,
|
CONFIG_NET_CONFIG_MY_IPV6_ADDR,
|
||||||
&my_addr) < 0) {
|
&my_addr) < 0) {
|
||||||
NET_ERR("Invalid IPv6 address %s",
|
LOG_ERR("Invalid IPv6 address %s",
|
||||||
CONFIG_NET_CONFIG_MY_IPV6_ADDR);
|
CONFIG_NET_CONFIG_MY_IPV6_ADDR);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ifaddr = net_if_ipv6_addr_add(iface, &my_addr, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv6_addr_add(iface, &my_addr, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Could not add unicast address to interface");
|
LOG_ERR("Could not add unicast address to interface");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ static bool join_coap_multicast_group(void)
|
||||||
|
|
||||||
mcast = net_if_ipv6_maddr_add(iface, &mcast_addr.sin6_addr);
|
mcast = net_if_ipv6_maddr_add(iface, &mcast_addr.sin6_addr);
|
||||||
if (!mcast) {
|
if (!mcast) {
|
||||||
NET_ERR("Could not add multicast address to interface\n");
|
LOG_ERR("Could not add multicast address to interface\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,13 +118,13 @@ static int start_coap_server(void)
|
||||||
|
|
||||||
sock = socket(addr6.sin6_family, SOCK_DGRAM, IPPROTO_UDP);
|
sock = socket(addr6.sin6_family, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
NET_ERR("Failed to create UDP socket %d", errno);
|
LOG_ERR("Failed to create UDP socket %d", errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = bind(sock, (struct sockaddr *)&addr6, sizeof(addr6));
|
r = bind(sock, (struct sockaddr *)&addr6, sizeof(addr6));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to bind UDP socket %d", errno);
|
LOG_ERR("Failed to bind UDP socket %d", errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,13 +144,13 @@ static int start_coap_server(void)
|
||||||
|
|
||||||
sock = socket(addr.sin_family, SOCK_DGRAM, IPPROTO_UDP);
|
sock = socket(addr.sin_family, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
NET_ERR("Failed to create UDP socket %d", errno);
|
LOG_ERR("Failed to create UDP socket %d", errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
|
r = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to bind UDP socket %d", errno);
|
LOG_ERR("Failed to bind UDP socket %d", errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,7 +168,7 @@ static int send_coap_reply(struct coap_packet *cpkt,
|
||||||
|
|
||||||
r = sendto(sock, cpkt->data, cpkt->offset, 0, addr, addr_len);
|
r = sendto(sock, cpkt->data, cpkt->offset, 0, addr, addr_len);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Failed to send %d", errno);
|
LOG_ERR("Failed to send %d", errno);
|
||||||
r = -errno;
|
r = -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -221,9 +221,9 @@ static int piggyback_get(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
NET_INFO("type: %u code %u id %u", type, code, id);
|
LOG_INF("type: %u code %u id %u", type, code, id);
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
|
|
||||||
if (type == COAP_TYPE_CON) {
|
if (type == COAP_TYPE_CON) {
|
||||||
type = COAP_TYPE_ACK;
|
type = COAP_TYPE_ACK;
|
||||||
|
|
@ -294,9 +294,9 @@ static int test_del(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
NET_INFO("type: %u code %u id %u", type, code, id);
|
LOG_INF("type: %u code %u id %u", type, code, id);
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
|
|
||||||
if (type == COAP_TYPE_CON) {
|
if (type == COAP_TYPE_CON) {
|
||||||
type = COAP_TYPE_ACK;
|
type = COAP_TYPE_ACK;
|
||||||
|
|
@ -344,9 +344,9 @@ static int test_put(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
NET_INFO("type: %u code %u id %u", type, code, id);
|
LOG_INF("type: %u code %u id %u", type, code, id);
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
|
|
||||||
payload = coap_packet_get_payload(request, &payload_len);
|
payload = coap_packet_get_payload(request, &payload_len);
|
||||||
if (payload) {
|
if (payload) {
|
||||||
|
|
@ -404,9 +404,9 @@ static int test_post(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
NET_INFO("type: %u code %u id %u", type, code, id);
|
LOG_INF("type: %u code %u id %u", type, code, id);
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
|
|
||||||
payload = coap_packet_get_payload(request, &payload_len);
|
payload = coap_packet_get_payload(request, &payload_len);
|
||||||
if (payload) {
|
if (payload) {
|
||||||
|
|
@ -473,27 +473,27 @@ static int query_get(struct coap_resource *resource,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
NET_INFO("type: %u code %u id %u", type, code, id);
|
LOG_INF("type: %u code %u id %u", type, code, id);
|
||||||
NET_INFO("num queries: %d", r);
|
LOG_INF("num queries: %d", r);
|
||||||
|
|
||||||
for (i = 0; i < r; i++) {
|
for (i = 0; i < r; i++) {
|
||||||
char str[16];
|
char str[16];
|
||||||
|
|
||||||
if (options[i].len + 1 > sizeof(str)) {
|
if (options[i].len + 1 > sizeof(str)) {
|
||||||
NET_INFO("Unexpected length of query: "
|
LOG_INF("Unexpected length of query: "
|
||||||
"%d (expected %zu)",
|
"%d (expected %zu)",
|
||||||
options[i].len, sizeof(str));
|
options[i].len, sizeof(str));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(str, options[i].value, options[i].len);
|
memcpy(str, options[i].value, options[i].len);
|
||||||
str[options[i].len] = '\0';
|
str[options[i].len] = '\0';
|
||||||
|
|
||||||
NET_INFO("query[%d]: %s", i + 1, str);
|
LOG_INF("query[%d]: %s", i + 1, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
|
|
||||||
data = (u8_t *)k_malloc(MAX_COAP_MSG_LEN);
|
data = (u8_t *)k_malloc(MAX_COAP_MSG_LEN);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
|
@ -562,9 +562,9 @@ static int location_query_post(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
NET_INFO("type: %u code %u id %u", type, code, id);
|
LOG_INF("type: %u code %u id %u", type, code, id);
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
|
|
||||||
if (type == COAP_TYPE_CON) {
|
if (type == COAP_TYPE_CON) {
|
||||||
type = COAP_TYPE_ACK;
|
type = COAP_TYPE_ACK;
|
||||||
|
|
@ -620,9 +620,9 @@ static int separate_get(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
NET_INFO("type: %u code %u id %u", type, code, id);
|
LOG_INF("type: %u code %u id %u", type, code, id);
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
|
|
||||||
if (type == COAP_TYPE_ACK) {
|
if (type == COAP_TYPE_ACK) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -723,9 +723,9 @@ static int large_get(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
NET_INFO("type: %u code %u id %u", type, code, id);
|
LOG_INF("type: %u code %u id %u", type, code, id);
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
|
|
||||||
data = (u8_t *)k_malloc(MAX_COAP_MSG_LEN);
|
data = (u8_t *)k_malloc(MAX_COAP_MSG_LEN);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
|
@ -824,30 +824,30 @@ static int large_update_put(struct coap_resource *resource,
|
||||||
|
|
||||||
r = coap_update_from_block(request, &ctx);
|
r = coap_update_from_block(request, &ctx);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Invalid block size option from request");
|
LOG_ERR("Invalid block size option from request");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
payload = coap_packet_get_payload(request, &len);
|
payload = coap_packet_get_payload(request, &len);
|
||||||
if (!last_block && payload == NULL) {
|
if (!last_block && payload == NULL) {
|
||||||
NET_ERR("Packet without payload");
|
LOG_ERR("Packet without payload");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("**************");
|
LOG_INF("**************");
|
||||||
NET_INFO("[ctx] current %zu block_size %u total_size %zu",
|
LOG_INF("[ctx] current %zu block_size %u total_size %zu",
|
||||||
ctx.current, coap_block_size_to_bytes(ctx.block_size),
|
ctx.current, coap_block_size_to_bytes(ctx.block_size),
|
||||||
ctx.total_size);
|
ctx.total_size);
|
||||||
NET_INFO("**************");
|
LOG_INF("**************");
|
||||||
|
|
||||||
code = coap_header_get_code(request);
|
code = coap_header_get_code(request);
|
||||||
type = coap_header_get_type(request);
|
type = coap_header_get_type(request);
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
NET_INFO("type: %u code %u id %u", type, code, id);
|
LOG_INF("type: %u code %u id %u", type, code, id);
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
|
|
||||||
/* Do something with the payload */
|
/* Do something with the payload */
|
||||||
|
|
||||||
|
|
@ -870,7 +870,7 @@ static int large_update_put(struct coap_resource *resource,
|
||||||
|
|
||||||
r = coap_append_block1_option(&response, &ctx);
|
r = coap_append_block1_option(&response, &ctx);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Could not add Block1 option to response");
|
LOG_ERR("Could not add Block1 option to response");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -913,13 +913,13 @@ static int large_create_post(struct coap_resource *resource,
|
||||||
|
|
||||||
r = coap_update_from_block(request, &ctx);
|
r = coap_update_from_block(request, &ctx);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Invalid block size option from request");
|
LOG_ERR("Invalid block size option from request");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
payload = coap_packet_get_payload(request, &len);
|
payload = coap_packet_get_payload(request, &len);
|
||||||
if (!last_block && payload) {
|
if (!last_block && payload) {
|
||||||
NET_ERR("Packet without payload");
|
LOG_ERR("Packet without payload");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -928,9 +928,9 @@ static int large_create_post(struct coap_resource *resource,
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
NET_INFO("type: %u code %u id %u", type, code, id);
|
LOG_INF("type: %u code %u id %u", type, code, id);
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
|
|
||||||
if (!last_block) {
|
if (!last_block) {
|
||||||
code = COAP_RESPONSE_CODE_CONTINUE;
|
code = COAP_RESPONSE_CODE_CONTINUE;
|
||||||
|
|
@ -951,7 +951,7 @@ static int large_create_post(struct coap_resource *resource,
|
||||||
|
|
||||||
r = coap_append_block1_option(&response, &ctx);
|
r = coap_append_block1_option(&response, &ctx);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Could not add Block1 option to response");
|
LOG_ERR("Could not add Block1 option to response");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1148,9 +1148,9 @@ done:
|
||||||
id = coap_header_get_id(request);
|
id = coap_header_get_id(request);
|
||||||
tkl = coap_header_get_token(request, token);
|
tkl = coap_header_get_token(request, token);
|
||||||
|
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
NET_INFO("type: %u code %u id %u", type, code, id);
|
LOG_INF("type: %u code %u id %u", type, code, id);
|
||||||
NET_INFO("*******");
|
LOG_INF("*******");
|
||||||
|
|
||||||
return send_notification_packet(addr, addr_len,
|
return send_notification_packet(addr, addr_len,
|
||||||
observe ? resource->age : 0,
|
observe ? resource->age : 0,
|
||||||
|
|
@ -1326,7 +1326,7 @@ static void process_coap_request(u8_t *data, u16_t data_len,
|
||||||
|
|
||||||
r = coap_packet_parse(&request, data, data_len, options, opt_num);
|
r = coap_packet_parse(&request, data, data_len, options, opt_num);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_ERR("Invalid data received (%d)\n", r);
|
LOG_ERR("Invalid data received (%d)\n", r);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1354,13 +1354,13 @@ not_found:
|
||||||
o = coap_find_observer_by_addr(observers, NUM_OBSERVERS,
|
o = coap_find_observer_by_addr(observers, NUM_OBSERVERS,
|
||||||
client_addr);
|
client_addr);
|
||||||
if (!o) {
|
if (!o) {
|
||||||
NET_ERR("Observer not found\n");
|
LOG_ERR("Observer not found\n");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = find_resouce_by_observer(resources, o);
|
r = find_resouce_by_observer(resources, o);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
NET_ERR("Observer found but Resource not found\n");
|
LOG_ERR("Observer found but Resource not found\n");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1373,7 +1373,7 @@ end:
|
||||||
r = coap_handle_request(&request, resources, options, opt_num,
|
r = coap_handle_request(&request, resources, options, opt_num,
|
||||||
client_addr, client_addr_len);
|
client_addr, client_addr_len);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
NET_WARN("No handler for such request (%d)\n", r);
|
LOG_WRN("No handler for such request (%d)\n", r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1389,7 +1389,7 @@ static int process_client_request(void)
|
||||||
received = recvfrom(sock, request, sizeof(request), 0,
|
received = recvfrom(sock, request, sizeof(request), 0,
|
||||||
&client_addr, &client_addr_len);
|
&client_addr, &client_addr_len);
|
||||||
if (received < 0) {
|
if (received < 0) {
|
||||||
NET_ERR("Connection error %d", errno);
|
LOG_ERR("Connection error %d", errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1404,7 +1404,7 @@ void main(void)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
NET_DBG("Start CoAP-server sample");
|
LOG_DBG("Start CoAP-server sample");
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV6)
|
#if defined(CONFIG_NET_IPV6)
|
||||||
bool res;
|
bool res;
|
||||||
|
|
@ -1430,9 +1430,9 @@ void main(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Done");
|
LOG_DBG("Done");
|
||||||
return;
|
return;
|
||||||
|
|
||||||
quit:
|
quit:
|
||||||
NET_ERR("Quit");
|
LOG_ERR("Quit");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,13 +111,13 @@ static void wait(void)
|
||||||
* we'll check them all.
|
* we'll check them all.
|
||||||
*/
|
*/
|
||||||
if (poll(fds, nfds, K_FOREVER) < 0) {
|
if (poll(fds, nfds, K_FOREVER) < 0) {
|
||||||
NET_ERR("Error in poll:%d", errno);
|
LOG_ERR("Error in poll:%d", errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_app(void)
|
static void init_app(void)
|
||||||
{
|
{
|
||||||
NET_INFO(APP_BANNER);
|
LOG_INF(APP_BANNER);
|
||||||
|
|
||||||
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
|
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
|
||||||
int err = tls_credential_add(CA_CERTIFICATE_TAG,
|
int err = tls_credential_add(CA_CERTIFICATE_TAG,
|
||||||
|
|
@ -125,7 +125,7 @@ static void init_app(void)
|
||||||
ca_certificate,
|
ca_certificate,
|
||||||
sizeof(ca_certificate));
|
sizeof(ca_certificate));
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
NET_ERR("Failed to register public certificate: %d", err);
|
LOG_ERR("Failed to register public certificate: %d", err);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -173,7 +173,7 @@ void main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
quit:
|
quit:
|
||||||
NET_INFO("Stopping...");
|
LOG_INF("Stopping...");
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||||
stop_udp();
|
stop_udp();
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,10 @@ static int send_tcp_data(struct data *data)
|
||||||
ret = sendall(data->tcp.sock, lorem_ipsum, data->tcp.expecting);
|
ret = sendall(data->tcp.sock, lorem_ipsum, data->tcp.expecting);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("%s TCP: Failed to send data, errno %d", data->proto,
|
LOG_ERR("%s TCP: Failed to send data, errno %d", data->proto,
|
||||||
errno);
|
errno);
|
||||||
} else {
|
} else {
|
||||||
NET_DBG("%s TCP: Sent %d bytes", data->proto,
|
LOG_DBG("%s TCP: Sent %d bytes", data->proto,
|
||||||
data->tcp.expecting);
|
data->tcp.expecting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,12 +63,12 @@ static int send_tcp_data(struct data *data)
|
||||||
static int compare_tcp_data(struct data *data, const char *buf, u32_t received)
|
static int compare_tcp_data(struct data *data, const char *buf, u32_t received)
|
||||||
{
|
{
|
||||||
if (data->tcp.received + received > data->tcp.expecting) {
|
if (data->tcp.received + received > data->tcp.expecting) {
|
||||||
NET_ERR("Too much data received: TCP %s", data->proto);
|
LOG_ERR("Too much data received: TCP %s", data->proto);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(buf, lorem_ipsum + data->tcp.received, received) != 0) {
|
if (memcmp(buf, lorem_ipsum + data->tcp.received, received) != 0) {
|
||||||
NET_ERR("Invalid data received: TCP %s", data->proto);
|
LOG_ERR("Invalid data received: TCP %s", data->proto);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,7 +86,7 @@ static int start_tcp_proto(struct data *data, struct sockaddr *addr,
|
||||||
data->tcp.sock = socket(addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
|
data->tcp.sock = socket(addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
|
||||||
#endif
|
#endif
|
||||||
if (data->tcp.sock < 0) {
|
if (data->tcp.sock < 0) {
|
||||||
NET_ERR("Failed to create TCP socket (%s): %d", data->proto,
|
LOG_ERR("Failed to create TCP socket (%s): %d", data->proto,
|
||||||
errno);
|
errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +99,7 @@ static int start_tcp_proto(struct data *data, struct sockaddr *addr,
|
||||||
ret = setsockopt(data->tcp.sock, SOL_TLS, TLS_SEC_TAG_LIST,
|
ret = setsockopt(data->tcp.sock, SOL_TLS, TLS_SEC_TAG_LIST,
|
||||||
sec_tag_list, sizeof(sec_tag_list));
|
sec_tag_list, sizeof(sec_tag_list));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Failed to set TLS_SEC_TAG_LIST option (%s): %d",
|
LOG_ERR("Failed to set TLS_SEC_TAG_LIST option (%s): %d",
|
||||||
data->proto, errno);
|
data->proto, errno);
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +107,7 @@ static int start_tcp_proto(struct data *data, struct sockaddr *addr,
|
||||||
ret = setsockopt(data->tcp.sock, SOL_TLS, TLS_HOSTNAME,
|
ret = setsockopt(data->tcp.sock, SOL_TLS, TLS_HOSTNAME,
|
||||||
TLS_PEER_HOSTNAME, sizeof(TLS_PEER_HOSTNAME));
|
TLS_PEER_HOSTNAME, sizeof(TLS_PEER_HOSTNAME));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Failed to set TLS_HOSTNAME option (%s): %d",
|
LOG_ERR("Failed to set TLS_HOSTNAME option (%s): %d",
|
||||||
data->proto, errno);
|
data->proto, errno);
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -115,7 +115,7 @@ static int start_tcp_proto(struct data *data, struct sockaddr *addr,
|
||||||
|
|
||||||
ret = connect(data->tcp.sock, addr, addrlen);
|
ret = connect(data->tcp.sock, addr, addrlen);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot connect to TCP remote (%s): %d", data->proto,
|
LOG_ERR("Cannot connect to TCP remote (%s): %d", data->proto,
|
||||||
errno);
|
errno);
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -156,13 +156,13 @@ static int process_tcp_proto(struct data *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Response complete */
|
/* Response complete */
|
||||||
NET_DBG("%s TCP: Received and compared %d bytes, all ok",
|
LOG_DBG("%s TCP: Received and compared %d bytes, all ok",
|
||||||
data->proto, data->tcp.received);
|
data->proto, data->tcp.received);
|
||||||
|
|
||||||
|
|
||||||
if (++data->tcp.counter % 1000 == 0) {
|
if (++data->tcp.counter % 1000 == 0) {
|
||||||
NET_INFO("%s TCP: Exchanged %u packets", data->proto,
|
LOG_INF("%s TCP: Exchanged %u packets", data->proto,
|
||||||
data->tcp.counter);
|
data->tcp.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = send_tcp_data(data);
|
ret = send_tcp_data(data);
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ static int send_udp_data(struct data *data)
|
||||||
|
|
||||||
ret = send(data->udp.sock, lorem_ipsum, data->udp.expecting, 0);
|
ret = send(data->udp.sock, lorem_ipsum, data->udp.expecting, 0);
|
||||||
|
|
||||||
NET_DBG("%s UDP: Sent %d bytes", data->proto, data->udp.expecting);
|
LOG_DBG("%s UDP: Sent %d bytes", data->proto, data->udp.expecting);
|
||||||
|
|
||||||
k_delayed_work_submit(&data->udp.recv, UDP_WAIT);
|
k_delayed_work_submit(&data->udp.recv, UDP_WAIT);
|
||||||
|
|
||||||
|
|
@ -46,12 +46,12 @@ static int send_udp_data(struct data *data)
|
||||||
static int compare_udp_data(struct data *data, const char *buf, u32_t received)
|
static int compare_udp_data(struct data *data, const char *buf, u32_t received)
|
||||||
{
|
{
|
||||||
if (received != data->udp.expecting) {
|
if (received != data->udp.expecting) {
|
||||||
NET_ERR("Invalid amount of data received: UDP %s", data->proto);
|
LOG_ERR("Invalid amount of data received: UDP %s", data->proto);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(buf, lorem_ipsum, received) != 0) {
|
if (memcmp(buf, lorem_ipsum, received) != 0) {
|
||||||
NET_ERR("Invalid data received: UDP %s", data->proto);
|
LOG_ERR("Invalid data received: UDP %s", data->proto);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ static void wait_reply(struct k_work *work)
|
||||||
/* This means that we did not receive response in time. */
|
/* This means that we did not receive response in time. */
|
||||||
struct data *data = CONTAINER_OF(work, struct data, udp.recv);
|
struct data *data = CONTAINER_OF(work, struct data, udp.recv);
|
||||||
|
|
||||||
NET_ERR("UDP %s: Data packet not received", data->proto);
|
LOG_ERR("UDP %s: Data packet not received", data->proto);
|
||||||
|
|
||||||
/* Send a new packet at this point */
|
/* Send a new packet at this point */
|
||||||
send_udp_data(data);
|
send_udp_data(data);
|
||||||
|
|
@ -90,7 +90,7 @@ static int start_udp_proto(struct data *data, struct sockaddr *addr,
|
||||||
data->udp.sock = socket(addr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
|
data->udp.sock = socket(addr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
#endif
|
#endif
|
||||||
if (data->udp.sock < 0) {
|
if (data->udp.sock < 0) {
|
||||||
NET_ERR("Failed to create UDP socket (%s): %d", data->proto,
|
LOG_ERR("Failed to create UDP socket (%s): %d", data->proto,
|
||||||
errno);
|
errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +103,7 @@ static int start_udp_proto(struct data *data, struct sockaddr *addr,
|
||||||
ret = setsockopt(data->udp.sock, SOL_TLS, TLS_SEC_TAG_LIST,
|
ret = setsockopt(data->udp.sock, SOL_TLS, TLS_SEC_TAG_LIST,
|
||||||
sec_tag_list, sizeof(sec_tag_list));
|
sec_tag_list, sizeof(sec_tag_list));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Failed to set TLS_SEC_TAG_LIST option (%s): %d",
|
LOG_ERR("Failed to set TLS_SEC_TAG_LIST option (%s): %d",
|
||||||
data->proto, errno);
|
data->proto, errno);
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +111,7 @@ static int start_udp_proto(struct data *data, struct sockaddr *addr,
|
||||||
ret = setsockopt(data->udp.sock, SOL_TLS, TLS_HOSTNAME,
|
ret = setsockopt(data->udp.sock, SOL_TLS, TLS_HOSTNAME,
|
||||||
TLS_PEER_HOSTNAME, sizeof(TLS_PEER_HOSTNAME));
|
TLS_PEER_HOSTNAME, sizeof(TLS_PEER_HOSTNAME));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Failed to set TLS_HOSTNAME option (%s): %d",
|
LOG_ERR("Failed to set TLS_HOSTNAME option (%s): %d",
|
||||||
data->proto, errno);
|
data->proto, errno);
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +120,7 @@ static int start_udp_proto(struct data *data, struct sockaddr *addr,
|
||||||
/* Call connect so we can use send and recv. */
|
/* Call connect so we can use send and recv. */
|
||||||
ret = connect(data->udp.sock, addr, addrlen);
|
ret = connect(data->udp.sock, addr, addrlen);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot connect to UDP remote (%s): %d", data->proto,
|
LOG_ERR("Cannot connect to UDP remote (%s): %d", data->proto,
|
||||||
errno);
|
errno);
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -149,18 +149,18 @@ static int process_udp_proto(struct data *data)
|
||||||
|
|
||||||
ret = compare_udp_data(data, recv_buf, received);
|
ret = compare_udp_data(data, recv_buf, received);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_WARN("%s UDP: Received and compared %d bytes, data "
|
LOG_WRN("%s UDP: Received and compared %d bytes, data "
|
||||||
"mismatch", data->proto, received);
|
"mismatch", data->proto, received);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Correct response received */
|
/* Correct response received */
|
||||||
NET_DBG("%s UDP: Received and compared %d bytes, all ok",
|
LOG_DBG("%s UDP: Received and compared %d bytes, all ok",
|
||||||
data->proto, received);
|
data->proto, received);
|
||||||
|
|
||||||
if (++data->udp.counter % 1000 == 0) {
|
if (++data->udp.counter % 1000 == 0) {
|
||||||
NET_INFO("%s UDP: Exchanged %u packets", data->proto,
|
LOG_INF("%s UDP: Exchanged %u packets", data->proto,
|
||||||
data->udp.counter);
|
data->udp.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
k_delayed_work_cancel(&data->udp.recv);
|
k_delayed_work_cancel(&data->udp.recv);
|
||||||
|
|
|
||||||
|
|
@ -52,32 +52,32 @@ static int setup_iface(struct net_if *iface, const char *ipv6_addr,
|
||||||
|
|
||||||
ret = net_eth_vlan_enable(iface, vlan_tag);
|
ret = net_eth_vlan_enable(iface, vlan_tag);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
LOG_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
LOG_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ static void init_app(void)
|
||||||
{
|
{
|
||||||
k_sem_init(&quit_lock, 0, UINT_MAX);
|
k_sem_init(&quit_lock, 0, UINT_MAX);
|
||||||
|
|
||||||
NET_INFO(APP_BANNER);
|
LOG_INF(APP_BANNER);
|
||||||
|
|
||||||
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
|
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
|
||||||
int err = tls_credential_add(SERVER_CERTIFICATE_TAG,
|
int err = tls_credential_add(SERVER_CERTIFICATE_TAG,
|
||||||
|
|
@ -50,7 +50,7 @@ static void init_app(void)
|
||||||
server_certificate,
|
server_certificate,
|
||||||
sizeof(server_certificate));
|
sizeof(server_certificate));
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
NET_ERR("Failed to register public certificate: %d", err);
|
LOG_ERR("Failed to register public certificate: %d", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ static void init_app(void)
|
||||||
TLS_CREDENTIAL_PRIVATE_KEY,
|
TLS_CREDENTIAL_PRIVATE_KEY,
|
||||||
private_key, sizeof(private_key));
|
private_key, sizeof(private_key));
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
NET_ERR("Failed to register private key: %d", err);
|
LOG_ERR("Failed to register private key: %d", err);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -79,7 +79,7 @@ void main(void)
|
||||||
|
|
||||||
k_sem_take(&quit_lock, K_FOREVER);
|
k_sem_take(&quit_lock, K_FOREVER);
|
||||||
|
|
||||||
NET_INFO("Stopping...");
|
LOG_INF("Stopping...");
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_NET_TCP)) {
|
if (IS_ENABLED(CONFIG_NET_TCP)) {
|
||||||
stop_tcp();
|
stop_tcp();
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ static int start_tcp_proto(struct data *data, struct sockaddr *bind_addr,
|
||||||
data->tcp.sock = socket(bind_addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
|
data->tcp.sock = socket(bind_addr->sa_family, SOCK_STREAM, IPPROTO_TCP);
|
||||||
#endif
|
#endif
|
||||||
if (data->tcp.sock < 0) {
|
if (data->tcp.sock < 0) {
|
||||||
NET_ERR("Failed to create TCP socket (%s): %d", data->proto,
|
LOG_ERR("Failed to create TCP socket (%s): %d", data->proto,
|
||||||
errno);
|
errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +73,7 @@ static int start_tcp_proto(struct data *data, struct sockaddr *bind_addr,
|
||||||
ret = setsockopt(data->tcp.sock, SOL_TLS, TLS_SEC_TAG_LIST,
|
ret = setsockopt(data->tcp.sock, SOL_TLS, TLS_SEC_TAG_LIST,
|
||||||
sec_tag_list, sizeof(sec_tag_list));
|
sec_tag_list, sizeof(sec_tag_list));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Failed to set TCP secure option (%s): %d", data->proto,
|
LOG_ERR("Failed to set TCP secure option (%s): %d", data->proto,
|
||||||
errno);
|
errno);
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -81,14 +81,14 @@ static int start_tcp_proto(struct data *data, struct sockaddr *bind_addr,
|
||||||
|
|
||||||
ret = bind(data->tcp.sock, bind_addr, bind_addrlen);
|
ret = bind(data->tcp.sock, bind_addr, bind_addrlen);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Failed to bind TCP socket (%s): %d", data->proto,
|
LOG_ERR("Failed to bind TCP socket (%s): %d", data->proto,
|
||||||
errno);
|
errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = listen(data->tcp.sock, MAX_CLIENT_QUEUE);
|
ret = listen(data->tcp.sock, MAX_CLIENT_QUEUE);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Failed to listen on TCP socket (%s): %d", data->proto,
|
LOG_ERR("Failed to listen on TCP socket (%s): %d", data->proto,
|
||||||
errno);
|
errno);
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
}
|
}
|
||||||
|
|
@ -105,17 +105,17 @@ static int process_tcp(struct data *data)
|
||||||
struct sockaddr_in client_addr;
|
struct sockaddr_in client_addr;
|
||||||
socklen_t client_addr_len = sizeof(client_addr);
|
socklen_t client_addr_len = sizeof(client_addr);
|
||||||
|
|
||||||
NET_INFO("Waiting for TCP connection (%s)...", data->proto);
|
LOG_INF("Waiting for TCP connection (%s)...", data->proto);
|
||||||
|
|
||||||
client = accept(data->tcp.sock, (struct sockaddr *)&client_addr,
|
client = accept(data->tcp.sock, (struct sockaddr *)&client_addr,
|
||||||
&client_addr_len);
|
&client_addr_len);
|
||||||
if (client < 0) {
|
if (client < 0) {
|
||||||
NET_ERR("Error in accept (%s): %d - stopping server",
|
LOG_ERR("Error in accept (%s): %d - stopping server",
|
||||||
data->proto, errno);
|
data->proto, errno);
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("TCP (%s): Accepted connection", data->proto);
|
LOG_INF("TCP (%s): Accepted connection", data->proto);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
received = recv(client, data->tcp.recv_buffer + offset,
|
received = recv(client, data->tcp.recv_buffer + offset,
|
||||||
|
|
@ -123,12 +123,12 @@ static int process_tcp(struct data *data)
|
||||||
|
|
||||||
if (received == 0) {
|
if (received == 0) {
|
||||||
/* Connection closed */
|
/* Connection closed */
|
||||||
NET_INFO("TCP (%s): Connection closed", data->proto);
|
LOG_INF("TCP (%s): Connection closed", data->proto);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
} else if (received < 0) {
|
} else if (received < 0) {
|
||||||
/* Socket error */
|
/* Socket error */
|
||||||
NET_ERR("TCP (%s): Connection error %d", data->proto,
|
LOG_ERR("TCP (%s): Connection error %d", data->proto,
|
||||||
errno);
|
errno);
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
break;
|
break;
|
||||||
|
|
@ -148,18 +148,18 @@ static int process_tcp(struct data *data)
|
||||||
#endif
|
#endif
|
||||||
ret = sendall(client, data->tcp.recv_buffer, offset);
|
ret = sendall(client, data->tcp.recv_buffer, offset);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("TCP (%s): Failed to send, "
|
LOG_ERR("TCP (%s): Failed to send, "
|
||||||
"closing socket", data->proto);
|
"closing socket", data->proto);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("TCP (%s): Received and replied with %d bytes",
|
LOG_DBG("TCP (%s): Received and replied with %d bytes",
|
||||||
data->proto, offset);
|
data->proto, offset);
|
||||||
|
|
||||||
if (++data->tcp.counter % 1000 == 0) {
|
if (++data->tcp.counter % 1000 == 0) {
|
||||||
NET_INFO("%s TCP: Sent %u packets", data->proto,
|
LOG_INF("%s TCP: Sent %u packets", data->proto,
|
||||||
data->tcp.counter);
|
data->tcp.counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
|
||||||
|
|
@ -52,32 +52,32 @@ static int setup_iface(struct net_if *iface, const char *ipv6_addr,
|
||||||
|
|
||||||
ret = net_eth_vlan_enable(iface, vlan_tag);
|
ret = net_eth_vlan_enable(iface, vlan_tag);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
LOG_ERR("Cannot enable VLAN for tag %d (%d)", vlan_tag, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
if (net_addr_pton(AF_INET6, ipv6_addr, &addr6)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv6_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
if (net_addr_pton(AF_INET, ipv4_addr, &addr4)) {
|
||||||
NET_ERR("Invalid address: %s", ipv6_addr);
|
LOG_ERR("Invalid address: %s", ipv6_addr);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv4_addr_add(iface, &addr4, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
LOG_ERR("Cannot add %s to interface %p", ipv4_addr, iface);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
LOG_DBG("Interface %p VLAN tag %d setup done.", iface, vlan_tag);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,17 +21,17 @@ void main(void)
|
||||||
/* Allow some setup time before starting to send data */
|
/* Allow some setup time before starting to send data */
|
||||||
k_sleep(SLEEP_BETWEEN_PRINTS);
|
k_sleep(SLEEP_BETWEEN_PRINTS);
|
||||||
|
|
||||||
NET_DBG("Starting");
|
LOG_DBG("Starting");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
NET_ERR("Error message");
|
LOG_ERR("Error message");
|
||||||
NET_WARN("Warning message");
|
LOG_WRN("Warning message");
|
||||||
NET_INFO("Info message");
|
LOG_INF("Info message");
|
||||||
NET_DBG("Debug message");
|
LOG_DBG("Debug message");
|
||||||
|
|
||||||
k_sleep(SLEEP_BETWEEN_PRINTS);
|
k_sleep(SLEEP_BETWEEN_PRINTS);
|
||||||
|
|
||||||
} while (count--);
|
} while (count--);
|
||||||
|
|
||||||
NET_DBG("Stopping");
|
LOG_DBG("Stopping");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,27 +39,27 @@ static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("IPv4 address: %s",
|
LOG_INF("IPv4 address: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET,
|
log_strdup(net_addr_ntop(AF_INET,
|
||||||
&if_addr->address.in_addr,
|
&if_addr->address.in_addr,
|
||||||
hr_addr, NET_IPV4_ADDR_LEN)));
|
hr_addr, NET_IPV4_ADDR_LEN)));
|
||||||
NET_INFO("Lease time: %u seconds",
|
LOG_INF("Lease time: %u seconds",
|
||||||
iface->config.dhcpv4.lease_time);
|
iface->config.dhcpv4.lease_time);
|
||||||
NET_INFO("Subnet: %s",
|
LOG_INF("Subnet: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET,
|
log_strdup(net_addr_ntop(AF_INET,
|
||||||
&iface->config.ip.ipv4->netmask,
|
&iface->config.ip.ipv4->netmask,
|
||||||
hr_addr, NET_IPV4_ADDR_LEN)));
|
hr_addr, NET_IPV4_ADDR_LEN)));
|
||||||
NET_INFO("Router: %s",
|
LOG_INF("Router: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET,
|
log_strdup(net_addr_ntop(AF_INET,
|
||||||
&iface->config.ip.ipv4->gw,
|
&iface->config.ip.ipv4->gw,
|
||||||
hr_addr, NET_IPV4_ADDR_LEN)));
|
hr_addr, NET_IPV4_ADDR_LEN)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup_dhcpv4(struct net_if *iface)
|
static void setup_dhcpv4(struct net_if *iface)
|
||||||
{
|
{
|
||||||
NET_INFO("Running dhcpv4 client...");
|
LOG_INF("Running dhcpv4 client...");
|
||||||
|
|
||||||
net_mgmt_init_event_callback(&mgmt_cb, ipv4_addr_add_handler,
|
net_mgmt_init_event_callback(&mgmt_cb, ipv4_addr_add_handler,
|
||||||
NET_EVENT_IPV4_ADDR_ADD);
|
NET_EVENT_IPV4_ADDR_ADD);
|
||||||
|
|
@ -84,15 +84,15 @@ static void setup_ipv4(struct net_if *iface)
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET, CONFIG_NET_CONFIG_MY_IPV4_ADDR, &addr)) {
|
if (net_addr_pton(AF_INET, CONFIG_NET_CONFIG_MY_IPV4_ADDR, &addr)) {
|
||||||
NET_ERR("Invalid address: %s", CONFIG_NET_CONFIG_MY_IPV4_ADDR);
|
LOG_ERR("Invalid address: %s", CONFIG_NET_CONFIG_MY_IPV4_ADDR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
net_if_ipv4_addr_add(iface, &addr, NET_ADDR_MANUAL, 0);
|
net_if_ipv4_addr_add(iface, &addr, NET_ADDR_MANUAL, 0);
|
||||||
|
|
||||||
NET_INFO("IPv4 address: %s",
|
LOG_INF("IPv4 address: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET, &addr, hr_addr,
|
log_strdup(net_addr_ntop(AF_INET, &addr, hr_addr,
|
||||||
NET_IPV4_ADDR_LEN)));
|
NET_IPV4_ADDR_LEN)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
@ -113,18 +113,18 @@ static void setup_ipv6(struct net_if *iface)
|
||||||
struct in6_addr addr;
|
struct in6_addr addr;
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, CONFIG_NET_CONFIG_MY_IPV6_ADDR, &addr)) {
|
if (net_addr_pton(AF_INET6, CONFIG_NET_CONFIG_MY_IPV6_ADDR, &addr)) {
|
||||||
NET_ERR("Invalid address: %s", CONFIG_NET_CONFIG_MY_IPV6_ADDR);
|
LOG_ERR("Invalid address: %s", CONFIG_NET_CONFIG_MY_IPV6_ADDR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
net_if_ipv6_addr_add(iface, &addr, NET_ADDR_MANUAL, 0);
|
net_if_ipv6_addr_add(iface, &addr, NET_ADDR_MANUAL, 0);
|
||||||
|
|
||||||
NET_INFO("IPv6 address: %s",
|
LOG_INF("IPv6 address: %s",
|
||||||
log_strdup(net_addr_ntop(AF_INET6, &addr, hr_addr,
|
log_strdup(net_addr_ntop(AF_INET6, &addr, hr_addr,
|
||||||
NET_IPV6_ADDR_LEN)));
|
NET_IPV6_ADDR_LEN)));
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, MCAST_IP6ADDR, &addr)) {
|
if (net_addr_pton(AF_INET6, MCAST_IP6ADDR, &addr)) {
|
||||||
NET_ERR("Invalid address: %s", MCAST_IP6ADDR);
|
LOG_ERR("Invalid address: %s", MCAST_IP6ADDR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,7 +139,7 @@ void main(void)
|
||||||
{
|
{
|
||||||
struct net_if *iface = net_if_get_default();
|
struct net_if *iface = net_if_get_default();
|
||||||
|
|
||||||
NET_INFO("Starting Telnet sample");
|
LOG_INF("Starting Telnet sample");
|
||||||
|
|
||||||
setup_ipv4(iface);
|
setup_ipv4(iface);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ struct net_pkt *build_reply_pkt(const char *name,
|
||||||
struct net_buf *frag, *tmp;
|
struct net_buf *frag, *tmp;
|
||||||
int header_len = 0, recv_len, reply_len;
|
int header_len = 0, recv_len, reply_len;
|
||||||
|
|
||||||
NET_DBG("%s received %d bytes", name, net_pkt_appdatalen(pkt));
|
LOG_DBG("%s received %d bytes", name, net_pkt_appdatalen(pkt));
|
||||||
|
|
||||||
if (net_pkt_appdatalen(pkt) == 0) {
|
if (net_pkt_appdatalen(pkt) == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -137,21 +137,21 @@ static inline void stats(void)
|
||||||
if (!first_print) {
|
if (!first_print) {
|
||||||
first_print = true;
|
first_print = true;
|
||||||
} else {
|
} else {
|
||||||
NET_INFO("[%u]", ++count);
|
LOG_INF("[%u]", ++count);
|
||||||
NET_INFO("Packets received %u", tp_stats.pkts.recv);
|
LOG_INF("Packets received %u", tp_stats.pkts.recv);
|
||||||
#if defined(SEND_REPLY)
|
#if defined(SEND_REPLY)
|
||||||
NET_INFO("Packets sent %u", tp_stats.pkts.sent);
|
LOG_INF("Packets sent %u", tp_stats.pkts.sent);
|
||||||
#endif
|
#endif
|
||||||
NET_INFO("Packets dropped %u", tp_stats.pkts.dropped);
|
LOG_INF("Packets dropped %u", tp_stats.pkts.dropped);
|
||||||
NET_INFO("Bytes received %u", tp_stats.bytes.recv);
|
LOG_INF("Bytes received %u", tp_stats.bytes.recv);
|
||||||
#if defined(SEND_REPLY)
|
#if defined(SEND_REPLY)
|
||||||
NET_INFO("Bytes sent %u", tp_stats.bytes.sent);
|
LOG_INF("Bytes sent %u", tp_stats.bytes.sent);
|
||||||
#endif
|
#endif
|
||||||
NET_INFO("Packets / period %u", tp_stats.pkts.recv -
|
LOG_INF("Packets / period %u", tp_stats.pkts.recv -
|
||||||
tp_stats.pkts.prev_recv);
|
tp_stats.pkts.prev_recv);
|
||||||
NET_INFO("Packets / sec %u", (tp_stats.pkts.recv -
|
LOG_INF("Packets / sec %u", (tp_stats.pkts.recv -
|
||||||
tp_stats.pkts.prev_recv) /
|
tp_stats.pkts.prev_recv) /
|
||||||
PRINT_STATS_SECS);
|
PRINT_STATS_SECS);
|
||||||
}
|
}
|
||||||
|
|
||||||
next_print = curr + PRINT_STATISTICS_INTERVAL;
|
next_print = curr + PRINT_STATISTICS_INTERVAL;
|
||||||
|
|
@ -174,7 +174,7 @@ void pkt_sent(struct net_app_ctx *ctx,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
if (!status) {
|
if (!status) {
|
||||||
NET_DBG("Sent %d bytes", POINTER_TO_UINT(user_data_send));
|
LOG_DBG("Sent %d bytes", POINTER_TO_UINT(user_data_send));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,7 +195,7 @@ void main(void)
|
||||||
|
|
||||||
k_sem_take(&quit_lock, K_FOREVER);
|
k_sem_take(&quit_lock, K_FOREVER);
|
||||||
|
|
||||||
NET_INFO("Stopping...");
|
LOG_INF("Stopping...");
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
if (IS_ENABLED(CONFIG_NET_UDP)) {
|
||||||
stop_udp();
|
stop_udp();
|
||||||
|
|
|
||||||
|
|
@ -165,14 +165,14 @@ static int init_app(void)
|
||||||
|
|
||||||
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET));
|
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET));
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
NET_ERR("No ethernet interfaces found.");
|
LOG_ERR("No ethernet interfaces found.");
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_VLAN)
|
#if defined(CONFIG_NET_VLAN)
|
||||||
ret = net_eth_vlan_enable(iface, CONFIG_SAMPLE_VLAN_TAG);
|
ret = net_eth_vlan_enable(iface, CONFIG_SAMPLE_VLAN_TAG);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable VLAN for tag %d (%d)",
|
LOG_ERR("Cannot enable VLAN for tag %d (%d)",
|
||||||
CONFIG_SAMPLE_VLAN_TAG, ret);
|
CONFIG_SAMPLE_VLAN_TAG, ret);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -189,19 +189,19 @@ static int init_app(void)
|
||||||
*/
|
*/
|
||||||
ret = net_eth_vlan_enable(ud.second, CONFIG_SAMPLE_VLAN_TAG_2);
|
ret = net_eth_vlan_enable(ud.second, CONFIG_SAMPLE_VLAN_TAG_2);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable VLAN for tag %d (%d)",
|
LOG_ERR("Cannot enable VLAN for tag %d (%d)",
|
||||||
CONFIG_SAMPLE_VLAN_TAG_2, ret);
|
CONFIG_SAMPLE_VLAN_TAG_2, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV6)
|
#if defined(CONFIG_NET_IPV6)
|
||||||
if (net_addr_pton(AF_INET6, CONFIG_SAMPLE_IPV6_ADDR_2, &addr6)) {
|
if (net_addr_pton(AF_INET6, CONFIG_SAMPLE_IPV6_ADDR_2, &addr6)) {
|
||||||
NET_ERR("Invalid address: %s", CONFIG_SAMPLE_IPV6_ADDR_2);
|
LOG_ERR("Invalid address: %s", CONFIG_SAMPLE_IPV6_ADDR_2);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv6_addr_add(ud.second, &addr6, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv6_addr_add(ud.second, &addr6, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p",
|
LOG_ERR("Cannot add %s to interface %p",
|
||||||
CONFIG_SAMPLE_IPV6_ADDR_2, ud.second);
|
CONFIG_SAMPLE_IPV6_ADDR_2, ud.second);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
@ -211,13 +211,13 @@ static int init_app(void)
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV4)
|
#if defined(CONFIG_NET_IPV4)
|
||||||
if (net_addr_pton(AF_INET, CONFIG_SAMPLE_IPV4_ADDR_2, &addr4)) {
|
if (net_addr_pton(AF_INET, CONFIG_SAMPLE_IPV4_ADDR_2, &addr4)) {
|
||||||
NET_ERR("Invalid address: %s", CONFIG_SAMPLE_IPV4_ADDR_2);
|
LOG_ERR("Invalid address: %s", CONFIG_SAMPLE_IPV4_ADDR_2);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv4_addr_add(ud.second, &addr4, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv4_addr_add(ud.second, &addr4, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p",
|
LOG_ERR("Cannot add %s to interface %p",
|
||||||
CONFIG_SAMPLE_IPV4_ADDR_2, ud.second);
|
CONFIG_SAMPLE_IPV4_ADDR_2, ud.second);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
@ -257,8 +257,8 @@ static void stats(struct data *data)
|
||||||
goto skip_print;
|
goto skip_print;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_INFO("Traffic class statistics:");
|
LOG_INF("Traffic class statistics:");
|
||||||
NET_INFO(" Prio\tSent\tRecv\tDrop\tMiss\tTime (us)");
|
LOG_INF(" Prio\tSent\tRecv\tDrop\tMiss\tTime (us)");
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV6)
|
#if defined(CONFIG_NET_IPV6)
|
||||||
for (i = 0; i < NET_TC_COUNT; i++) {
|
for (i = 0; i < NET_TC_COUNT; i++) {
|
||||||
|
|
@ -267,13 +267,13 @@ static void stats(struct data *data)
|
||||||
data->conf->ipv6[i].stats.sent_time_count,
|
data->conf->ipv6[i].stats.sent_time_count,
|
||||||
data->conf->ipv6[i].stats.sent_time_sum);
|
data->conf->ipv6[i].stats.sent_time_sum);
|
||||||
|
|
||||||
NET_INFO("v6 %d\t%u\t%u\t%u\t%u\t%u",
|
LOG_INF("v6 %d\t%u\t%u\t%u\t%u\t%u",
|
||||||
data->conf->ipv6[i].priority,
|
data->conf->ipv6[i].priority,
|
||||||
data->conf->ipv6[i].stats.sent,
|
data->conf->ipv6[i].stats.sent,
|
||||||
data->conf->ipv6[i].stats.received,
|
data->conf->ipv6[i].stats.received,
|
||||||
data->conf->ipv6[i].stats.dropped,
|
data->conf->ipv6[i].stats.dropped,
|
||||||
data->conf->ipv6[i].stats.wrong_order,
|
data->conf->ipv6[i].stats.wrong_order,
|
||||||
round_trip_time);
|
round_trip_time);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -284,16 +284,16 @@ static void stats(struct data *data)
|
||||||
data->conf->ipv4[i].stats.sent_time_count,
|
data->conf->ipv4[i].stats.sent_time_count,
|
||||||
data->conf->ipv4[i].stats.sent_time_sum);
|
data->conf->ipv4[i].stats.sent_time_sum);
|
||||||
|
|
||||||
NET_INFO("v4 %d\t%u\t%u\t%u\t%u\t%u",
|
LOG_INF("v4 %d\t%u\t%u\t%u\t%u\t%u",
|
||||||
data->conf->ipv4[i].priority,
|
data->conf->ipv4[i].priority,
|
||||||
data->conf->ipv4[i].stats.sent,
|
data->conf->ipv4[i].stats.sent,
|
||||||
data->conf->ipv4[i].stats.received,
|
data->conf->ipv4[i].stats.received,
|
||||||
data->conf->ipv4[i].stats.dropped,
|
data->conf->ipv4[i].stats.dropped,
|
||||||
data->conf->ipv4[i].stats.wrong_order,
|
data->conf->ipv4[i].stats.wrong_order,
|
||||||
round_trip_time);
|
round_trip_time);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
NET_INFO("---");
|
LOG_INF("---");
|
||||||
|
|
||||||
skip_print:
|
skip_print:
|
||||||
new_print = curr + PRINT_STATISTICS_INTERVAL;
|
new_print = curr + PRINT_STATISTICS_INTERVAL;
|
||||||
|
|
@ -404,7 +404,7 @@ static void udp_received(struct net_app_ctx *ctx,
|
||||||
ARG_UNUSED(status);
|
ARG_UNUSED(status);
|
||||||
|
|
||||||
if (data->expecting_udp != net_pkt_appdatalen(pkt)) {
|
if (data->expecting_udp != net_pkt_appdatalen(pkt)) {
|
||||||
NET_DBG("Sent %d bytes, received %u bytes",
|
LOG_DBG("Sent %d bytes, received %u bytes",
|
||||||
data->expecting_udp, net_pkt_appdatalen(pkt));
|
data->expecting_udp, net_pkt_appdatalen(pkt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -441,7 +441,7 @@ static int connect_udp(sa_family_t family, struct net_app_ctx *ctx,
|
||||||
ret = net_app_init_udp_client(ctx, NULL, NULL, peer, PEER_PORT,
|
ret = net_app_init_udp_client(ctx, NULL, NULL, peer, PEER_PORT,
|
||||||
WAIT_TIME, user_data);
|
WAIT_TIME, user_data);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init %s UDP client (%d)", data->proto, ret);
|
LOG_ERR("Cannot init %s UDP client (%d)", data->proto, ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -451,13 +451,13 @@ static int connect_udp(sa_family_t family, struct net_app_ctx *ctx,
|
||||||
|
|
||||||
ret = net_app_set_cb(ctx, NULL, udp_received, NULL, NULL);
|
ret = net_app_set_cb(ctx, NULL, udp_received, NULL, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot set callbacks (%d)", ret);
|
LOG_ERR("Cannot set callbacks (%d)", ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = net_app_connect(ctx, CONNECT_TIME);
|
ret = net_app_connect(ctx, CONNECT_TIME);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot connect UDP (%d)", ret);
|
LOG_ERR("Cannot connect UDP (%d)", ret);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -508,13 +508,13 @@ static void setup_clients(void)
|
||||||
conf.ipv6[i].conf = &conf;
|
conf.ipv6[i].conf = &conf;
|
||||||
|
|
||||||
if (i % 2) {
|
if (i % 2) {
|
||||||
NET_DBG("TC %d connecting to %s", i,
|
LOG_DBG("TC %d connecting to %s", i,
|
||||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR);
|
CONFIG_NET_CONFIG_PEER_IPV6_ADDR);
|
||||||
ret = connect_udp(AF_INET6, &udp6[i],
|
ret = connect_udp(AF_INET6, &udp6[i],
|
||||||
CONFIG_NET_CONFIG_PEER_IPV6_ADDR,
|
CONFIG_NET_CONFIG_PEER_IPV6_ADDR,
|
||||||
&conf.ipv6[i], i);
|
&conf.ipv6[i], i);
|
||||||
} else {
|
} else {
|
||||||
NET_DBG("TC %d connecting to %s", i,
|
LOG_DBG("TC %d connecting to %s", i,
|
||||||
CONFIG_SAMPLE_PEER_IPV6_ADDR_2);
|
CONFIG_SAMPLE_PEER_IPV6_ADDR_2);
|
||||||
ret = connect_udp(AF_INET6, &udp6[i],
|
ret = connect_udp(AF_INET6, &udp6[i],
|
||||||
CONFIG_SAMPLE_PEER_IPV6_ADDR_2,
|
CONFIG_SAMPLE_PEER_IPV6_ADDR_2,
|
||||||
|
|
@ -522,7 +522,7 @@ static void setup_clients(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init IPv6 UDP client %d (%d)",
|
LOG_ERR("Cannot init IPv6 UDP client %d (%d)",
|
||||||
i + 1, ret);
|
i + 1, ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -535,13 +535,13 @@ static void setup_clients(void)
|
||||||
conf.ipv4[i].conf = &conf;
|
conf.ipv4[i].conf = &conf;
|
||||||
|
|
||||||
if (i % 2) {
|
if (i % 2) {
|
||||||
NET_DBG("TC %d connecting to %s", i,
|
LOG_DBG("TC %d connecting to %s", i,
|
||||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR);
|
CONFIG_NET_CONFIG_PEER_IPV4_ADDR);
|
||||||
ret = connect_udp(AF_INET, &udp4[i],
|
ret = connect_udp(AF_INET, &udp4[i],
|
||||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR,
|
CONFIG_NET_CONFIG_PEER_IPV4_ADDR,
|
||||||
&conf.ipv4[i], i);
|
&conf.ipv4[i], i);
|
||||||
} else {
|
} else {
|
||||||
NET_DBG("TC %d connecting to %s", i,
|
LOG_DBG("TC %d connecting to %s", i,
|
||||||
CONFIG_SAMPLE_PEER_IPV4_ADDR_2);
|
CONFIG_SAMPLE_PEER_IPV4_ADDR_2);
|
||||||
ret = connect_udp(AF_INET, &udp4[i],
|
ret = connect_udp(AF_INET, &udp4[i],
|
||||||
CONFIG_SAMPLE_PEER_IPV4_ADDR_2,
|
CONFIG_SAMPLE_PEER_IPV4_ADDR_2,
|
||||||
|
|
@ -549,7 +549,7 @@ static void setup_clients(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init IPv4 UDP client %d (%d)",
|
LOG_ERR("Cannot init IPv4 UDP client %d (%d)",
|
||||||
i + 1, ret);
|
i + 1, ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,13 +55,13 @@ static int init_app(void)
|
||||||
|
|
||||||
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET));
|
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET));
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
NET_ERR("No ethernet interfaces found.");
|
LOG_ERR("No ethernet interfaces found.");
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = net_eth_vlan_enable(iface, CONFIG_SAMPLE_VLAN_TAG);
|
ret = net_eth_vlan_enable(iface, CONFIG_SAMPLE_VLAN_TAG);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable VLAN for tag %d (%d)",
|
LOG_ERR("Cannot enable VLAN for tag %d (%d)",
|
||||||
CONFIG_SAMPLE_VLAN_TAG, ret);
|
CONFIG_SAMPLE_VLAN_TAG, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,30 +77,30 @@ static int init_app(void)
|
||||||
*/
|
*/
|
||||||
ret = net_eth_vlan_enable(ud.second, CONFIG_SAMPLE_VLAN_TAG_2);
|
ret = net_eth_vlan_enable(ud.second, CONFIG_SAMPLE_VLAN_TAG_2);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable VLAN for tag %d (%d)",
|
LOG_ERR("Cannot enable VLAN for tag %d (%d)",
|
||||||
CONFIG_SAMPLE_VLAN_TAG_2, ret);
|
CONFIG_SAMPLE_VLAN_TAG_2, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET6, CONFIG_SAMPLE_IPV6_ADDR_2, &addr6)) {
|
if (net_addr_pton(AF_INET6, CONFIG_SAMPLE_IPV6_ADDR_2, &addr6)) {
|
||||||
NET_ERR("Invalid address: %s", CONFIG_SAMPLE_IPV6_ADDR_2);
|
LOG_ERR("Invalid address: %s", CONFIG_SAMPLE_IPV6_ADDR_2);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv6_addr_add(ud.second, &addr6, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv6_addr_add(ud.second, &addr6, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p",
|
LOG_ERR("Cannot add %s to interface %p",
|
||||||
CONFIG_SAMPLE_IPV6_ADDR_2, ud.second);
|
CONFIG_SAMPLE_IPV6_ADDR_2, ud.second);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET, CONFIG_SAMPLE_IPV4_ADDR_2, &addr4)) {
|
if (net_addr_pton(AF_INET, CONFIG_SAMPLE_IPV4_ADDR_2, &addr4)) {
|
||||||
NET_ERR("Invalid address: %s", CONFIG_SAMPLE_IPV4_ADDR_2);
|
LOG_ERR("Invalid address: %s", CONFIG_SAMPLE_IPV4_ADDR_2);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ifaddr = net_if_ipv4_addr_add(ud.second, &addr4, NET_ADDR_MANUAL, 0);
|
ifaddr = net_if_ipv4_addr_add(ud.second, &addr4, NET_ADDR_MANUAL, 0);
|
||||||
if (!ifaddr) {
|
if (!ifaddr) {
|
||||||
NET_ERR("Cannot add %s to interface %p",
|
LOG_ERR("Cannot add %s to interface %p",
|
||||||
CONFIG_SAMPLE_IPV4_ADDR_2, ud.second);
|
CONFIG_SAMPLE_IPV4_ADDR_2, ud.second);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,14 +108,14 @@ static int slip_process_byte(unsigned char c)
|
||||||
{
|
{
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
#ifdef VERBOSE_DEBUG
|
#ifdef VERBOSE_DEBUG
|
||||||
NET_DBG("recv: state %u byte %x", slip_state, c);
|
LOG_DBG("recv: state %u byte %x", slip_state, c);
|
||||||
#endif
|
#endif
|
||||||
switch (slip_state) {
|
switch (slip_state) {
|
||||||
case STATE_GARBAGE:
|
case STATE_GARBAGE:
|
||||||
if (c == SLIP_END) {
|
if (c == SLIP_END) {
|
||||||
slip_state = STATE_OK;
|
slip_state = STATE_OK;
|
||||||
}
|
}
|
||||||
NET_DBG("garbage: discard byte %x", c);
|
LOG_DBG("garbage: discard byte %x", c);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case STATE_ESC:
|
case STATE_ESC:
|
||||||
|
|
@ -141,18 +141,18 @@ static int slip_process_byte(unsigned char c)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE_DEBUG
|
#ifdef VERBOSE_DEBUG
|
||||||
NET_DBG("processed: state %u byte %x", slip_state, c);
|
LOG_DBG("processed: state %u byte %x", slip_state, c);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!pkt_curr) {
|
if (!pkt_curr) {
|
||||||
pkt_curr = net_pkt_get_reserve_rx(0, K_NO_WAIT);
|
pkt_curr = net_pkt_get_reserve_rx(0, K_NO_WAIT);
|
||||||
if (!pkt_curr) {
|
if (!pkt_curr) {
|
||||||
NET_ERR("No more buffers");
|
LOG_ERR("No more buffers");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
buf = net_pkt_get_frag(pkt_curr, K_NO_WAIT);
|
buf = net_pkt_get_frag(pkt_curr, K_NO_WAIT);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
NET_ERR("No more buffers");
|
LOG_ERR("No more buffers");
|
||||||
net_pkt_unref(pkt_curr);
|
net_pkt_unref(pkt_curr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -162,7 +162,7 @@ static int slip_process_byte(unsigned char c)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!net_buf_tailroom(buf)) {
|
if (!net_buf_tailroom(buf)) {
|
||||||
NET_ERR("No more buf space: buf %p len %u", buf, buf->len);
|
LOG_ERR("No more buf space: buf %p len %u", buf, buf->len);
|
||||||
|
|
||||||
net_pkt_unref(pkt_curr);
|
net_pkt_unref(pkt_curr);
|
||||||
pkt_curr = NULL;
|
pkt_curr = NULL;
|
||||||
|
|
@ -178,11 +178,11 @@ static void interrupt_handler(struct device *dev)
|
||||||
{
|
{
|
||||||
while (uart_irq_update(dev) && uart_irq_is_pending(dev)) {
|
while (uart_irq_update(dev) && uart_irq_is_pending(dev)) {
|
||||||
#ifdef VERBOSE_DEBUG
|
#ifdef VERBOSE_DEBUG
|
||||||
NET_DBG("");
|
LOG_DBG("");
|
||||||
#endif
|
#endif
|
||||||
if (uart_irq_tx_ready(dev)) {
|
if (uart_irq_tx_ready(dev)) {
|
||||||
#ifdef VERBOSE_DEBUG
|
#ifdef VERBOSE_DEBUG
|
||||||
NET_DBG("TX ready interrupt");
|
LOG_DBG("TX ready interrupt");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
k_sem_give(&tx_sem);
|
k_sem_give(&tx_sem);
|
||||||
|
|
@ -192,7 +192,7 @@ static void interrupt_handler(struct device *dev)
|
||||||
unsigned char byte;
|
unsigned char byte;
|
||||||
|
|
||||||
#ifdef VERBOSE_DEBUG
|
#ifdef VERBOSE_DEBUG
|
||||||
NET_DBG("RX ready interrupt");
|
LOG_DBG("RX ready interrupt");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (uart_fifo_read(dev, &byte, sizeof(byte))) {
|
while (uart_fifo_read(dev, &byte, sizeof(byte))) {
|
||||||
|
|
@ -203,11 +203,11 @@ static void interrupt_handler(struct device *dev)
|
||||||
* packet
|
* packet
|
||||||
*/
|
*/
|
||||||
if (!pkt_curr) {
|
if (!pkt_curr) {
|
||||||
NET_DBG("Skip SLIP_END");
|
LOG_DBG("Skip SLIP_END");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Full packet %p", pkt_curr);
|
LOG_DBG("Full packet %p", pkt_curr);
|
||||||
|
|
||||||
k_fifo_put(&rx_queue, pkt_curr);
|
k_fifo_put(&rx_queue, pkt_curr);
|
||||||
pkt_curr = NULL;
|
pkt_curr = NULL;
|
||||||
|
|
@ -225,20 +225,20 @@ static void send_data(u8_t *cfg, u8_t *data, size_t len)
|
||||||
|
|
||||||
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
|
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
NET_DBG("No pkt available");
|
LOG_DBG("No pkt available");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = net_pkt_get_frag(pkt, K_NO_WAIT);
|
buf = net_pkt_get_frag(pkt, K_NO_WAIT);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
NET_DBG("No fragment available");
|
LOG_DBG("No fragment available");
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
net_pkt_frag_insert(pkt, buf);
|
net_pkt_frag_insert(pkt, buf);
|
||||||
|
|
||||||
NET_DBG("queue pkt %p buf %p len %u", pkt, buf, len);
|
LOG_DBG("queue pkt %p buf %p len %u", pkt, buf, len);
|
||||||
|
|
||||||
/* Add configuration id */
|
/* Add configuration id */
|
||||||
memcpy(net_buf_add(buf, 2), cfg, 2);
|
memcpy(net_buf_add(buf, 2), cfg, 2);
|
||||||
|
|
@ -258,7 +258,7 @@ static void get_ieee_addr(void)
|
||||||
u8_t cfg[2] = { '!', 'M' };
|
u8_t cfg[2] = { '!', 'M' };
|
||||||
u8_t mac[8];
|
u8_t mac[8];
|
||||||
|
|
||||||
NET_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
/* Send in BE */
|
/* Send in BE */
|
||||||
sys_memcpy_swap(mac, mac_addr, sizeof(mac));
|
sys_memcpy_swap(mac, mac_addr, sizeof(mac));
|
||||||
|
|
@ -276,7 +276,7 @@ static void process_request(struct net_buf *buf)
|
||||||
get_ieee_addr();
|
get_ieee_addr();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
NET_ERR("Not handled request %c", cmd);
|
LOG_ERR("Not handled request %c", cmd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -302,7 +302,7 @@ static void process_data(struct net_pkt *pkt)
|
||||||
seq = net_buf_pull_u8(buf);
|
seq = net_buf_pull_u8(buf);
|
||||||
num_attr = net_buf_pull_u8(buf);
|
num_attr = net_buf_pull_u8(buf);
|
||||||
|
|
||||||
NET_DBG("seq %u num_attr %u", seq, num_attr);
|
LOG_DBG("seq %u num_attr %u", seq, num_attr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There are some attributes sent over this protocol
|
* There are some attributes sent over this protocol
|
||||||
|
|
@ -319,7 +319,7 @@ static void process_data(struct net_pkt *pkt)
|
||||||
/* Transmit data through radio */
|
/* Transmit data through radio */
|
||||||
ret = radio_api->tx(ieee802154_dev, pkt, buf);
|
ret = radio_api->tx(ieee802154_dev, pkt, buf);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
NET_ERR("Error transmit data");
|
LOG_ERR("Error transmit data");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Return correct status codes */
|
/* TODO: Return correct status codes */
|
||||||
|
|
@ -331,7 +331,7 @@ static void process_data(struct net_pkt *pkt)
|
||||||
|
|
||||||
static void set_channel(u8_t chan)
|
static void set_channel(u8_t chan)
|
||||||
{
|
{
|
||||||
NET_DBG("Set channel %c", chan);
|
LOG_DBG("Set channel %c", chan);
|
||||||
|
|
||||||
radio_api->set_channel(ieee802154_dev, chan);
|
radio_api->set_channel(ieee802154_dev, chan);
|
||||||
}
|
}
|
||||||
|
|
@ -341,7 +341,7 @@ static void process_config(struct net_pkt *pkt)
|
||||||
struct net_buf *buf = net_buf_frag_last(pkt->frags);
|
struct net_buf *buf = net_buf_frag_last(pkt->frags);
|
||||||
u8_t cmd = net_buf_pull_u8(buf);
|
u8_t cmd = net_buf_pull_u8(buf);
|
||||||
|
|
||||||
NET_DBG("Process config %c", cmd);
|
LOG_DBG("Process config %c", cmd);
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case 'S':
|
case 'S':
|
||||||
|
|
@ -351,13 +351,13 @@ static void process_config(struct net_pkt *pkt)
|
||||||
set_channel(net_buf_pull_u8(buf));
|
set_channel(net_buf_pull_u8(buf));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
NET_ERR("Unhandled cmd %u", cmd);
|
LOG_ERR("Unhandled cmd %u", cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rx_thread(void)
|
static void rx_thread(void)
|
||||||
{
|
{
|
||||||
NET_INFO("RX thread started");
|
LOG_INF("RX thread started");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
|
|
@ -367,7 +367,7 @@ static void rx_thread(void)
|
||||||
pkt = k_fifo_get(&rx_queue, K_FOREVER);
|
pkt = k_fifo_get(&rx_queue, K_FOREVER);
|
||||||
buf = net_buf_frag_last(pkt->frags);
|
buf = net_buf_frag_last(pkt->frags);
|
||||||
|
|
||||||
NET_DBG("Got pkt %p buf %p", pkt, buf);
|
LOG_DBG("Got pkt %p buf %p", pkt, buf);
|
||||||
|
|
||||||
hexdump("SLIP >", buf->data, buf->len);
|
hexdump("SLIP >", buf->data, buf->len);
|
||||||
|
|
||||||
|
|
@ -381,7 +381,7 @@ static void rx_thread(void)
|
||||||
process_config(pkt);
|
process_config(pkt);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
NET_ERR("Unknown message specifier %c", specifier);
|
LOG_ERR("Unknown message specifier %c", specifier);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -429,7 +429,7 @@ static size_t slip_buffer(u8_t *sbuf, struct net_buf *buf)
|
||||||
*/
|
*/
|
||||||
static void tx_thread(void)
|
static void tx_thread(void)
|
||||||
{
|
{
|
||||||
NET_DBG("TX thread started");
|
LOG_DBG("TX thread started");
|
||||||
|
|
||||||
/* Allow to send one TX */
|
/* Allow to send one TX */
|
||||||
k_sem_give(&tx_sem);
|
k_sem_give(&tx_sem);
|
||||||
|
|
@ -445,7 +445,7 @@ static void tx_thread(void)
|
||||||
buf = net_buf_frag_last(pkt->frags);
|
buf = net_buf_frag_last(pkt->frags);
|
||||||
len = net_pkt_get_len(pkt);
|
len = net_pkt_get_len(pkt);
|
||||||
|
|
||||||
NET_DBG("Send pkt %p buf %p len %d", pkt, buf, len);
|
LOG_DBG("Send pkt %p buf %p len %d", pkt, buf, len);
|
||||||
|
|
||||||
hexdump("SLIP <", buf->data, buf->len);
|
hexdump("SLIP <", buf->data, buf->len);
|
||||||
|
|
||||||
|
|
@ -506,11 +506,11 @@ static u8_t *get_mac(struct device *dev)
|
||||||
|
|
||||||
static bool init_ieee802154(void)
|
static bool init_ieee802154(void)
|
||||||
{
|
{
|
||||||
NET_INFO("Initialize ieee802.15.4");
|
LOG_INF("Initialize ieee802.15.4");
|
||||||
|
|
||||||
ieee802154_dev = device_get_binding(CONFIG_IEEE802154_CC2520_DRV_NAME);
|
ieee802154_dev = device_get_binding(CONFIG_IEEE802154_CC2520_DRV_NAME);
|
||||||
if (!ieee802154_dev) {
|
if (!ieee802154_dev) {
|
||||||
NET_ERR("Cannot get CC250 device");
|
LOG_ERR("Cannot get CC250 device");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -541,7 +541,7 @@ static bool init_ieee802154(void)
|
||||||
&filter);
|
&filter);
|
||||||
|
|
||||||
#ifdef CONFIG_NET_CONFIG_SETTINGS
|
#ifdef CONFIG_NET_CONFIG_SETTINGS
|
||||||
NET_INFO("Set panid %x", CONFIG_NET_CONFIG_IEEE802154_PAN_ID);
|
LOG_INF("Set panid %x", CONFIG_NET_CONFIG_IEEE802154_PAN_ID);
|
||||||
|
|
||||||
filter.pan_id = CONFIG_NET_CONFIG_IEEE802154_PAN_ID;
|
filter.pan_id = CONFIG_NET_CONFIG_IEEE802154_PAN_ID;
|
||||||
|
|
||||||
|
|
@ -552,7 +552,7 @@ static bool init_ieee802154(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_NET_CONFIG_SETTINGS
|
#ifdef CONFIG_NET_CONFIG_SETTINGS
|
||||||
NET_INFO("Set channel %x", CONFIG_NET_CONFIG_IEEE802154_CHANNEL);
|
LOG_INF("Set channel %x", CONFIG_NET_CONFIG_IEEE802154_CHANNEL);
|
||||||
radio_api->set_channel(ieee802154_dev,
|
radio_api->set_channel(ieee802154_dev,
|
||||||
CONFIG_NET_CONFIG_IEEE802154_CHANNEL);
|
CONFIG_NET_CONFIG_IEEE802154_CHANNEL);
|
||||||
#endif /* CONFIG_NET_CONFIG_SETTINGS */
|
#endif /* CONFIG_NET_CONFIG_SETTINGS */
|
||||||
|
|
@ -565,7 +565,7 @@ static bool init_ieee802154(void)
|
||||||
|
|
||||||
int net_recv_data(struct net_if *iface, struct net_pkt *pkt)
|
int net_recv_data(struct net_if *iface, struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
NET_DBG("Got data, pkt %p, frags->len %d",
|
LOG_DBG("Got data, pkt %p, frags->len %d",
|
||||||
pkt, net_pkt_get_len(pkt));
|
pkt, net_pkt_get_len(pkt));
|
||||||
|
|
||||||
k_fifo_put(&tx_queue, pkt);
|
k_fifo_put(&tx_queue, pkt);
|
||||||
|
|
@ -581,11 +581,11 @@ void main(void)
|
||||||
|
|
||||||
dev = device_get_binding(CONFIG_CDC_ACM_PORT_NAME);
|
dev = device_get_binding(CONFIG_CDC_ACM_PORT_NAME);
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
NET_ERR("CDC ACM device not found");
|
LOG_ERR("CDC ACM device not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Wait for DTR");
|
LOG_DBG("Wait for DTR");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
uart_line_ctrl_get(dev, LINE_CTRL_DTR, &dtr);
|
uart_line_ctrl_get(dev, LINE_CTRL_DTR, &dtr);
|
||||||
|
|
@ -595,7 +595,7 @@ void main(void)
|
||||||
|
|
||||||
uart_dev = dev;
|
uart_dev = dev;
|
||||||
|
|
||||||
NET_DBG("DTR set, continue");
|
LOG_DBG("DTR set, continue");
|
||||||
|
|
||||||
#if CONFIG_DCD_DSR
|
#if CONFIG_DCD_DSR
|
||||||
/* They are optional, we use them to test the interrupt endpoint */
|
/* They are optional, we use them to test the interrupt endpoint */
|
||||||
|
|
@ -616,7 +616,7 @@ void main(void)
|
||||||
else
|
else
|
||||||
printk("Baudrate detected: %d\n", baudrate);
|
printk("Baudrate detected: %d\n", baudrate);
|
||||||
|
|
||||||
NET_INFO("USB serial initialized");
|
LOG_INF("USB serial initialized");
|
||||||
|
|
||||||
/* Initialize net_pkt */
|
/* Initialize net_pkt */
|
||||||
net_pkt_init();
|
net_pkt_init();
|
||||||
|
|
@ -629,7 +629,7 @@ void main(void)
|
||||||
|
|
||||||
/* Initialize ieee802154 device */
|
/* Initialize ieee802154 device */
|
||||||
if (!init_ieee802154()) {
|
if (!init_ieee802154()) {
|
||||||
NET_ERR("Unable to initialize ieee802154");
|
LOG_ERR("Unable to initialize ieee802154");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,14 +99,14 @@ static int setup_cert(struct net_app_ctx *ctx,
|
||||||
ret = mbedtls_x509_crt_parse(cert, echo_apps_cert_der,
|
ret = mbedtls_x509_crt_parse(cert, echo_apps_cert_der,
|
||||||
sizeof(echo_apps_cert_der));
|
sizeof(echo_apps_cert_der));
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
LOG_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mbedtls_pk_parse_key(pkey, echo_apps_key_der,
|
ret = mbedtls_pk_parse_key(pkey, echo_apps_key_der,
|
||||||
sizeof(echo_apps_key_der), NULL, 0);
|
sizeof(echo_apps_key_der), NULL, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_pk_parse_key returned %d", ret);
|
LOG_ERR("mbedtls_pk_parse_key returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ static int http_response(struct http_ctx *ctx, const char *header,
|
||||||
|
|
||||||
ret = http_add_header(ctx, header, dst, NULL);
|
ret = http_add_header(ctx, header, dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot add HTTP header (%d)", ret);
|
LOG_ERR("Cannot add HTTP header (%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ static int http_response(struct http_ctx *ctx, const char *header,
|
||||||
ret = http_add_header_field(ctx, "Content-Length", content_length,
|
ret = http_add_header_field(ctx, "Content-Length", content_length,
|
||||||
dst, NULL);
|
dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot add Content-Length HTTP header (%d)", ret);
|
LOG_ERR("Cannot add Content-Length HTTP header (%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,7 +175,7 @@ static int http_response(struct http_ctx *ctx, const char *header,
|
||||||
|
|
||||||
ret = http_send_chunk(ctx, payload, payload_len, dst, NULL);
|
ret = http_send_chunk(ctx, payload, payload_len, dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send data to peer (%d)", ret);
|
LOG_ERR("Cannot send data to peer (%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,7 +201,7 @@ static int http_serve_index_html(struct http_ctx *ctx,
|
||||||
#include "index.html.gz.inc"
|
#include "index.html.gz.inc"
|
||||||
};
|
};
|
||||||
|
|
||||||
NET_DBG("Sending index.html (%zd bytes) to client",
|
LOG_DBG("Sending index.html (%zd bytes) to client",
|
||||||
sizeof(index_html));
|
sizeof(index_html));
|
||||||
|
|
||||||
return http_response(ctx, HTTP_STATUS_200_OK_GZ, index_html,
|
return http_response(ctx, HTTP_STATUS_200_OK_GZ, index_html,
|
||||||
|
|
@ -215,7 +215,7 @@ static int http_serve_style_css(struct http_ctx *ctx,
|
||||||
#include "style.css.gz.inc"
|
#include "style.css.gz.inc"
|
||||||
};
|
};
|
||||||
|
|
||||||
NET_DBG("Sending style.css (%zd bytes) to client",
|
LOG_DBG("Sending style.css (%zd bytes) to client",
|
||||||
sizeof(style_css_gz));
|
sizeof(style_css_gz));
|
||||||
|
|
||||||
return http_response(ctx, HTTP_STATUS_200_OK_GZ_CSS,
|
return http_response(ctx, HTTP_STATUS_200_OK_GZ_CSS,
|
||||||
|
|
@ -230,7 +230,7 @@ static int http_serve_favicon_ico(struct http_ctx *ctx,
|
||||||
#include "favicon.ico.gz.inc"
|
#include "favicon.ico.gz.inc"
|
||||||
};
|
};
|
||||||
|
|
||||||
NET_DBG("Sending favicon.ico (%zd bytes) to client",
|
LOG_DBG("Sending favicon.ico (%zd bytes) to client",
|
||||||
sizeof(favicon_ico_gz));
|
sizeof(favicon_ico_gz));
|
||||||
|
|
||||||
return http_response(ctx, HTTP_STATUS_200_OK_GZ,
|
return http_response(ctx, HTTP_STATUS_200_OK_GZ,
|
||||||
|
|
@ -249,7 +249,7 @@ static void ws_connected(struct http_ctx *ctx,
|
||||||
memcpy(url, ctx->http.url, len);
|
memcpy(url, ctx->http.url, len);
|
||||||
url[len] = '\0';
|
url[len] = '\0';
|
||||||
|
|
||||||
NET_DBG("%s connect attempt URL %s",
|
LOG_DBG("%s connect attempt URL %s",
|
||||||
type == HTTP_CONNECTION ? "HTTP" : "WS", url);
|
type == HTTP_CONNECTION ? "HTTP" : "WS", url);
|
||||||
|
|
||||||
if (type == HTTP_CONNECTION) {
|
if (type == HTTP_CONNECTION) {
|
||||||
|
|
@ -307,7 +307,7 @@ static void ws_received(struct http_ctx *ctx,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#if EXTRA_DEBUG
|
#if EXTRA_DEBUG
|
||||||
NET_DBG("Received %d bytes data", net_pkt_appdatalen(pkt));
|
LOG_DBG("Received %d bytes data", net_pkt_appdatalen(pkt));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = ws_console_recv(ctx, pkt);
|
ret = ws_console_recv(ctx, pkt);
|
||||||
|
|
@ -315,7 +315,7 @@ static void ws_received(struct http_ctx *ctx,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
NET_ERR("Receive error (%d)", status);
|
LOG_ERR("Receive error (%d)", status);
|
||||||
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
@ -334,7 +334,7 @@ static void ws_sent(struct http_ctx *ctx,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
#if EXTRA_DEBUG
|
#if EXTRA_DEBUG
|
||||||
NET_DBG("Data sent status %d", status);
|
LOG_DBG("Data sent status %d", status);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -342,7 +342,7 @@ static void ws_closed(struct http_ctx *ctx,
|
||||||
int status,
|
int status,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
NET_DBG("Connection %p closed", ctx);
|
LOG_DBG("Connection %p closed", ctx);
|
||||||
|
|
||||||
ws_console_disable(ctx);
|
ws_console_disable(ctx);
|
||||||
}
|
}
|
||||||
|
|
@ -362,7 +362,7 @@ static enum http_verdict default_handler(struct http_ctx *ctx,
|
||||||
enum http_connection_type type,
|
enum http_connection_type type,
|
||||||
const struct sockaddr *dst)
|
const struct sockaddr *dst)
|
||||||
{
|
{
|
||||||
NET_DBG("No handler for %s URL %s",
|
LOG_DBG("No handler for %s URL %s",
|
||||||
type == HTTP_CONNECTION ? "HTTP" : "WS",
|
type == HTTP_CONNECTION ? "HTTP" : "WS",
|
||||||
get_string(ctx->http.url_len, ctx->http.url));
|
get_string(ctx->http.url_len, ctx->http.url));
|
||||||
|
|
||||||
|
|
@ -417,7 +417,7 @@ void start_ws_console(void)
|
||||||
|
|
||||||
ret = net_ipaddr_parse(ZEPHYR_ADDR, &addr);
|
ret = net_ipaddr_parse(ZEPHYR_ADDR, &addr);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot set local address (%d)", ret);
|
LOG_ERR("Cannot set local address (%d)", ret);
|
||||||
panic(NULL);
|
panic(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -440,7 +440,7 @@ void start_ws_console(void)
|
||||||
result, sizeof(result),
|
result, sizeof(result),
|
||||||
"Zephyr WS console", NULL);
|
"Zephyr WS console", NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init web server (%d)", ret);
|
LOG_ERR("Cannot init web server (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -462,7 +462,7 @@ void start_ws_console(void)
|
||||||
ws_tls_console_stack,
|
ws_tls_console_stack,
|
||||||
K_THREAD_STACK_SIZEOF(ws_tls_console_stack));
|
K_THREAD_STACK_SIZEOF(ws_tls_console_stack));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable TLS support (%d)", ret);
|
LOG_ERR("Cannot enable TLS support (%d)", ret);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ static struct k_sem quit_lock;
|
||||||
void panic(const char *msg)
|
void panic(const char *msg)
|
||||||
{
|
{
|
||||||
if (msg) {
|
if (msg) {
|
||||||
NET_ERR("%s", msg);
|
LOG_ERR("%s", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
@ -52,7 +52,7 @@ struct net_pkt *build_reply_pkt(const char *name,
|
||||||
struct net_buf *frag, *tmp;
|
struct net_buf *frag, *tmp;
|
||||||
int header_len = 0, recv_len, reply_len;
|
int header_len = 0, recv_len, reply_len;
|
||||||
|
|
||||||
NET_INFO("%s received %d bytes", name, net_pkt_appdatalen(pkt));
|
LOG_INF("%s received %d bytes", name, net_pkt_appdatalen(pkt));
|
||||||
|
|
||||||
if (net_pkt_appdatalen(pkt) == 0) {
|
if (net_pkt_appdatalen(pkt) == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -129,7 +129,7 @@ void pkt_sent(struct net_app_ctx *ctx,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
if (!status) {
|
if (!status) {
|
||||||
NET_INFO("Sent %d bytes", POINTER_TO_UINT(user_data_send));
|
LOG_INF("Sent %d bytes", POINTER_TO_UINT(user_data_send));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ void main(void)
|
||||||
|
|
||||||
k_sem_take(&quit_lock, K_FOREVER);
|
k_sem_take(&quit_lock, K_FOREVER);
|
||||||
|
|
||||||
NET_INFO("Stopping...");
|
LOG_INF("Stopping...");
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_NET_TCP)) {
|
if (IS_ENABLED(CONFIG_NET_TCP)) {
|
||||||
stop_server();
|
stop_server();
|
||||||
|
|
|
||||||
|
|
@ -98,14 +98,14 @@ static int setup_cert(struct net_app_ctx *ctx,
|
||||||
ret = mbedtls_x509_crt_parse(cert, echo_apps_cert_der,
|
ret = mbedtls_x509_crt_parse(cert, echo_apps_cert_der,
|
||||||
sizeof(echo_apps_cert_der));
|
sizeof(echo_apps_cert_der));
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
LOG_ERR("mbedtls_x509_crt_parse returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mbedtls_pk_parse_key(pkey, echo_apps_key_der,
|
ret = mbedtls_pk_parse_key(pkey, echo_apps_key_der,
|
||||||
sizeof(echo_apps_key_der), NULL, 0);
|
sizeof(echo_apps_key_der), NULL, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
NET_ERR("mbedtls_pk_parse_key returned %d", ret);
|
LOG_ERR("mbedtls_pk_parse_key returned %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,7 +139,7 @@ static int http_response(struct http_ctx *ctx, const char *header,
|
||||||
|
|
||||||
ret = http_add_header(ctx, header, dst, NULL);
|
ret = http_add_header(ctx, header, dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot add HTTP header (%d)", ret);
|
LOG_ERR("Cannot add HTTP header (%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,7 +153,7 @@ static int http_response(struct http_ctx *ctx, const char *header,
|
||||||
ret = http_add_header_field(ctx, "Content-Length", content_length,
|
ret = http_add_header_field(ctx, "Content-Length", content_length,
|
||||||
dst, NULL);
|
dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot add Content-Length HTTP header (%d)", ret);
|
LOG_ERR("Cannot add Content-Length HTTP header (%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ static int http_response(struct http_ctx *ctx, const char *header,
|
||||||
|
|
||||||
ret = http_send_chunk(ctx, payload, payload_len, dst, NULL);
|
ret = http_send_chunk(ctx, payload, payload_len, dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot send data to peer (%d)", ret);
|
LOG_ERR("Cannot send data to peer (%d)", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -178,7 +178,7 @@ static int http_serve_index_html(struct http_ctx *ctx,
|
||||||
#include "index.html.inc"
|
#include "index.html.inc"
|
||||||
};
|
};
|
||||||
|
|
||||||
NET_DBG("Sending index.html (%zd bytes) to client",
|
LOG_DBG("Sending index.html (%zd bytes) to client",
|
||||||
sizeof(index_html));
|
sizeof(index_html));
|
||||||
|
|
||||||
return http_response(ctx, HTTP_STATUS_200_OK, index_html,
|
return http_response(ctx, HTTP_STATUS_200_OK, index_html,
|
||||||
|
|
@ -192,7 +192,7 @@ static int http_serve_js(struct http_ctx *ctx,
|
||||||
#include "ws.js.gz.inc"
|
#include "ws.js.gz.inc"
|
||||||
};
|
};
|
||||||
|
|
||||||
NET_DBG("Sending ws.js (%zd bytes) to client", sizeof(js_gz));
|
LOG_DBG("Sending ws.js (%zd bytes) to client", sizeof(js_gz));
|
||||||
return http_response(ctx, HTTP_STATUS_200_OK_GZ_CSS,
|
return http_response(ctx, HTTP_STATUS_200_OK_GZ_CSS,
|
||||||
js_gz, sizeof(js_gz), dst);
|
js_gz, sizeof(js_gz), dst);
|
||||||
}
|
}
|
||||||
|
|
@ -232,11 +232,11 @@ static int append_and_send_data(struct http_ctx *http_ctx,
|
||||||
ret = ws_send_msg_to_client(http_ctx, buf, len,
|
ret = ws_send_msg_to_client(http_ctx, buf, len,
|
||||||
opcode, final, dst, NULL);
|
opcode, final, dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_DBG("Could not send %zd bytes data to client",
|
LOG_DBG("Could not send %zd bytes data to client",
|
||||||
len);
|
len);
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
NET_DBG("Sent %zd bytes to client", len);
|
LOG_DBG("Sent %zd bytes to client", len);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_count = 0;
|
msg_count = 0;
|
||||||
|
|
@ -251,10 +251,10 @@ static int append_and_send_data(struct http_ctx *http_ctx,
|
||||||
ret = ws_send_msg_to_client(http_ctx, buf, len,
|
ret = ws_send_msg_to_client(http_ctx, buf, len,
|
||||||
opcode, final, dst, NULL);
|
opcode, final, dst, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_DBG("Could not send %zd bytes data to client", len);
|
LOG_DBG("Could not send %zd bytes data to client", len);
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
NET_DBG("Sent %zd bytes to client", len);
|
LOG_DBG("Sent %zd bytes to client", len);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_count++;
|
msg_count++;
|
||||||
|
|
@ -266,7 +266,7 @@ out:
|
||||||
static int ws_works(struct http_ctx *ctx,
|
static int ws_works(struct http_ctx *ctx,
|
||||||
const struct sockaddr *dst)
|
const struct sockaddr *dst)
|
||||||
{
|
{
|
||||||
NET_INFO("WS url called");
|
LOG_INF("WS url called");
|
||||||
|
|
||||||
append_and_send_data(ctx, dst, false, "connection");
|
append_and_send_data(ctx, dst, false, "connection");
|
||||||
append_and_send_data(ctx, dst, true, " established.");
|
append_and_send_data(ctx, dst, true, " established.");
|
||||||
|
|
@ -285,7 +285,7 @@ static void ws_connected(struct http_ctx *ctx,
|
||||||
memcpy(url, ctx->http.url, len);
|
memcpy(url, ctx->http.url, len);
|
||||||
url[len] = '\0';
|
url[len] = '\0';
|
||||||
|
|
||||||
NET_DBG("%s connect attempt URL %s",
|
LOG_DBG("%s connect attempt URL %s",
|
||||||
type == HTTP_CONNECTION ? "HTTP" : "WS", url);
|
type == HTTP_CONNECTION ? "HTTP" : "WS", url);
|
||||||
|
|
||||||
if (type == HTTP_CONNECTION) {
|
if (type == HTTP_CONNECTION) {
|
||||||
|
|
@ -341,7 +341,7 @@ static void ws_received(struct http_ctx *ctx,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Received %d bytes data", net_pkt_appdatalen(pkt));
|
LOG_DBG("Received %d bytes data", net_pkt_appdatalen(pkt));
|
||||||
|
|
||||||
if (flags & WS_FLAG_BINARY) {
|
if (flags & WS_FLAG_BINARY) {
|
||||||
opcode = WS_OPCODE_DATA_BINARY;
|
opcode = WS_OPCODE_DATA_BINARY;
|
||||||
|
|
@ -359,11 +359,11 @@ static void ws_received(struct http_ctx *ctx,
|
||||||
frag->frags ? true : false,
|
frag->frags ? true : false,
|
||||||
dst, user_data);
|
dst, user_data);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_DBG("Cannot send ws data (%d bytes) "
|
LOG_DBG("Cannot send ws data (%d bytes) "
|
||||||
"back (%d)",
|
"back (%d)",
|
||||||
frag->len - hdr_len, ret);
|
frag->len - hdr_len, ret);
|
||||||
} else {
|
} else {
|
||||||
NET_DBG("Sent %d bytes to client",
|
LOG_DBG("Sent %d bytes to client",
|
||||||
frag->len - hdr_len);
|
frag->len - hdr_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -380,7 +380,7 @@ static void ws_received(struct http_ctx *ctx,
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
NET_ERR("Receive error (%d)", status);
|
LOG_ERR("Receive error (%d)", status);
|
||||||
|
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
|
|
@ -393,14 +393,14 @@ static void ws_sent(struct http_ctx *ctx,
|
||||||
void *user_data_send,
|
void *user_data_send,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
NET_DBG("Data sent status %d", status);
|
LOG_DBG("Data sent status %d", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ws_closed(struct http_ctx *ctx,
|
static void ws_closed(struct http_ctx *ctx,
|
||||||
int status,
|
int status,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
NET_DBG("Connection %p closed", ctx);
|
LOG_DBG("Connection %p closed", ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *get_string(int str_len, const char *str)
|
static const char *get_string(int str_len, const char *str)
|
||||||
|
|
@ -418,7 +418,7 @@ static enum http_verdict default_handler(struct http_ctx *ctx,
|
||||||
enum http_connection_type type,
|
enum http_connection_type type,
|
||||||
const struct sockaddr *dst)
|
const struct sockaddr *dst)
|
||||||
{
|
{
|
||||||
NET_DBG("No handler for %s URL %s",
|
LOG_DBG("No handler for %s URL %s",
|
||||||
type == HTTP_CONNECTION ? "HTTP" : "WS",
|
type == HTTP_CONNECTION ? "HTTP" : "WS",
|
||||||
get_string(ctx->http.url_len, ctx->http.url));
|
get_string(ctx->http.url_len, ctx->http.url));
|
||||||
|
|
||||||
|
|
@ -473,7 +473,7 @@ void start_server(void)
|
||||||
|
|
||||||
ret = net_ipaddr_parse(ZEPHYR_ADDR, &addr);
|
ret = net_ipaddr_parse(ZEPHYR_ADDR, &addr);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot set local address (%d)", ret);
|
LOG_ERR("Cannot set local address (%d)", ret);
|
||||||
panic(NULL);
|
panic(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -495,7 +495,7 @@ void start_server(void)
|
||||||
result, sizeof(result),
|
result, sizeof(result),
|
||||||
"Zephyr WS server", NULL);
|
"Zephyr WS server", NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot init web server (%d)", ret);
|
LOG_ERR("Cannot init web server (%d)", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -516,7 +516,7 @@ void start_server(void)
|
||||||
ws_tls_stack,
|
ws_tls_stack,
|
||||||
K_THREAD_STACK_SIZEOF(ws_tls_stack));
|
K_THREAD_STACK_SIZEOF(ws_tls_stack));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
NET_ERR("Cannot enable TLS support (%d)", ret);
|
LOG_ERR("Cannot enable TLS support (%d)", ret);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue