Skip to content

Commit df220d7

Browse files
Arto Kinnunencmonr
Arto Kinnunen
authored andcommitted
Squashed 'features/nanostack/FEATURE_NANOSTACK/coap-service/' changes from d0a2597..8689fca
8689fca Reverting address check from transaction find (#89) ca3c3ab Fix transactions to handle all token lengths (#87) git-subtree-dir: features/nanostack/FEATURE_NANOSTACK/coap-service git-subtree-split: 8689fca
1 parent dcfce96 commit df220d7

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

features/nanostack/FEATURE_NANOSTACK/coap-service/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ override CFLAGS += -I$(EVENTLOOP_DIR)/nanostack-event-loop/
4848
COAPSERVICE_DIR := ../coap-service
4949
override CFLAGS += -I$(COAPSERVICE_DIR)/coap-service/
5050
override CFLAGS += -I$(COAPSERVICE_DIR)/source/include/
51-
52-
ifeq (Linux,$(shell uname))
5351
override CFLAGS += -DHAVE_DEBUG
54-
endif
5552

5653
LIB = libcoap-service.a
5754

features/nanostack/FEATURE_NANOSTACK/coap-service/source/coap_message_handler.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ static void own_free(void *ptr)
4646

4747
static NS_LIST_DEFINE(request_list, coap_transaction_t, link);
4848

49-
static coap_transaction_t *transaction_find_client_by_token(uint8_t token[4])
49+
static coap_transaction_t *transaction_find_client_by_token(uint8_t *token, uint8_t token_len, const uint8_t address[static 16], uint16_t port)
5050
{
51+
(void) address;
52+
(void) port;
5153
coap_transaction_t *this = NULL;
54+
5255
ns_list_foreach(coap_transaction_t, cur_ptr, &request_list) {
53-
if (memcmp(cur_ptr->token,token,4) == 0 && cur_ptr->client_request) {
56+
if ((cur_ptr->token_len == token_len) && (memcmp(cur_ptr->token, token, token_len) == 0) && cur_ptr->client_request) {
5457
this = cur_ptr;
55-
break;
58+
break;
5659
}
5760
}
5861
return this;
@@ -147,12 +150,13 @@ static int8_t coap_rx_function(sn_coap_hdr_s *resp_ptr, sn_nsdl_addr_s *address_
147150
coap_transaction_t *this = NULL;
148151
(void)address_ptr;
149152
(void)param;
153+
150154
tr_warn("transaction was not handled %d", resp_ptr->msg_id);
151155
if (!resp_ptr) {
152156
return -1;
153157
}
154-
if( resp_ptr->token_ptr ){
155-
this = transaction_find_client_by_token(resp_ptr->token_ptr);
158+
if(resp_ptr->token_ptr){
159+
this = transaction_find_client_by_token(resp_ptr->token_ptr, resp_ptr->token_len, address_ptr->addr_ptr, address_ptr->port);
156160
}
157161
if (!this) {
158162
return 0;
@@ -278,6 +282,7 @@ int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t
278282
memcpy(transaction_ptr->remote_address, source_addr_ptr, 16);
279283
if (coap_message->token_len) {
280284
memcpy(transaction_ptr->token, coap_message->token_ptr, coap_message->token_len);
285+
transaction_ptr->token_len = coap_message->token_len;
281286
}
282287
transaction_ptr->remote_port = port;
283288
if (cb(socket_id, coap_message, transaction_ptr) < 0) {
@@ -292,7 +297,7 @@ int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t
292297
} else {
293298
coap_transaction_t *this = NULL;
294299
if (coap_message->token_ptr) {
295-
this = transaction_find_client_by_token(coap_message->token_ptr);
300+
this = transaction_find_client_by_token(coap_message->token_ptr, coap_message->token_len, source_addr_ptr, port);
296301
}
297302
if (!this) {
298303
tr_error("client transaction not found");
@@ -352,8 +357,9 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
352357

353358
do{
354359
randLIB_get_n_bytes_random(token,4);
355-
}while(transaction_find_client_by_token(token));
360+
}while(transaction_find_client_by_token(token, 4, destination_addr, destination_port));
356361
memcpy(transaction_ptr->token,token,4);
362+
transaction_ptr->token_len = 4;
357363
request.token_ptr = transaction_ptr->token;
358364
request.token_len = 4;
359365

@@ -464,7 +470,7 @@ int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle,
464470
response.payload_len = payload_len;
465471
response.payload_ptr = (uint8_t *) payload_ptr; // Cast away const and trust that nsdl doesn't modify...
466472
response.content_format = content_type;
467-
response.token_len = 4;
473+
response.token_len = transaction_ptr->token_len;
468474
response.token_ptr = transaction_ptr->token;
469475
response.msg_code = message_code;
470476
if (transaction_ptr->req_msg_type == COAP_MSG_TYPE_CONFIRMABLE) {

features/nanostack/FEATURE_NANOSTACK/coap-service/source/include/coap_message_handler.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@ typedef struct coap_msg_handler_s {
5050
typedef struct coap_transaction {
5151
uint8_t remote_address[16];
5252
uint8_t local_address[16];
53-
uint8_t token[4];
53+
uint8_t token[8];
5454
uint32_t create_time;
55+
uint8_t *data_ptr;
56+
coap_message_handler_response_recv *resp_cb;
5557
uint16_t remote_port;
5658
uint16_t msg_id;
5759
uint16_t data_len;
5860
int8_t service_id;
5961
uint8_t options;
60-
uint8_t *data_ptr;
62+
uint8_t token_len;
6163
sn_coap_msg_type_e req_msg_type;
6264
bool client_request: 1;
6365

64-
coap_message_handler_response_recv *resp_cb;
6566
ns_list_link_t link;
6667
} coap_transaction_t;
6768

0 commit comments

Comments
 (0)