Make all multicast coap messages sent as Low_QoS/NON.
authorYamin Al-Mousa <yamin.s.al-mousa@intel.com>
Fri, 19 Dec 2014 18:44:34 +0000 (10:44 -0800)
committerYamin Al-Mousa <yamin.s.al-mousa@intel.com>
Fri, 19 Dec 2014 18:44:34 +0000 (10:44 -0800)
When a client in C++ is configured to use HighQoS,
then discovery request goes as CON to a multicast address.
However, responses/ACKs are coming from a unicast address.
This makes it impossible for clients to associate requests
with responses and stop retrying CON pdus.Now, CoAP layer is
making sure that all packets sent to multicast address are NON.

Change-Id: I41f351c5c9ce75fc4846d970514733bef5cdce61
Signed-off-by: Yamin Al-Mousa <yamin.s.al-mousa@intel.com>
Signed-off-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
resource/csdk/libcoap-4.1.1/net.c
resource/csdk/occoap/include/occoaphelper.h
resource/csdk/occoap/src/occoap.c
resource/csdk/occoap/src/occoaphelper.c
resource/csdk/stack/include/ocstack.h

index 4fce8f9..d36b0e2 100644 (file)
@@ -997,9 +997,9 @@ int coap_remove_from_queue(coap_queue_t **queue, coap_tid_t id,
 
     if (!queue || !*queue)
         return 0;
+    debug("*** looking for transaction %u == %u\n", id, (*queue)->id);
 
     /* replace queue head if PDU's time is less than head's time */
-
     if (id == (*queue)->id) { /* found transaction */
         *node = *queue;
         *queue = (*queue)->next;
index 2dc687e..8e36776 100644 (file)
 #define MAX_URI_QUERY_BUF_SIZE ((MAX_URI_LENGTH) >= (MAX_QUERY_LENGTH) ?\
                             (MAX_URI_LENGTH) : (MAX_QUERY_LENGTH))
 
+#define COAP_WK_IPAddr_0 (224)
+#define COAP_WK_IPAddr_1 (0)
+#define COAP_WK_IPAddr_2 (1)
+#define COAP_WK_IPAddr_3 (187)
+
 // checks if optionID is within vendor specific range
 OCStackResult isVendorSpecific(uint16_t optionID);
 
@@ -49,7 +54,7 @@ OCStackResult isVendorSpecific(uint16_t optionID);
 uint8_t OCToCoAPResponseCode(OCStackResult result);
 
 //Convert OCQualityOfService to coap NON vs CON
-uint8_t OCToCoAPQoS(OCQualityOfService qos);
+uint8_t OCToCoAPQoS(OCQualityOfService qos, uint8_t * ipAddr);
 
 // Convert CoAP code to OCStack code
 OCStackResult CoAPToOCResponseCode(uint8_t coapCode);
index 78bce42..813c5e8 100644 (file)
@@ -55,7 +55,6 @@
 // Private Variables
 //=============================================================================
 
-static uint8_t coapWKIpAddr[] = { 224, 0, 1, 187 };
 static coap_context_t *gCoAPCtx = NULL;
 
 //=============================================================================
@@ -676,8 +675,8 @@ OCStackResult OCInitCoAP(const char *address, uint16_t port, OCMode mode) {
 
     // To allow presence notification work we need to init socket gCoAPCtx->sockfd_wellknown
     // for servers as well as clients
-    OCBuildIPv4Address(coapWKIpAddr[0], coapWKIpAddr[1], coapWKIpAddr[2],
-            coapWKIpAddr[3], COAP_DEFAULT_PORT, &mcastAddr);
+    OCBuildIPv4Address(COAP_WK_IPAddr_0, COAP_WK_IPAddr_1, COAP_WK_IPAddr_2,
+            COAP_WK_IPAddr_3, COAP_DEFAULT_PORT, &mcastAddr);
     VERIFY_SUCCESS(
             coap_join_wellknown_group(gCoAPCtx,
                     (coap_address_t* )&mcastAddr), 0);
@@ -754,7 +753,7 @@ OCStackResult OCDoCoAPResource(OCMethod method, OCQualityOfService qos, OCCoAPTo
         OC_LOG_V(DEBUG, TAG, "secure uri %d", uri.secure);
     }
 
-    coapMsgType = OCToCoAPQoS(qos);
+    coapMsgType = OCToCoAPQoS(qos, ipAddr);
 
     // Decide method type
     switch (method) {
index 966bd79..1727c26 100644 (file)
@@ -90,8 +90,13 @@ uint8_t OCToCoAPResponseCode(OCStackResult result)
     return ret;
 }
 
-uint8_t OCToCoAPQoS(OCQualityOfService qos)
+uint8_t OCToCoAPQoS(OCQualityOfService qos, uint8_t * ipAddr)
 {
+    if(ipAddr[0] == COAP_WK_IPAddr_0 && ipAddr[1] == COAP_WK_IPAddr_1 &&
+            ipAddr[2] == COAP_WK_IPAddr_2 && ipAddr[3] == COAP_WK_IPAddr_3)
+    {
+        return COAP_MESSAGE_NON;
+    }
     switch (qos)
     {
         case OC_HIGH_QOS:
index ab348f9..8be0d12 100644 (file)
@@ -425,7 +425,10 @@ OCStackResult OCProcess();
  * @param requiredUri        - URI of the resource to interact with
  * @param referenceUri       - URI of the reference resource
  * @param request            - JSON encoded request
- * @param qos                - quality of service
+ * @param qos                - quality of service. Note that if this API is called on a uri with
+ *                             the well-known multicast IP address, the qos will be forced to
+ *                             OC_LOW_QOS
+ *                             since it is impractical to send other QOS levels on such addresses.
  * @param clientApplicationCB- asynchronous callback function that is invoked
  *                             by the stack when discovery or resource interaction is complete
  * @param options            - The address of an array containing the vendor specific