Made changes to support Arduino 1.5.8 with Connectivity Abstraction.
authorJoseph Morrow <joseph.l.morrow@intel.com>
Mon, 2 Feb 2015 23:40:01 +0000 (18:40 -0500)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Tue, 3 Feb 2015 01:16:18 +0000 (01:16 +0000)
Since the CA Layer assumes version 1.5.8 of Arduino, our original
makefile implementation had to be updated to match this.

Since the directory structure is mildly different between 1.0.5 and
1.5.8, these changes were necessary that are found in
arduinomega.proerties.

Due to casting errors, source code was updated accordingly.

Change-Id: Ib8f68fa9dd4f14af2dfadbeac2f0d85cc0d292d4
Signed-off-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/34
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sashi Penta <sashi.kumar.penta@intel.com>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
18 files changed:
resource/csdk/arduinomega.properties
resource/csdk/connectivity/build/arduino/Makefile
resource/csdk/connectivity/common/SConscript
resource/csdk/connectivity/lib/libcoap-4.1.1/coap_list.c
resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.c
resource/csdk/connectivity/lib/libcoap-4.1.1/resource.c
resource/csdk/connectivity/lib/libcoap-4.1.1/str.c
resource/csdk/connectivity/lib/libcoap-4.1.1/uri.c
resource/csdk/makefile
resource/csdk/ocsocket/src/ocsocket.c
resource/csdk/ocsocket/src/ocsocket_arduino.c [moved from resource/csdk/ocsocket/src/ocsocket_arduino.cpp with 100% similarity]
resource/csdk/ocsocket/src/ocsocket_arduino_wifi.c [moved from resource/csdk/ocsocket/src/ocsocket_arduino_wifi.cpp with 100% similarity]
resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript
resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/makefile
resource/csdk/stack/src/occlientcb.c
resource/csdk/stack/src/ocobserve.c
resource/csdk/stack/src/ocserverrequest.c
resource/csdk/stack/src/ocstack.c

index 2b76cee..58b46e8 100644 (file)
@@ -1,22 +1,22 @@
 
 #Source directories
-SDIR_ARD_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
-SDIR_ARD_SPI = $(ARDUINO_DIR)/libraries/SPI
-SDIR_ARD_ETH = $(ARDUINO_DIR)/libraries/Ethernet
-SDIR_ARD_ETH_UTIL = $(ARDUINO_DIR)/libraries/Ethernet/utility
-SDIR_ARD_WIFI = $(ARDUINO_DIR)/libraries/WiFi
-SDIR_ARD_WIFI_UTIL = $(ARDUINO_DIR)/libraries/WiFi/utility
+SDIR_ARD_CORE = $(ARDUINO_DIR)/hardware/arduino/avr/cores/arduino
+SDIR_ARD_SPI = $(ARDUINO_DIR)/hardware/arduino/avr/libraries/SPI
+SDIR_ARD_ETH = $(ARDUINO_DIR)/libraries/Ethernet/src
+SDIR_ARD_ETH_UTIL = $(ARDUINO_DIR)/libraries/Ethernet/src/utility
+SDIR_ARD_WIFI = $(ARDUINO_DIR)/libraries/WiFi/src
+SDIR_ARD_WIFI_UTIL = $(ARDUINO_DIR)/libraries/WiFi/src/utility
 SDIR_ARD_TIME = $(ARDUINO_DIR)/libraries/Time/Time
 SDIR_ARD_PLATFORM = $(SDIR_ARD_CORE):$(SDIR_ARD_SPI):$(SDIR_ARD_TIME)
 
 #include directories
-INCD_ARD_CORE = -I$(ARDUINO_DIR)/hardware/arduino/cores/arduino
-INCD_ARD_VARIANT = -I$(ARDUINO_DIR)/hardware/arduino/variants/mega
-INCD_ARD_SPI = -I$(ARDUINO_DIR)/libraries/SPI
-INCD_ARD_ETH = -I$(ARDUINO_DIR)/libraries/Ethernet
-INCD_ARD_ETH_UTIL = -I$(ARDUINO_DIR)/libraries/Ethernet/utility
-INCD_ARD_WIFI = -I$(ARDUINO_DIR)/libraries/WiFi
-INCD_ARD_WIFI_UTIL = -I$(ARDUINO_DIR)/libraries/WiFi/utility
+INCD_ARD_CORE = -I$(ARDUINO_DIR)/hardware/arduino/avr/cores/arduino
+INCD_ARD_VARIANT = -I$(ARDUINO_DIR)/hardware/arduino/avr/variants/mega
+INCD_ARD_SPI = -I$(ARDUINO_DIR)/hardware/arduino/avr/libraries/SPI
+INCD_ARD_ETH = -I$(ARDUINO_DIR)/libraries/Ethernet/src
+INCD_ARD_ETH_UTIL = -I$(ARDUINO_DIR)/libraries/Ethernet/src/utility
+INCD_ARD_WIFI = -I$(ARDUINO_DIR)/libraries/WiFi/src
+INCD_ARD_WIFI_UTIL = -I$(ARDUINO_DIR)/libraries/WiFi/src/utility
 INCD_ARD_TIME = -I$(ARDUINO_DIR)/libraries/Time/Time
 
 INC_DIR_PLATFORM = $(INCD_ARD_CORE) $(INCD_ARD_VARIANT) $(INCD_ARD_SPI) $(INCD_ARD_TIME)
@@ -31,11 +31,12 @@ CC=$(ARDUINO_TOOLS_DIR)/avr-gcc
 AR=$(ARDUINO_TOOLS_DIR)/avr-ar
 RANLIB=$(ARDUINO_TOOLS_DIR)/avr-ranlib
 AVR_OBJCOPY=$(ARDUINO_TOOLS_DIR)/avr-objcopy
-AVR_PROGRAMMER=$(ARDUINO_TOOLS_DIR)/../../avrdude
+AVR_PROGRAMMER=$(ARDUINO_TOOLS_DIR)/avrdude
 
 #Needed object files
-CORE_COBJ = WInterrupts.o wiring.o wiring_digital.o
-CORE_CPPOBJ = main.o Stream.o WMath.o WString.o HardwareSerial.o Print.o SPI.o IPAddress.o
+CORE_COBJ = hooks.o WInterrupts.o wiring.o wiring_digital.o wiring_analog.o wiring_shift.o wiring_pulse.o
+CORE_CPPOBJ = CDC.o HardwareSerial.o HardwareSerial0.o HardwareSerial1.o HardwareSerial2.o HardwareSerial3.o IPAddress.o HID.o \
+              main.o new.o Print.o Stream.o Tone.o USBCore.o WMath.o WString.o SPI.o
 ETH_CPPOBJ = Dhcp.o Dns.o Ethernet.o EthernetUdp.o
 ETH_UTIL_CPPOBJ = socket.o w5100.o
 WIFI_COBJ = WiFi.o WiFiClient.o WiFiServer.o WiFiUdp.o server_drv.o spi_drv.o wifi_drv.o
index 495413d..46d418a 100644 (file)
@@ -30,7 +30,7 @@ all: prep_dirs core.a $(APP_NAME).o $(APP_NAME).elf $(APP_NAME).hex
 
 $(info *********PLATFORM_OBJS!!**********)
 core.a: $(PLATFORM_OBJS)
-       @cd $(OBJ_DIR) && $(AR) -x ../../../lib/libcoap-4.1.1/release/libcoap.a
+       @cd $(OBJ_DIR) && $(AR) -x ../../../lib/libcoap-4.1.1/$(BUILD)/libcoap.a
        $(AR) rcs $@ $(CORE_COBJ) $(CORE_CPPOBJ) $(PLATFORM_OBJS) $(OBJ_DIR)/*.o
        $(RANLIB) $@
 
index 9f4dcbf..4bf6cb1 100644 (file)
@@ -31,7 +31,7 @@ ca_common_src = [
        ]
        
 if ca_os == 'arduino':
-       env.Command(env.get('BUILD_DIR') + 'logger.c.o', None, '$CXX -o ' + env.get('BUILD_DIR') + 'logger.c.o' + ' $LINKFLAGS  $CCFLAGS  $CXXFLAGS ' + header + ' ' + 'common/src/logger.c')
+       env.Command(env.get('BUILD_DIR') + 'logger.c', None, '$CXX -o ' + env.get('BUILD_DIR') + 'logger.c' + ' $LINKFLAGS  $CCFLAGS  $CXXFLAGS ' + header + ' ' + 'common/src/logger.c')
        platform_src = [
                env.get('BUILD_DIR') + 'logger.c.o',
        ]
index f2f4808..73f1595 100644 (file)
@@ -75,7 +75,7 @@ void coap_delete_list(coap_list_t *queue)
 coap_list_t *
 coap_new_listnode(void *data, void (*delete_func)(void *))
 {
-    coap_list_t *node = coap_malloc( sizeof(coap_list_t) );
+    coap_list_t *node = (coap_list_t *) coap_malloc( sizeof(coap_list_t) );
     if (!node)
     {
 #ifndef NDEBUG
index 9262503..5762007 100644 (file)
@@ -98,7 +98,7 @@ coap_pdu_init(unsigned char type, unsigned char code, unsigned short id, size_t
 
     /* size must be large enough for hdr */
 #if defined(WITH_POSIX) || defined(WITH_ARDUINO)
-    pdu = coap_malloc(sizeof(coap_pdu_t) + size);
+    pdu = (coap_pdu_t *) coap_malloc(sizeof(coap_pdu_t) + size);
 #endif
 #ifdef WITH_CONTIKI
     pdu = (coap_pdu_t *)memb_alloc(&pdu_storage);
index fd78268..8c3a3ec 100644 (file)
@@ -119,7 +119,7 @@ int match(const str *text, const str *pattern, int match_prefix, int match_subst
         {
             size_t token_length;
             unsigned char *token = next_token;
-            next_token = memchr(token, ' ', remaining_length);
+            next_token = (unsigned char *) memchr(token, ' ', remaining_length);
 
             if (next_token)
             {
@@ -637,7 +637,8 @@ coap_find_observer(coap_resource_t *resource, const coap_address_t *peer, const
     assert(resource);
     assert(peer);
 
-    for (s = list_head(resource->subscribers); s; s = list_item_next(s))
+    for (s = (coap_subscription_t *) list_head(resource->subscribers);
+            s; s = (coap_subscription_t *) list_item_next((void *) s))
     {
         if (coap_address_equals(&s->subscriber, peer)
                 && (!token
@@ -752,7 +753,8 @@ static void coap_notify_observers(coap_context_t *context, coap_resource_t *r)
         assert(h); /* we do not allow subscriptions if no
          * GET handler is defined */
 
-        for (obs = list_head(r->subscribers); obs; obs = list_item_next(obs))
+        for (obs = (coap_subscription_t *) list_head(r->subscribers);
+                obs; obs = (coap_subscription_t *) list_item_next((void *) obs))
         {
             if (r->dirty == 0 && obs->dirty == 0)
                 /* running this resource due to partiallydirty, but this observation's notification was already enqueued */
@@ -866,7 +868,8 @@ static void coap_remove_failed_observers(coap_context_t *context, coap_resource_
 {
     coap_subscription_t *obs;
 
-    for (obs = list_head(resource->subscribers); obs; obs = list_item_next(obs))
+    for (obs = (coap_subscription_t *) list_head(resource->subscribers);
+            obs; obs = (coap_subscription_t *) list_item_next((void *) obs))
     {
         if (coap_address_equals(peer, &obs->subscriber) && token->length == obs->token_length
                 && memcmp(token->s, obs->token, token->length) == 0)
index 82a5696..950803d 100644 (file)
@@ -16,7 +16,7 @@
 
 str *coap_new_string(size_t size)
 {
-    str *s = coap_malloc(sizeof(str) + size + 1);
+    str *s = (str *) coap_malloc(sizeof(str) + size + 1);
     if (!s)
     {
 #ifndef NDEBUG
index 8018520..31ac600 100644 (file)
@@ -427,7 +427,7 @@ coap_new_uri(const unsigned char *uri, unsigned int length)
 {
     unsigned char *result;
 
-    result = coap_malloc(length + 1 + sizeof(coap_uri_t));
+    result = (unsigned char *) coap_malloc(length + 1 + sizeof(coap_uri_t));
 
     if (!result)
         return NULL;
@@ -494,7 +494,7 @@ coap_clone_uri(const coap_uri_t *uri)
  * segment_handler_t hence we use this wrapper as safe typecast. */
 static inline void hash_segment(unsigned char *s, size_t len, void *data)
 {
-    coap_hash(s, len, data);
+    coap_hash(s, len, (unsigned char *) data);
 }
 
 int coap_hash_path(const unsigned char *path, size_t len, coap_key_t key)
index 57ad7e8..60f3a5a 100644 (file)
 # override with `make PLATFORM=arduinomega` or `make PLATFORM=arduinodue`
 # default to release build
 # default to build for linux
+# default to ETHERNET for transport
 BUILD   := release
 PLATFORM := linux
+TRANSPORT := ETHERNET
 
 # override with `make PLATFORM=arduinomega ARDUINOWIFI=1` to enable Arduino WiFi shield
 ARDUINOWIFI := 0
@@ -89,6 +91,7 @@ LCOAP_DIR             = libcoap-4.1.1
 OCCOAP_DIR             = occoap
 OCTBSTACK_DIR          = stack
 OCMALLOC_DIR           = ocmalloc
+OCSECURITY_DIR  = security
 EXTLIBS_DIR            = ../../extlibs
 CJSON_DIR              = $(EXTLIBS_DIR)/cjson
 TINYDTLS_DIR   = $(EXTLIBS_DIR)/tinydtls
@@ -97,8 +100,12 @@ CONNECTIVITY_DIR    = connectivity
 OCCOAP_SRC             = $(OCCOAP_DIR)/src
 OCTBSTACK_SRC          = $(OCTBSTACK_DIR)/src
 OCMALLOC_SRC           = $(OCMALLOC_DIR)/src
+OCSECURITY_SRC    = $(OCSECURITY_DIR)/src
 CJSON_SRC              = $(CJSON_DIR)
 CONNECTIVITY_SRC       = $(CONNECTIVITY_DIR)
+OCLOGGER_SRC           = $(OCLOGGER_DIR)/src
+OCSOCKET_SRC           = $(OCSOCKET_DIR)/src
+OCRANDOM_SRC           = $(OCRANDOM_DIR)/src
 
 OCLOGGER_INC           = $(OCLOGGER_DIR)/include
 OC_LOG_INC             = $(OC_LOG_DIR)/include
@@ -108,6 +115,7 @@ LCOAP_INC           = $(LCOAP_DIR)
 OCCOAP_INC             = $(OCCOAP_DIR)/include
 OCTBSTACK_INC          = $(OCTBSTACK_DIR)/include
 OCMALLOC_INC           = $(OCMALLOC_DIR)/include
+OCSECURITY_INC = $(OCSECURITY_DIR)/include
 CJSON_INC              = $(CJSON_DIR)
 CONNECTIVITY_INC       = $(CONNECTIVITY_DIR)/inc
 
@@ -118,6 +126,8 @@ INC_DIRS    += -I$(OCSOCKET_INC)
 INC_DIRS       += -I$(LCOAP_INC)
 INC_DIRS       += -I$(OCCOAP_INC)
 INC_DIRS       += -I$(OCMALLOC_INC)
+INC_DIRS       += -I$(OCSECURITY_INC)
+INC_DIRS       += -I$(OCSECURITY_INC)/internal
 INC_DIRS       += -I$(OCTBSTACK_INC)
 INC_DIRS       += -I$(OCTBSTACK_INC)/internal
 INC_DIRS       += -I$(CJSON_INC)
@@ -125,9 +135,9 @@ INC_DIRS    += -I$(CONNECTIVITY_INC)
 INC_DIRS       += -I$(CONNECTIVITY_DIR)/api
 
 # TODO-CA Remove -fstack-protector-all before merging to master
-CC_FLAGS.debug         := -O0 -g3 -Wall -fstack-protector-all -c -fmessage-length=0 -pedantic -fpic -DTB_LOG 
+CC_FLAGS.debug         := -O0 -g3 -Wall -fstack-protector-all -c -fmessage-length=0 -pedantic -fpic -DTB_LOG
 # TODO-CA Remove -fstack-protector-all before merging to master
-CC_FLAGS.release       := -Os -Wall -fstack-protector-all -c -fmessage-length=0 -fpic 
+CC_FLAGS.release       := -Os -Wall -fstack-protector-all -c -fmessage-length=0 -fpic
 
 CFLAGS         += $(CC_FLAGS.$(BUILD)) $(INC_DIRS) $(CFLAGS_PLATFORM) $(INC_DIR_PLATFORM)
 LDLIBS         += -lcoap
@@ -144,19 +154,29 @@ OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocobserve.c
 OCTBSTACK_SOURCES      += $(OCTBSTACK_SRC)/ocserverrequest.c
 OCTBSTACK_SOURCES      += $(OCTBSTACK_SRC)/occollection.c
 OCTBSTACK_SOURCES      += $(OCTBSTACK_SRC)/oicgroup.c
+OCTBSTACK_SOURCES      += $(OCSECURITY_SRC)/ocsecurity.c
+OCTBSTACK_SOURCES      += $(OCMALLOC_SRC)/ocmalloc.c
+OCTBSTACK_SOURCES      += $(OCLOGGER_SRC)/logger.c
+OCTBSTACK_SOURCES      += $(OCRANDOM_SRC)/ocrandom.c
+
+ifeq ($(PLATFORM_TYPE),arduino)
+    ifeq ($(ARDUINOWIFI),1)
+        OCTBSTACK_SOURCES += $(OCSOCKET_SRC)/ocsocket_arduino_wifi.c
+    else
+        OCTBSTACK_SOURCES += $(OCSOCKET_SRC)/ocsocket_arduino.c
+    endif
+else
+    OCTBSTACK_SOURCES += $(OCSOCKET_SRC)/ocsocket.c
+endif
 
 SOURCES                        := $(CJSON_SOURCES)
 SOURCES                        += $(OCCOAP_SOURCES)
 SOURCES                        += $(OCTBSTACK_SOURCES)
 
-all:   make_lcoap objdirs obj_build ca liboctbstack.a
+all:   objdirs obj_build ca liboctbstack.a
 
 buildScript_all: objdirs obj_build ca liboctbstack.a
 
-make_lcoap:
-       @echo "Building $@"
-       $(MAKE) -C $(LCOAP_DIR) "BUILD=$(BUILD)" "PLATFORM=$(PLATFORM)" "ARDUINOWIFI=$(ARDUINOWIFI)" "CA_INT_DTLS=$(CA_INT_DTLS)"
-
 objdirs:
        mkdir -p $(PLATFORM)
        mkdir -p $(PLATFORM)/$(ARDUINO_SHIELD_TYPE)
@@ -170,15 +190,15 @@ obj_build:
 
 ca:
        @echo "Building $@"
-       @cd $(CONNECTIVITY_SRC)/lib/libcoap-4.1.1 && $(MAKE)
-       @cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE)
-       @cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE)
-
+        ifeq ($(PLATFORM),linux)
+           @cd $(CONNECTIVITY_SRC)/lib/libcoap-4.1.1 && $(MAKE)
+           @cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE) "BUILD=$(BUILD)" "PLATFORM=linux"
+           @cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE)
+        else
+           @cd $(CONNECTIVITY_SRC)/build/ && $(MAKE) "PLATFORM=$(PLATFORM)" "ARDUINO_DIR=$(ARDUINO_DIR)" "TRANSPORT=$(TRANSPORT)"
+        endif
 liboctbstack.a:
        @echo "Building $@"
-       # Unpackage libcoap.a to $(OBJ_DIR)/$(BUILD). The output objects from OCStack and OCCoap are already at this location
-       @cd $(OBJ_DIR) && $(AR) -x $(PLATFORM_SPECIFIC_BACKOUT)$(LCOAP_DIR)/$(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)/libcoap.a
-       # Repackage all the objects at this location into a single archive. This is OCStack, OCCoap, and LibCoap (LibCoap contains OCRandom, OCLogger, and OCSocket.).
        $(AR) -r $(OUT_DIR)/$@ $(OBJ_DIR)/*.o
 
     ifeq ($(CA_INT_DTLS),0)
@@ -198,6 +218,8 @@ clean: legacy_clean
        -rm -rf linux
        -rm -rf arduinomega
        -rm -rf arduinodue
+       @cd $(CONNECTIVITY_SRC)/build/ && $(MAKE) clean "PLATFORM=arduinomega"
+       @cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE) "clean"
 
 deepclean: legacy_deepclean
        -rm -rf linux
@@ -223,6 +245,5 @@ legacy_deepclean:
        cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE) clean
        cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE) clean
        rm -rf $(OBJ_DIR)
-       $(MAKE) clean -C $(LCOAP_DIR)
        rm -rf release
        rm -rf debug
index 1593d94..d79c70b 100644 (file)
@@ -378,20 +378,16 @@ int32_t OCDevAddrToString(OCDevAddr* addr, char* stringAddress)
 int32_t OCDevAddrToIPv4Addr(OCDevAddr *ipAddr, uint8_t *a, uint8_t *b,
             uint8_t *c, uint8_t *d )
 {
-    struct sockaddr_in *sa;
-    uint32_t ip;
 
     if ( !ipAddr || !a || !b || !c || !d ) {
         OC_LOG(FATAL, MOD_NAME, "Invalid argument");
         return ERR_INVALID_INPUT;
     }
 
-    sa = (struct sockaddr_in*)ipAddr->addr;
-    ip = ntohl(sa->sin_addr.s_addr);
-    *d = *((uint8_t*)&ip + 0);
-    *c = *((uint8_t*)&ip + 1);
-    *b = *((uint8_t*)&ip + 2);
-    *a = *((uint8_t*)&ip + 3);
+    *a = ipAddr->addr[0];
+    *b = ipAddr->addr[1];
+    *c = ipAddr->addr[2];
+    *d = ipAddr->addr[3];
 
     return ERR_SUCCESS;
 }
@@ -400,14 +396,12 @@ int32_t OCDevAddrToIPv4Addr(OCDevAddr *ipAddr, uint8_t *a, uint8_t *b,
 /// Retrieve the IPv4 address embedded inside OCDev address data structure
 int32_t OCDevAddrToPort(OCDevAddr *ipAddr, uint16_t *port)
 {
-    struct sockaddr_in *sa;
     if ( !ipAddr || !port ) {
         OC_LOG(FATAL, MOD_NAME, "Invalid argument");
         return ERR_INVALID_INPUT;
     }
 
-    sa = (struct sockaddr_in*)ipAddr->addr;
-    *port = ntohs(sa->sin_port);
+    *port = *((uint16_t*)&ipAddr->addr[4]);
 
     return ERR_SUCCESS;
 }
index f5a4222..c064ae7 100644 (file)
@@ -12,7 +12,9 @@ arduino_simplecs_env.PrependUnique(CPPPATH = [
                ])
 
 arduino_simplecs_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-arduino_simplecs_env.PrependUnique(LIBS = ['octbstack', 'coap'])
+arduino_simplecs_env.PrependUnique(LIBS = ['octbstack', 'coap', 'connectivity_abstraction'])
+
+arduino_simplecs_env.AppendUnique(CPPDEFINES = ['CA_INT'])
 
 arduino_simplecs = arduino_simplecs_env.Program('SimpleClientServer', 'ocserver.cpp')
 env.CreateBin('SimpleClientServer')
@@ -20,4 +22,4 @@ env.CreateBin('SimpleClientServer')
 i_arduino_simplecs = arduino_simplecs_env.Install(env.get('BUILD_DIR'), arduino_simplecs)
 
 Alias('arduino_simplecs', i_arduino_simplecs)
-env.AppendTarget('arduino_simplecs')
\ No newline at end of file
+env.AppendTarget('arduino_simplecs')
index 3b01109..7d4655f 100644 (file)
@@ -45,8 +45,8 @@ LOGGER_DIR = $(ROOT_DIR)/logger
 STACK_DIR  = $(ROOT_DIR)/stack
 INC_DIRS = -I$(OCSOCK_DIR)/include/ -I$(OC_LOG_DIR)/include -I$(LOGGER_DIR)/include -I$(STACK_DIR)/include
 
-CC_FLAGS.debug         := -O1 -g3 -Wall -c -fmessage-length=0 -pedantic -fpic
-CC_FLAGS.release       := -Os -Wall -c -fmessage-length=0 -fpic
+CC_FLAGS.debug         := -O1 -g3 -Wall -c -fmessage-length=0 -pedantic -fpic -DCA_INT
+CC_FLAGS.release       := -Os -Wall -c -fmessage-length=0 -fpic -DCA_INT
 
 CFLAGS := $(CC_FLAGS.$(BUILD)) -DTB_LOG
 
@@ -67,6 +67,7 @@ all: prep_dirs core.a $(APP_NAME).o $(APP_NAME).elf $(APP_NAME).hex
 
 core.a: $(PLATFORM_OBJS)
        @cd $(OBJ_DIR) && $(AR) -x ../../../../$(ROOT_DIR)/$(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)/liboctbstack.a
+       @cd $(OBJ_DIR) && $(AR) -x ../../../../$(ROOT_DIR)/connectivity/build/arduino/core.a
        $(AR) rcs $(OBJ_DIR)/$@ $(foreach obj, $^, $(OBJ_DIR)/$(obj)) $(OBJ_DIR)/*.o
        @cd $(OBJ_DIR) && $(RANLIB) $@
 
@@ -103,7 +104,7 @@ endif
 
 install: all
 ifeq ($(PLATFORM),arduinomega)
-       $(AVR_PROGRAMMER) -C$(ARDUINO_DIR)/hardware/tools/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P/dev/$(ARDUINO_PORT) -b115200 -D -Uflash:w:$(OUT_DIR)/$(APP_NAME).hex:i
+       $(AVR_PROGRAMMER) -C$(ARDUINO_DIR)/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P/dev/$(ARDUINO_PORT) -b115200 -D -Uflash:w:$(OUT_DIR)/$(APP_NAME).hex:i
 else ifeq ($(PLATFORM),arduinodue)
        stty -F /dev/$(ARDUINO_PORT) speed 1200 cs8 -cstopb -parenb
        $(ARDUINO_DIR)/hardware/tools/bossac -i -d --port=$(ARDUINO_PORT) -U false -e -w -v -b $(OUT_DIR)/$(APP_NAME).hex -R
index 0bb05f1..349d9e1 100644 (file)
@@ -108,7 +108,7 @@ void DeleteClientCB(ClientCB * cbNode) {
         LL_DELETE(cbList, cbNode);
         OC_LOG(INFO, TAG, PCF("deleting tokens"));
         CADestroyToken (cbNode->token);
-        OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)cbNode->token, CA_MAX_TOKEN_LEN);
+        OC_LOG_BUFFER(INFO, TAG, (const unsigned char *)cbNode->token, CA_MAX_TOKEN_LEN);
         OCFree(cbNode->handle);
         OCFree(cbNode->requestUri);
         if(cbNode->deleteCallback)
@@ -145,8 +145,8 @@ ClientCB* GetClientCB(const CAToken_t * token, OCDoHandle handle, const unsigned
     if(token) {
         LL_FOREACH(cbList, out) {
             OC_LOG(INFO, TAG, PCF("comparing tokens"));
-            OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)*token, CA_MAX_TOKEN_LEN);
-            OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)out->token, CA_MAX_TOKEN_LEN);
+            OC_LOG_BUFFER(INFO, TAG, (const unsigned char *)*token, CA_MAX_TOKEN_LEN);
+            OC_LOG_BUFFER(INFO, TAG, (const unsigned char *)out->token, CA_MAX_TOKEN_LEN);
             if(memcmp(out->token, *token, CA_MAX_TOKEN_LEN) == 0)
             {
                 return out;
index 778433a..30539bb 100644 (file)
@@ -366,8 +366,8 @@ ResourceObserver* GetObserverUsingToken (const CAToken_t * token)
         LL_FOREACH (serverObsList, out)
         {
             OC_LOG(INFO, TAG,PCF("comparing tokens"));
-            OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)token, CA_MAX_TOKEN_LEN);
-            OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)out->token, CA_MAX_TOKEN_LEN);
+            OC_LOG_BUFFER(INFO, TAG, (const unsigned char *)token, CA_MAX_TOKEN_LEN);
+            OC_LOG_BUFFER(INFO, TAG, (const unsigned char *)out->token, CA_MAX_TOKEN_LEN);
             if((memcmp(out->token, *token, CA_MAX_TOKEN_LEN) == 0))
             {
                 return out;
@@ -386,7 +386,7 @@ OCStackResult DeleteObserverUsingToken (CAToken_t * token)
     if (obsNode)
     {
         OC_LOG_V(INFO, TAG, PCF("deleting tokens"));
-        OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)obsNode->token, CA_MAX_TOKEN_LEN);
+        OC_LOG_BUFFER(INFO, TAG, (const unsigned char *)obsNode->token, CA_MAX_TOKEN_LEN);
         LL_DELETE (serverObsList, obsNode);
         OCFree(obsNode->resUri);
         OCFree(obsNode->query);
index 43cf963..75544c5 100644 (file)
@@ -40,8 +40,8 @@ OCServerRequest * GetServerRequestUsingToken (const CAToken_t token)
     LL_FOREACH (serverRequestList, out)
     {
         OC_LOG(INFO, TAG,PCF("comparing tokens"));
-        OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)token, CA_MAX_TOKEN_LEN);
-        OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)out->requestToken, CA_MAX_TOKEN_LEN);
+        OC_LOG_BUFFER(INFO, TAG, (const unsigned char *)token, CA_MAX_TOKEN_LEN);
+        OC_LOG_BUFFER(INFO, TAG, (const unsigned char *)out->requestToken, CA_MAX_TOKEN_LEN);
         if(memcmp(out->requestToken, token, CA_MAX_TOKEN_LEN) == 0)
         {
             return out;
@@ -279,10 +279,10 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse)
     OCServerRequest *serverRequest = (OCServerRequest *)ehResponse->requestHandle;
 
     // Copy the address
-    responseEndpoint.resourceUri      = (CAURI_t)serverRequest->resourceUrl;
+    responseEndpoint.resourceUri      = (CAURI_t) serverRequest->resourceUrl;
     responseEndpoint.addressInfo      = serverRequest->addressInfo;
     responseEndpoint.connectivityType = serverRequest->connectivityType;
-    responseEndpoint.isSecured        = serverRequest->secured;
+    responseEndpoint.isSecured        = (CABool_t) serverRequest->secured;
 
     // Copy the info
     switch (ehResponse->ehResult)
index 1ca8301..d3e9a74 100644 (file)
 
 #include "cacommon.h"
 #include "cainterface.h"
-#include <arpa/inet.h>
 
+#ifndef ARDUINO
+#include <arpa/inet.h>
+#endif
 
 //-----------------------------------------------------------------------------
 // Typedefs
@@ -237,7 +239,7 @@ OCStackResult OCToCAConnectivityType(OCConnectivityType ocConType, CAConnectivit
         case OC_ALL:
             // Currently OC_ALL represents WIFI and ETHERNET
             // Add other connectivity types as they are enabled in future
-            *caConType = (CA_WIFI|CA_ETHERNET);
+            *caConType = (CAConnectivityType_t) (CA_WIFI|CA_ETHERNET);
             break;
         default:
             ret = OC_STACK_INVALID_PARAM;
@@ -274,18 +276,48 @@ OCStackResult CAToOCConnectivityType(CAConnectivityType_t caConType, OCConnectiv
 // update response.addr appropriately from endPoint.addressInfo
 OCStackResult UpdateResponseAddr(OCClientResponse *response, const CARemoteEndpoint_t* endPoint)
 {
-    struct sockaddr_in sa;
-    OCStackResult ret = OC_STACK_INVALID_PARAM;
+    OCStackResult ret = OC_STACK_ERROR;
+    static OCDevAddr address = {0};
+    char * tok = NULL;
+    char * cpAddress = (char *) OCMalloc(strlen(endPoint->addressInfo.IP.ipAddress) + 1);
+    if(!cpAddress)
+    {
+        ret = OC_STACK_NO_MEMORY;
+        goto exit;
+    }
+    memcpy(cpAddress, endPoint->addressInfo.IP.ipAddress,
+            strlen(endPoint->addressInfo.IP.ipAddress) + 1);
 
-    if (!endPoint)
+    // Grabs the first three numbers from the IPv4 address and replaces dots
+    for(int i=0; i<3; i++)
     {
-        OC_LOG(ERROR, TAG, PCF("CA Remote end-point is NULL!"));
-        return ret;
+        if(i==0)
+        {
+            tok = strtok(cpAddress, ".");
+        }
+        else
+        {
+            tok = strtok(NULL, ".");
+        }
+        if(!tok)
+        {
+            ret = OC_STACK_ERROR;
+            goto exit;
+        }
+        address.addr[i] = atoi(tok);
+        cpAddress[strlen(cpAddress)]='.'; // Replaces the dot here.
     }
-    inet_pton(AF_INET, endPoint->addressInfo.IP.ipAddress, &(sa.sin_addr));
-    sa.sin_port = htons(endPoint->addressInfo.IP.port);
-    static OCDevAddr address;
-    memcpy((void*)&address.addr, &(sa), sizeof(sa));
+
+    // Grabs the last number from the IPv4 address - has no dot to replace
+    tok = strtok(NULL, ".");
+    if(!tok)
+    {
+        ret = OC_STACK_ERROR;
+        goto exit;
+    }
+    address.addr[3] = atoi(tok);
+    memcpy(&address.addr[4], &endPoint->addressInfo.IP.port, sizeof(uint32_t));
+
     if(response)
     {
         response->addr = &address;
@@ -295,6 +327,8 @@ OCStackResult UpdateResponseAddr(OCClientResponse *response, const CARemoteEndpo
     {
         OC_LOG(ERROR, TAG, PCF("OCClientResponse is NULL!"));
     }
+exit:
+    OCFree(cpAddress);
     return ret;
 }
 
@@ -377,7 +411,7 @@ OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
     snprintf(fullUri, MAX_URI_LENGTH, "coap://%s:%u%s", ipAddress, endPoint->addressInfo.IP.port,
                 OC_PRESENCE_URI);
 
-    cbNode = GetClientCB(NULL, NULL, (unsigned char *)fullUri);
+    cbNode = GetClientCB(NULL, NULL, (unsigned char *) fullUri);
 
     if(cbNode)
     {
@@ -386,7 +420,7 @@ OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
     else
     {
         snprintf(fullUri, MAX_URI_LENGTH, "%s%s", OC_MULTICAST_IP, endPoint->resourceUri);
-        cbNode = GetClientCB(NULL, NULL, (unsigned char *)fullUri);
+        cbNode = GetClientCB(NULL, NULL, (unsigned char *) fullUri);
         if(cbNode)
         {
             multicastPresenceSubscribe = 1;
@@ -404,7 +438,11 @@ OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint,
     response.resJSONPayload = NULL;
     response.result = OC_STACK_OK;
 
-    UpdateResponseAddr(&response, endPoint);
+    result = UpdateResponseAddr(&response, endPoint);
+    if(result != OC_STACK_OK)
+    {
+        goto exit;
+    }
 
     if(responseInfo->info.payload)
     {
@@ -544,6 +582,8 @@ void HandleCAResponses(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_
 {
     OC_LOG(INFO, TAG, PCF("Enter HandleCAResponses"));
 
+    OCStackApplicationResult appResult = OC_STACK_DELETE_TRANSACTION;
+
     if(NULL == endPoint)
     {
         OC_LOG(ERROR, TAG, PCF("endPoint is NULL"));
@@ -562,7 +602,7 @@ void HandleCAResponses(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_
         return;
     }
 
-    ClientCB *cbNode = GetClientCB(&(responseInfo->info.token), NULL, NULL);
+    ClientCB *cbNode = GetClientCB((CAToken_t *)&(responseInfo->info.token), NULL, NULL);
 
     if (cbNode)
     {
@@ -607,8 +647,9 @@ void HandleCAResponses(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_
                  &(responseInfo->info.options[i]), sizeof(OCHeaderOption));
             }
         }
-        if (cbNode->callBack(cbNode->context,
-                cbNode->handle, &response) == OC_STACK_DELETE_TRANSACTION)
+        appResult = cbNode->callBack(cbNode->context,
+                cbNode->handle, &response);
+        if (appResult == OC_STACK_DELETE_TRANSACTION)
         {
             FindAndDeleteClientCB(cbNode);
         }
@@ -633,6 +674,8 @@ void HandleCARequests(const CARemoteEndpoint_t* endPoint, const CARequestInfo_t*
         return;
     }
 
+    OCStackResult requestResult = OC_STACK_ERROR;
+
     if(myStackMode == OC_CLIENT)
     {
         //TODO: should the client be responding to requests?
@@ -699,7 +742,7 @@ void HandleCARequests(const CARemoteEndpoint_t* endPoint, const CARequestInfo_t*
     }
 
     OC_LOG_V(INFO, TAG, "HandleCARequests: CA token length = %d", CA_MAX_TOKEN_LEN);
-    OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)requestInfo->info.token, CA_MAX_TOKEN_LEN);
+    OC_LOG_BUFFER(INFO, TAG, (const unsigned char *)requestInfo->info.token, CA_MAX_TOKEN_LEN);
 
     serverRequest.requestToken = (CAToken_t)OCMalloc(CA_MAX_TOKEN_LEN+1);
     // Module Name
@@ -739,23 +782,23 @@ void HandleCARequests(const CARemoteEndpoint_t* endPoint, const CARequestInfo_t*
     // copy vendor specific header options
     // TODO-CA: CA is including non-vendor header options as well, like observe.
     // Need to filter those out
-    GetObserveHeaderOption(&serverRequest.observationOption,
-            requestInfo->info.options, (uint8_t *)&(requestInfo->info.numOptions));
+    uint8_t tempNum = (requestInfo->info.numOptions);
+    GetObserveHeaderOption(&serverRequest.observationOption, requestInfo->info.options, &tempNum);
     if (requestInfo->info.numOptions > MAX_HEADER_OPTIONS)
     {
         OC_LOG(ERROR, TAG,
                 PCF("The request info numOptions is greater than MAX_HEADER_OPTIONS"));
         return;
     }
-    serverRequest.numRcvdVendorSpecificHeaderOptions = requestInfo->info.numOptions;
+    serverRequest.numRcvdVendorSpecificHeaderOptions = tempNum;
     if (serverRequest.numRcvdVendorSpecificHeaderOptions)
     {
         memcpy (&(serverRequest.rcvdVendorSpecificHeaderOptions), requestInfo->info.options,
-            sizeof(CAHeaderOption_t)*requestInfo->info.numOptions);
+            sizeof(CAHeaderOption_t)*tempNum);
     }
 
-
-    if(HandleStackRequests (&serverRequest) != OC_STACK_OK)
+    requestResult = HandleStackRequests (&serverRequest);
+    if(requestResult != OC_STACK_OK)
     {
         OC_LOG(ERROR, TAG, PCF("HandleStackRequests failed"));
     }
@@ -1222,7 +1265,11 @@ OCStackResult OCInit(const char *ipAddr, uint16_t port, OCMode mode)
     OCSeedRandom();
     CAInitialize();
     //It is ok to select network to CA_WIFI for now
+#ifdef WITH_ARDUINO
+    CAResult_t caResult = CASelectNetwork(CA_ETHERNET);
+#else
     CAResult_t caResult = CASelectNetwork(CA_WIFI|CA_ETHERNET);
+#endif
     if(caResult == CA_STATUS_OK)
     {
         OC_LOG(INFO, TAG, PCF("CASelectNetwork to WIFI"));
@@ -1593,7 +1640,6 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
     }
 
     // create token
-
     caResult = CAGenerateToken(&token);
     if (caResult != CA_STATUS_OK)
     {
@@ -1626,7 +1672,7 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
 
     CAConnectivityType_t caConType;
 
-    result = OCToCAConnectivityType(conType, &caConType);
+    result = OCToCAConnectivityType((OCConnectivityType) conType, &caConType);
     if (result != OC_STACK_OK)
     {
         OC_LOG(ERROR, TAG, PCF("Invalid Connectivity Type"));
@@ -1639,6 +1685,11 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
         grpEnd.connectivityType = caConType;
 
         grpEnd.resourceUri = (CAURI_t) OCMalloc(uriLen + 1);
+        if(!grpEnd.resourceUri)
+        {
+            result = OC_STACK_NO_MEMORY;
+            goto exit;
+        }
         strncpy(grpEnd.resourceUri, requiredUri, (uriLen + 1));
 
         caResult = CASendRequestToAll(&grpEnd, &requestInfo);