terence zhang / Mbed OS mbed-os-example-wakaama

Dependencies:   C12832 LM75B

Revision:
14:ec9e195830ff
Parent:
12:cc4b0014fc3a
Child:
15:d0f20339c1ad
--- a/wakaama/liblwm2m.c	Wed May 03 11:13:02 2017 +0000
+++ b/wakaama/liblwm2m.c	Sat May 06 11:21:27 2017 +0000
@@ -199,6 +199,45 @@
 }
 
 #ifdef LWM2M_CLIENT_MODE
+
+#ifdef MBED_OS_EXAMPLE_WAKAAMA
+int lwm2m_add_server(lwm2m_context_t * contextP,
+                     uint16_t shortID,
+                     uint32_t lifetime,
+                     char * sms,
+                     lwm2m_binding_t binding,
+                     void * sessionH,
+                     lwm2m_security_t * securityP)
+{
+    lwm2m_server_t * serverP;
+    int status = COAP_500_INTERNAL_SERVER_ERROR;
+
+    serverP = (lwm2m_server_t *)lwm2m_malloc(sizeof(lwm2m_server_t));
+    if (serverP != NULL)
+    {
+        memset(serverP, 0, sizeof(lwm2m_server_t));
+        memcpy(&(serverP->security), securityP, sizeof(lwm2m_security_t));
+        serverP->shortID = shortID;
+        serverP->lifetime = lifetime;
+        serverP->binding = binding;
+        if (sms != NULL)
+        {
+            // copy the SMS number
+            int len = strlen(sms);
+            serverP->sms = (char*) lwm2m_malloc(strlen(sms)+1);
+            memcpy(serverP->sms, sms, len+1);
+        }
+        serverP->sessionH = sessionH;
+        contextP->serverList = (lwm2m_server_t*)LWM2M_LIST_ADD(contextP->serverList, serverP);
+
+        status = COAP_NO_ERROR;
+    }
+
+    return status;
+}
+#endif
+
+
 static int prv_refreshServerList(lwm2m_context_t * contextP)
 {
     lwm2m_server_t * targetP;
@@ -256,9 +295,10 @@
     LOG_ARG("endpointName: \"%s\", msisdn: \"%s\", altPath: \"%s\", numObject: %d", endpointName, msisdn, altPath, numObject);
     // This API can be called only once for now
     if (contextP->endpointName != NULL || contextP->objectList != NULL) return COAP_400_BAD_REQUEST;
+    printf(">>>1\n");
 
     if (endpointName == NULL) return COAP_400_BAD_REQUEST;
-    if (numObject < 3) return COAP_400_BAD_REQUEST;
+    //if (numObject < 3) return COAP_400_BAD_REQUEST;
     // Check that mandatory objects are present
     found = 0;
     for (i = 0 ; i < numObject ; i++)
@@ -271,7 +311,7 @@
     if (altPath != NULL)
     {
         if (0 == utils_isAltPathValid(altPath))
-        {
+        {   
             return COAP_400_BAD_REQUEST;
         }
         if (altPath[1] == 0)