contiki-os / contiki

The official git repository for Contiki, the open source OS for the Internet of Things
http://www.contiki-os.org/
Other
3.69k stars 2.58k forks source link

Bug in Contiki CoAP Observing implementation with CON messages #1985

Open Altamura opened 7 years ago

Altamura commented 7 years ago

Hello to everybody. I have found some bug in the Contiki CoAP code, more specifically in the portion regardind the Observing functionality. I have simulated a network in Cooja (with Z1 motes) including:

In order to correctly compile and execute the code I have added the following parameters to the project-conf.h file:

undef NBR_TABLE_CONF_MAX_NEIGHBORS

define NBR_TABLE_CONF_MAX_NEIGHBORS 10

undef UIP_CONF_MAX_ROUTES

define UIP_CONF_MAX_ROUTES 10

undef UIP_CONF_BUFFER_SIZE

define UIP_CONF_BUFFER_SIZE 280

In the simulation everything works fine and the client correctly received the periodic notifications from the server. Each notification consist of a string "VERY LONG EVENT X" where X is an integer incremented for each step.

However this approach uses NON message, so when the client receives a notification he dosn't reply with an ACK. I have modified this behavior changing the 'coap_notify_observers_sub()' function in /apps/er-coap/er-coap-observe.c with the instruction:

coap_init_message(notification, COAP_TYPE_CON, CONTENT_2_05, 0);

In this way the server notify each subscribers for that resource with a CON message. From this moment the observing mechanism doesn't work as expected infact the first character in the notification is always different and wrong. Infact the client correctly receive the notification but its payload is (wrongly) changed when he reply with the ACK. More in detail the notification is changed during this instruction:

coap_send_message(addr, port, uip_appdata, len);

in the simple_reply() function (see er-coap-observe-client.c), invoked in the coap_handle_notification() function with:

if(notification->type == COAP_TYPE_CON) { simple_reply(COAP_TYPE_ACK, addr, port, notification); }

Something wrong happens during the coap_send_message function. What exactly? Thank you for your help.

araldit commented 6 years ago

I just discovered this bug myself - did you ever investigate any further?

Altamura commented 6 years ago

No, I'm sorry.


From: Ole Nissen notifications@github.com Sent: Thursday, December 28, 2017 12:30:35 PM To: contiki-os/contiki Cc: Altamura; Author Subject: Re: [contiki-os/contiki] Bug in Contiki CoAP Observing implementation with CON messages (#1985)

I just discovered this bug myself - did you ever investigate any further?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/contiki-os/contiki/issues/1985#issuecomment-354274449, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AXXEALn0VEuakxzZfwWXk2A6e882w7hqks5tE3vbgaJpZM4LJsY5.

SyedRazaBashir commented 6 years ago

hi. how to send coap packets from client to server through border router