#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)
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
$(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) $@
]
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',
]
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
/* 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);
{
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)
{
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
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 */
{
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)
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
{
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;
* 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)
# 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
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
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
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
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)
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
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)
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)
-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
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
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;
}
/// 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;
}
])
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')
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')
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
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) $@
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
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)
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;
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;
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);
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;
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)
#include "cacommon.h"
#include "cainterface.h"
-#include <arpa/inet.h>
+#ifndef ARDUINO
+#include <arpa/inet.h>
+#endif
//-----------------------------------------------------------------------------
// Typedefs
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;
// 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;
{
OC_LOG(ERROR, TAG, PCF("OCClientResponse is NULL!"));
}
+exit:
+ OCFree(cpAddress);
return ret;
}
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)
{
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;
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)
{
{
OC_LOG(INFO, TAG, PCF("Enter HandleCAResponses"));
+ OCStackApplicationResult appResult = OC_STACK_DELETE_TRANSACTION;
+
if(NULL == endPoint)
{
OC_LOG(ERROR, TAG, PCF("endPoint is NULL"));
return;
}
- ClientCB *cbNode = GetClientCB(&(responseInfo->info.token), NULL, NULL);
+ ClientCB *cbNode = GetClientCB((CAToken_t *)&(responseInfo->info.token), NULL, NULL);
if (cbNode)
{
&(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);
}
return;
}
+ OCStackResult requestResult = OC_STACK_ERROR;
+
if(myStackMode == OC_CLIENT)
{
//TODO: should the client be responding to requests?
}
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
// 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"));
}
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"));
}
// create token
-
caResult = CAGenerateToken(&token);
if (caResult != CA_STATUS_OK)
{
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"));
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);