#include "payload_logging.h"
// Tracking user input
-static int UNICAST_DISCOVERY = 0;
-static int TEST_CASE = 0;
-static int CONNECTIVITY = 0;
+static int UnicastDiscovery = 0;
+static int TestCase = 0;
+static int Connectivity = 0;
-static const char * UNICAST_DEVICE_DISCOVERY_QUERY = "coap://%s/oic/d";
-static const char * MULTICAST_DEVICE_DISCOVERY_QUERY = "/oic/d";
-static const char * UNICAST_PLATFORM_DISCOVERY_QUERY = "coap://%s/oic/p";
-static const char * MULTICAST_PLATFORM_DISCOVERY_QUERY = "/oic/p";
+static const char *DEVICE_DISCOVERY_QUERY = "%s/oic/d";
+static const char *PLATFORM_DISCOVERY_QUERY = "%s/oic/p";
+static const char *RESOURCE_DISCOVERY_QUERY = "%s/oic/res";
-static const char * UNICAST_RESOURCE_DISCOVERY_QUERY = "coap://%s/oic/res";
-static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res";
//The following variable determines the interface protocol (IPv4, IPv6, etc)
-//to be used for sending unicast messages. Default set to IPv4.
-static OCConnectivityType OC_CONNTYPE = CT_ADAPTER_IP;
-static std::string coapServerIP = "255.255.255.255";
-static std::string coapServerPort = "5683";
+//to be used for sending unicast messages. Default set to IP dual stack.
+static OCConnectivityType ConnType = CT_ADAPTER_IP;
+static OCDevAddr serverAddr;
+static char discoveryAddr[100];
static std::string coapServerResource = "/a/light";
-// Size to hold IPV4_ADDRESS:PORT
-static const int IPV4_ADDR_SIZE = 24;
-//Use ipv4addr for both InitDiscovery and InitPlatformOrDeviceDiscovery
-char ipv4addr[IPV4_ADDR_SIZE];
+
void StripNewLineChar(char* str);
// The handle for the observe registration
{
OCRepPayload* payload = OCRepPayloadCreate();
- if(!payload)
+ if (!payload)
{
std::cout << "Failed to create put payload object"<<std::endl;
std::exit(1);
}
OCStackResult InvokeOCDoResource(std::ostringstream &query,
+ OCDevAddr *remoteAddr,
OCMethod method,
OCQualityOfService qos,
OCClientResponseHandler cb,
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- ret = OCDoResource(&handle, method, query.str().c_str(), 0,
+ ret = OCDoResource(&handle, method, query.str().c_str(), remoteAddr,
(method == OC_REST_PUT) ? putPayload() : NULL,
- (OC_CONNTYPE), qos, &cbData, options, numOptions);
+ (ConnType), qos, &cbData, options, numOptions);
if (ret != OC_STACK_OK)
{
OCStackApplicationResult putReqCB(void* ctx, OCDoHandle /*handle*/,
OCClientResponse * clientResponse)
{
- if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
+ if (ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for PUT recvd successfully");
}
- if(clientResponse)
+ if (clientResponse)
{
OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
OCStackApplicationResult postReqCB(void *ctx, OCDoHandle /*handle*/,
OCClientResponse *clientResponse)
{
- if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
+ if (ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for POST recvd successfully");
}
- if(clientResponse)
+ if (clientResponse)
{
OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
OCDoHandle /*handle*/,
OCClientResponse *clientResponse)
{
- if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
+ if (ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for DELETE recvd successfully");
}
- if(clientResponse)
+ if (clientResponse)
{
OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
OCStackApplicationResult getReqCB(void* ctx, OCDoHandle /*handle*/,
OCClientResponse * clientResponse)
{
- if(clientResponse == NULL)
+ if (clientResponse == NULL)
{
OC_LOG(INFO, TAG, "getReqCB received NULL clientResponse");
return OC_STACK_DELETE_TRANSACTION;
}
- if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
+ if (ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for GET query recvd successfully");
}
OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
OC_LOG(INFO, TAG, PCF("=============> Get Response"));
- if(clientResponse->numRcvdVendorSpecificHeaderOptions > 0)
+ if (clientResponse->numRcvdVendorSpecificHeaderOptions > 0)
{
OC_LOG (INFO, TAG, "Received vendor specific options");
uint8_t i = 0;
OCHeaderOption * rcvdOptions = clientResponse->rcvdVendorSpecificHeaderOptions;
for( i = 0; i < clientResponse->numRcvdVendorSpecificHeaderOptions; i++)
{
- if(((OCHeaderOption)rcvdOptions[i]).protocolID == OC_COAP_ID)
+ if (((OCHeaderOption)rcvdOptions[i]).protocolID == OC_COAP_ID)
{
OC_LOG_V(INFO, TAG, "Received option with OC_COAP_ID and ID %u with",
((OCHeaderOption)rcvdOptions[i]).optionID );
OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle /*handle*/,
OCClientResponse * clientResponse)
{
- if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
+ if (ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for OBS query recvd successfully");
}
- if(clientResponse)
+ if (clientResponse)
{
OC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
gNumObserveNotifies++;
if (gNumObserveNotifies == 15) //large number to test observing in DELETE case.
{
- if(TEST_CASE == TEST_OBS_REQ_NON || TEST_CASE == TEST_OBS_REQ_CON)
+ if (TestCase == TEST_OBS_REQ_NON || TestCase == TEST_OBS_REQ_CON)
{
if (OCCancel (gObserveDoHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK)
{
}
return OC_STACK_DELETE_TRANSACTION;
}
- else if(TEST_CASE == TEST_OBS_REQ_NON_CANCEL_IMM)
+ else if (TestCase == TEST_OBS_REQ_NON_CANCEL_IMM)
{
if (OCCancel (gObserveDoHandle, OC_HIGH_QOS, NULL, 0) != OC_STACK_OK)
{
}
}
}
- if(clientResponse->sequenceNumber == OC_OBSERVE_REGISTER)
+ if (clientResponse->sequenceNumber == OC_OBSERVE_REGISTER)
{
OC_LOG(INFO, TAG, "This also serves as a registration confirmation");
}
- else if(clientResponse->sequenceNumber == OC_OBSERVE_DEREGISTER)
+ else if (clientResponse->sequenceNumber == OC_OBSERVE_DEREGISTER)
{
OC_LOG(INFO, TAG, "This also serves as a deregistration confirmation");
return OC_STACK_DELETE_TRANSACTION;
}
- else if(clientResponse->sequenceNumber == OC_OBSERVE_NO_OPTION)
+ else if (clientResponse->sequenceNumber == OC_OBSERVE_NO_OPTION)
{
OC_LOG(INFO, TAG, "This also tells you that registration/deregistration failed");
return OC_STACK_DELETE_TRANSACTION;
// This is a function called back when a device is discovered
OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle /*handle*/,
- OCClientResponse * clientResponse)
+ OCClientResponse * clientResponse)
{
if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
{
clientResponse->devAddr.port);
OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
- OC_CONNTYPE = clientResponse->connType;
+ ConnType = clientResponse->connType;
+ serverAddr = clientResponse->devAddr;
parseClientResponse(clientResponse);
- switch(TEST_CASE)
+ switch(TestCase)
{
case TEST_GET_REQ_NON:
InitGetRequest(OC_LOW_QOS, 0, 0);
return OC_STACK_KEEP_TRANSACTION;
}
-OCStackApplicationResult PlatformDiscoveryReqCB (void* ctx,
- OCDoHandle /*handle*/,
- OCClientResponse * clientResponse)
+OCStackApplicationResult PlatformDiscoveryReqCB(void* ctx,
+ OCDoHandle /*handle*/,
+ OCClientResponse * clientResponse)
{
if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for Platform DISCOVER query recvd successfully");
}
- if(clientResponse)
+ if (clientResponse)
{
OC_LOG(INFO, TAG, PCF("Discovery Response:"));
OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
OC_LOG_V(INFO, TAG, "PlatformDiscoveryReqCB received Null clientResponse");
}
- return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION;
+ return (UnicastDiscovery) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION;
}
-OCStackApplicationResult DeviceDiscoveryReqCB (void* ctx, OCDoHandle /*handle*/,
- OCClientResponse * clientResponse)
+OCStackApplicationResult DeviceDiscoveryReqCB(void* ctx, OCDoHandle /*handle*/,
+ OCClientResponse * clientResponse)
{
if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
{
OC_LOG(INFO, TAG, "Callback Context for Device DISCOVER query recvd successfully");
}
- if(clientResponse)
+ if (clientResponse)
{
OC_LOG(INFO, TAG, PCF("Discovery Response:"));
OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
OC_LOG_V(INFO, TAG, "PlatformDiscoveryReqCB received Null clientResponse");
}
- return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION;
+ return (UnicastDiscovery) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION;
}
#ifdef WITH_PRESENCE
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
std::ostringstream querySuffix;
- query << "coap://" << coapServerIP << ":" << coapServerPort << OC_RSRVD_PRESENCE_URI;
- if(TEST_CASE == TEST_OBS_PRESENCE)
+ query << OC_RSRVD_PRESENCE_URI;
+ if (TestCase == TEST_OBS_PRESENCE)
{
- result = InvokeOCDoResource(query, OC_REST_PRESENCE, OC_LOW_QOS,
- presenceCB, NULL, 0);
+ result = InvokeOCDoResource(query, &serverAddr, OC_REST_PRESENCE,
+ OC_LOW_QOS, presenceCB, NULL, 0);
}
- if(TEST_CASE == TEST_OBS_PRESENCE_WITH_FILTER || TEST_CASE == TEST_OBS_PRESENCE_WITH_FILTERS)
+ if (TestCase == TEST_OBS_PRESENCE_WITH_FILTER || TestCase == TEST_OBS_PRESENCE_WITH_FILTERS)
{
querySuffix.str("");
querySuffix << query.str() << "?rt=core.led";
- result = InvokeOCDoResource(querySuffix, OC_REST_PRESENCE, OC_LOW_QOS,
- presenceCB, NULL, 0);
+ result = InvokeOCDoResource(querySuffix, &serverAddr, OC_REST_PRESENCE,
+ OC_LOW_QOS, presenceCB, NULL, 0);
}
- if(TEST_CASE == TEST_OBS_PRESENCE_WITH_FILTERS)
+ if (TestCase == TEST_OBS_PRESENCE_WITH_FILTERS)
{
- if(result == OC_STACK_OK)
+ if (result == OC_STACK_OK)
{
querySuffix.str("");
querySuffix << query.str() << "?rt=core.fan";
- result = InvokeOCDoResource(querySuffix, OC_REST_PRESENCE, OC_LOW_QOS,
+ result = InvokeOCDoResource(querySuffix, &serverAddr, OC_REST_PRESENCE, OC_LOW_QOS,
presenceCB, NULL, 0);
}
}
- if(TEST_CASE == TEST_OBS_MULTICAST_PRESENCE)
+ if (TestCase == TEST_OBS_MULTICAST_PRESENCE)
{
- if(result == OC_STACK_OK)
+ if (result == OC_STACK_OK)
{
std::ostringstream multicastPresenceQuery;
multicastPresenceQuery.str("");
multicastPresenceQuery << "coap://" << OC_MULTICAST_PREFIX << OC_RSRVD_PRESENCE_URI;
- result = InvokeOCDoResource(multicastPresenceQuery, OC_REST_PRESENCE, OC_LOW_QOS,
+ result = InvokeOCDoResource(multicastPresenceQuery, &serverAddr, OC_REST_PRESENCE, OC_LOW_QOS,
presenceCB, NULL, 0);
}
}
{
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
- query << "coap://" << coapServerIP << ":" << coapServerPort << "/SomeUnknownResource";
- return (InvokeOCDoResource(query, OC_REST_GET, (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS,
+ query << "/SomeUnknownResource";
+ return (InvokeOCDoResource(query, &serverAddr, OC_REST_GET, (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS,
getReqCB, NULL, 0));
}
{
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
- query << "coap://" << coapServerIP << ":" << coapServerPort << coapServerResource;
- return (InvokeOCDoResource(query,
- OC_REST_OBSERVE, (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS, obsReqCB, NULL, 0));
+ query << coapServerResource;
+ return (InvokeOCDoResource(query, &serverAddr, OC_REST_OBSERVE,
+ (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS, obsReqCB, NULL, 0));
}
int InitPutRequest(OCQualityOfService qos)
{
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
- query << "coap://" << coapServerIP << ":" << coapServerPort << coapServerResource;
- return (InvokeOCDoResource(query, OC_REST_PUT, (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS,
+ query << coapServerResource;
+ return (InvokeOCDoResource(query, &serverAddr, OC_REST_PUT, (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS,
putReqCB, NULL, 0));
}
OCStackResult result;
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
- query << "coap://" << coapServerIP << ":" << coapServerPort << coapServerResource;
+ query << coapServerResource;
// First POST operation (to create an Light instance)
- result = InvokeOCDoResource(query, OC_REST_POST,
+ result = InvokeOCDoResource(query, &serverAddr, OC_REST_POST,
((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
postReqCB, NULL, 0);
if (OC_STACK_OK != result)
}
// Second POST operation (to create an Light instance)
- result = InvokeOCDoResource(query, OC_REST_POST,
+ result = InvokeOCDoResource(query, &serverAddr, OC_REST_POST,
((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
postReqCB, NULL, 0);
if (OC_STACK_OK != result)
}
// This POST operation will update the original resourced /a/light
- return (InvokeOCDoResource(query, OC_REST_POST,
+ return (InvokeOCDoResource(query, &serverAddr, OC_REST_POST,
((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
postReqCB, NULL, 0));
}
{
sleep (30);//long enough to give the server time to finish deleting the resource.
std::ostringstream query;
- query << "coap://" << coapServerIP << ":" << coapServerPort << coapServerResource;
+ query << coapServerResource;
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
qos = OC_HIGH_QOS;
}
- OCStackResult result = InvokeOCDoResource(query, OC_REST_DELETE,
+ OCStackResult result = InvokeOCDoResource(query, &serverAddr, OC_REST_DELETE,
qos,
deleteReqCB, NULL, 0);
{
OCStackResult result;
std::ostringstream query;
- query << "coap://" << coapServerIP << ":" << coapServerPort << coapServerResource;
+ query << coapServerResource;
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
// First DELETE operation
- result = InvokeOCDoResource(query, OC_REST_DELETE,
+ result = InvokeOCDoResource(query, &serverAddr, OC_REST_DELETE,
qos,
deleteReqCB, NULL, 0);
if (OC_STACK_OK != result)
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
- query << "coap://" << coapServerIP << ":" << coapServerPort << coapServerResource;
+ query << coapServerResource;
// ocserver is written to only process "power<X" query.
if (getWithQuery)
}
if (withVendorSpecificHeaderOptions)
{
- return (InvokeOCDoResource(query, OC_REST_GET,
+ return (InvokeOCDoResource(query, &serverAddr, OC_REST_GET,
(qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, getReqCB, options, 2));
}
else
{
- return (InvokeOCDoResource(query, OC_REST_GET,
+ return (InvokeOCDoResource(query, &serverAddr, OC_REST_GET,
(qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, getReqCB, NULL, 0));
}
}
OCCallbackData cbData;
char szQueryUri[64] = { 0 };
+ snprintf(szQueryUri, sizeof (szQueryUri) - 1, PLATFORM_DISCOVERY_QUERY, discoveryAddr);
+
cbData.cb = PlatformDiscoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- if(UNICAST_DISCOVERY)
- {
- snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PLATFORM_DISCOVERY_QUERY, ipv4addr);
- }
- else
- {
- strncpy(szQueryUri, MULTICAST_PLATFORM_DISCOVERY_QUERY, sizeof(szQueryUri) -1 );
- }
- szQueryUri[sizeof(szQueryUri) -1] = '\0';
-
- if(UNICAST_DISCOVERY)
- {
- ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
- (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0);
- }
- else
- {
-
- ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, OC_CONNTYPE,
- (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0);
- }
-
+ ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT,
+ (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS,
+ &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack device error");
OCStackResult ret;
OCCallbackData cbData;
- char szQueryUri[64] = { 0 };
+ char szQueryUri[100] = { 0 };
+
+ snprintf(szQueryUri, sizeof (szQueryUri) - 1, DEVICE_DISCOVERY_QUERY, discoveryAddr);
cbData.cb = DeviceDiscoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- if(UNICAST_DISCOVERY)
- {
- snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_DEVICE_DISCOVERY_QUERY, ipv4addr);
- }
- else
- {
- strncpy(szQueryUri, MULTICAST_DEVICE_DISCOVERY_QUERY, sizeof(szQueryUri) -1 );
- }
- szQueryUri[sizeof(szQueryUri) -1] = '\0';
-
- if(UNICAST_DISCOVERY)
- {
- ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
- (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0);
- }
- else
- {
- ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, OC_CONNTYPE,
- (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0);
- }
-
+ ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT,
+ (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS,
+ &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack device error");
{
OCStackResult ret;
OCCallbackData cbData;
- /* Start a discovery query*/
- char szQueryUri[64] = { 0 };
+ char szQueryUri[100] = { 0 };
- if (UNICAST_DISCOVERY)
- {
- snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_RESOURCE_DISCOVERY_QUERY, ipv4addr);
- }
- else
- {
- strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY);
- }
+ snprintf(szQueryUri, sizeof (szQueryUri) - 1, RESOURCE_DISCOVERY_QUERY, discoveryAddr);
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- if(UNICAST_DISCOVERY)
- {
- ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
- (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0);
- }
- else
- {
- ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, OC_CONNTYPE,
- (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS, &cbData, NULL, 0);
- }
+
+ ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, CT_DEFAULT,
+ (qos == OC_HIGH_QOS) ? OC_HIGH_QOS : OC_LOW_QOS,
+ &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
switch(opt)
{
case 'u':
- UNICAST_DISCOVERY = atoi(optarg);
+ UnicastDiscovery = atoi(optarg);
break;
case 't':
- TEST_CASE = atoi(optarg);
+ TestCase = atoi(optarg);
break;
case 'c':
- CONNECTIVITY = atoi(optarg);
+ Connectivity = atoi(optarg);
break;
default:
PrintUsage();
}
}
- if ((UNICAST_DISCOVERY != 0 && UNICAST_DISCOVERY != 1) ||
- (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS) ||
- (CONNECTIVITY < CT_ADAPTER_DEFAULT || CONNECTIVITY >= MAX_CT))
+ if ((UnicastDiscovery != 0 && UnicastDiscovery != 1) ||
+ (TestCase < TEST_DISCOVER_REQ || TestCase >= MAX_TESTS) ||
+ (Connectivity < CT_ADAPTER_DEFAULT || Connectivity >= MAX_CT))
{
PrintUsage();
return -1;
}
- /* Initialize OCStack*/
- if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK)
+ if (OCInit1(OC_CLIENT, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack init error");
return 0;
}
- if(CONNECTIVITY == CT_ADAPTER_DEFAULT || CONNECTIVITY == CT_IP)
+ if (Connectivity == CT_ADAPTER_DEFAULT || Connectivity == CT_IP)
{
- OC_CONNTYPE = CT_ADAPTER_IP;
+ ConnType = CT_ADAPTER_IP;
}
else
{
PrintUsage();
}
- if (UNICAST_DISCOVERY)
+ discoveryAddr[0] = '\0';
+
+ if (UnicastDiscovery)
{
- OC_LOG(INFO, TAG, "Enter IP address with port number of the Server hosting resource");
- OC_LOG(INFO, TAG, "as follows - eg: 192.168.0.15:45454 (IP:Port) \n");
+ OC_LOG(INFO, TAG, "Enter IP address of server with optional port number");
+ OC_LOG(INFO, TAG, "IPv4: 192.168.0.15:45454\n");
+ OC_LOG(INFO, TAG, "IPv6: [fe80::20c:29ff:fe1b:9c5]:45454\n");
- if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin))
+ if (fgets(discoveryAddr, sizeof (discoveryAddr), stdin))
{
//Strip newline char from ipv4addr
- StripNewLineChar(ipv4addr);
+ StripNewLineChar(discoveryAddr);
}
else
{
- OC_LOG(ERROR, TAG, "!! Bad input for IPV4 address. !!");
+ OC_LOG(ERROR, TAG, "!! Bad input for IP address. !!");
return OC_STACK_INVALID_PARAM;
}
}
- if(UNICAST_DISCOVERY == 0 && TEST_CASE == TEST_DISCOVER_DEV_REQ)
+ if (UnicastDiscovery == 0 && TestCase == TEST_DISCOVER_DEV_REQ)
{
InitDeviceDiscovery(OC_LOW_QOS);
}
- else if(UNICAST_DISCOVERY == 0 && TEST_CASE == TEST_DISCOVER_PLATFORM_REQ)
+ else if (UnicastDiscovery == 0 && TestCase == TEST_DISCOVER_PLATFORM_REQ)
{
InitPlatformDiscovery(OC_LOW_QOS);
}
return 0;
}
-std::string getIPAddrTBServer(OCClientResponse * clientResponse)
-{
- if (!clientResponse)
- {
- return "";
- }
- if (!clientResponse->addr)
- {
- return "";
- }
-
- return std::string(clientResponse->devAddr.addr);
-}
-
-std::string getPortTBServer(OCClientResponse * clientResponse)
-{
- if (!clientResponse)
- {
- return "";
- }
- if (!clientResponse->addr)
- {
- return "";
- }
- std::ostringstream ss;
- ss << clientResponse->devAddr.port;
- return ss.str();
-}
-
std::string getConnectivityType (OCConnectivityType connType)
{
switch (connType & CT_MASK_ADAPTER)
std::string getQueryStrForGetPut(OCClientResponse * /*clientResponse*/)
{
-
return "/a/light";
}
void parseClientResponse(OCClientResponse * clientResponse)
{
- coapServerIP = getIPAddrTBServer(clientResponse);
- coapServerPort = getPortTBServer(clientResponse);
coapServerResource = getQueryStrForGetPut(clientResponse);
}
#define MAX_IP_ADDR_ST_SZ 16 //string size of "155.255.255.255" (15 + 1)
#define MAX_PORT_ST_SZ 6 //string size of "65535" (5 + 1)
-static int IPV4_ADDR_SIZE = 24;
-static int UNICAST_DISCOVERY = 0;
-static int TEST_CASE = 0;
-static int CONNECTIVITY = 0;
-
-static const char UNICAST_DISCOVERY_QUERY[] = "coap://%s/oic/res";
+static int UnicastDiscovery = 0;
+static int TestCase = 0;
+static int Connectivity = 0;
//The following variable determines the interface protocol (IP, etc)
//to be used for sending unicast messages. Default set to IP.
-static OCConnectivityType OC_CONNTYPE = CT_ADAPTER_IP;
-static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res";
+static OCConnectivityType ConnType = CT_ADAPTER_IP;
+static const char *RESOURCE_DISCOVERY_QUERY = "%s/oic/res";
int gQuitFlag = 0;
return resourceList;
}
-OCStackResult InvokeOCDoResource(std::ostringstream &query, OCMethod method,
- OCConnectivityType connType, OCQualityOfService qos,
- OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions)
+OCStackResult InvokeOCDoResource(std::ostringstream &query,
+ OCMethod method,
+ const OCDevAddr *dest,
+ OCQualityOfService qos,
+ OCClientResponseHandler cb,
+ OCHeaderOption * options, uint8_t numOptions)
{
OCStackResult ret;
OCCallbackData cbData;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- ret = OCDoResource(NULL, method, query.str().c_str(), 0,
+ ret = OCDoResource(NULL, method, query.str().c_str(), dest,
(method == OC_REST_PUT || method == OC_REST_POST) ? putPayload() : NULL,
- connType, qos, &cbData, options, numOptions);
+ CT_DEFAULT, qos, &cbData, options, numOptions);
if (ret != OC_STACK_OK)
{
}
OCStackApplicationResult putReqCB(void* ctx, OCDoHandle /*handle*/,
- OCClientResponse * clientResponse)
+ OCClientResponse * clientResponse)
{
if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
}
OCStackApplicationResult postReqCB(void *ctx, OCDoHandle /*handle*/,
- OCClientResponse *clientResponse)
+ OCClientResponse *clientResponse)
{
if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
}
OCStackApplicationResult getReqCB(void* ctx, OCDoHandle /*handle*/,
- OCClientResponse * clientResponse)
+ OCClientResponse * clientResponse)
{
if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
{
* This is a function called back when a device is discovered
*/
OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle /*handle*/,
- OCClientResponse * clientResponse)
+ OCClientResponse * clientResponse)
{
if (ctx == (void*)DEFAULT_CONTEXT_VALUE)
{
{
OC_LOG(ERROR, TAG, "<====DISCOVERY Callback fail to receive clientResponse====>\n");
}
- return (UNICAST_DISCOVERY) ?
+ return (UnicastDiscovery) ?
OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION ;
}
OC_LOG_V(ERROR, TAG, "Resource null, can't do PUT request\n");
return -1;
}
- query << "coap://" << resource->ip << ":" << resource->port << resource->uri ;
+ query << resource->uri;
OC_LOG_V(INFO, TAG,"Executing InitPutRequest, Query: %s", query.str().c_str());
- return (InvokeOCDoResource(query, OC_REST_PUT, resource->connType,
+ return (InvokeOCDoResource(query, OC_REST_PUT, &resource->endpoint,
((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
putReqCB, NULL, 0));
}
OCStackResult result;
std::ostringstream query;
//Get most recently inserted resource
- const ResourceNode * resource = getResource();
+ const ResourceNode *resource = getResource();
if(!resource)
{
return -1;
}
- query << "coap://" << resource->ip << ":" << resource->port << resource->uri ;
+ query << resource->uri;
OC_LOG_V(INFO, TAG,"Executing InitPostRequest, Query: %s", query.str().c_str());
// First POST operation (to create an LED instance)
- result = InvokeOCDoResource(query, OC_REST_POST, resource->connType,
+ result = InvokeOCDoResource(query, OC_REST_POST, &resource->endpoint,
((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
postReqCB, NULL, 0);
if (OC_STACK_OK != result)
}
// Second POST operation (to create an LED instance)
- result = InvokeOCDoResource(query, OC_REST_POST, resource->connType,
+ result = InvokeOCDoResource(query, OC_REST_POST, &resource->endpoint,
((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
postReqCB, NULL, 0);
if (OC_STACK_OK != result)
}
// This POST operation will update the original resourced /a/led
- return (InvokeOCDoResource(query, OC_REST_POST,resource->connType,
+ return (InvokeOCDoResource(query, OC_REST_POST, &resource->endpoint,
((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
postReqCB, NULL, 0));
}
OC_LOG_V(ERROR, TAG, "Resource null, can't do GET request\n");
return -1;
}
- query << "coap://" << resource->ip << ":" << resource->port << resource->uri ;
+ query << resource->uri;
OC_LOG_V(INFO, TAG,"Executing InitGetRequest, Query: %s", query.str().c_str());
- return (InvokeOCDoResource(query, OC_REST_GET, resource->connType,
+ return (InvokeOCDoResource(query, OC_REST_GET, &resource->endpoint,
(qos == OC_HIGH_QOS)?OC_HIGH_QOS:OC_LOW_QOS, getReqCB, NULL, 0));
}
{
OCStackResult ret;
OCCallbackData cbData;
- /* Start a discovery query*/
- char szQueryUri[64] = {};
- if (UNICAST_DISCOVERY)
+ char queryUri[200];
+ char ipaddr[100] = { '\0' };
+
+ if (UnicastDiscovery)
{
- char ipv4addr[IPV4_ADDR_SIZE];
- OC_LOG(INFO, TAG, "Enter IP address with port of the Server hosting resource"\
- "(Ex: 192.168.0.15:1234) ");
+ OC_LOG(INFO, TAG, "Enter IP address (with optional port) of the Server hosting resource\n");
+ OC_LOG(INFO, TAG, "IPv4: 192.168.0.15:45454\n");
+ OC_LOG(INFO, TAG, "IPv6: [fe80::20c:29ff:fe1b:9c5]:45454\n");
- if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin))
+ if (fgets(ipaddr, sizeof (ipaddr), stdin))
{
- //Strip newline char from ipv4addr
- StripNewLineChar(ipv4addr);
- snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_DISCOVERY_QUERY, ipv4addr);
+ StripNewLineChar(ipaddr); //Strip newline char from ipaddr
}
else
{
- OC_LOG(ERROR, TAG, "!! Bad input for IPV4 address. !!");
+ OC_LOG(ERROR, TAG, "!! Bad input for IP address. !!");
return OC_STACK_INVALID_PARAM;
}
}
- else
- {
- OICStrcpy(szQueryUri, sizeof(szQueryUri), MULTICAST_RESOURCE_DISCOVERY_QUERY);
- }
+
+ snprintf(queryUri, sizeof (queryUri), RESOURCE_DISCOVERY_QUERY, ipaddr);
+
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- if (UNICAST_DISCOVERY)
- {
- ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
- OC_LOW_QOS, &cbData, NULL, 0);
- }
- else
- {
- ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT,
- OC_LOW_QOS, &cbData, NULL, 0);
- }
+ ret = OCDoResource(NULL, OC_REST_DISCOVER, queryUri, 0, 0, CT_DEFAULT,
+ OC_LOW_QOS, &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
return ret;
}
-const char *getIPAddr(const OCClientResponse *clientResponse)
-{
- if (!clientResponse)
- {
- return "";
- }
-
- const OCDevAddr *devAddr = &clientResponse->devAddr;
- char *ipaddr = (char *) OICCalloc(1, strlen(devAddr->addr) +1);
- if (ipaddr)
- {
- snprintf(ipaddr, MAX_IP_ADDR_ST_SZ, "%s", devAddr->addr);
- }
- else
- {
- OC_LOG(ERROR, TAG, "Memory not allocated to ipaddr");
- }
- return ipaddr;
-}
-
-const char *getPort(const OCClientResponse *clientResponse)
-{
- if(!clientResponse)
- {
- return "";
- }
-
- char *port = NULL;
- if((port = (char *)OICCalloc(1, MAX_PORT_ST_SZ)))
- {
- snprintf(port, MAX_PORT_ST_SZ, "%d", clientResponse->devAddr.port);
- }
- else
- {
- OC_LOG(ERROR, TAG, "Memory not allocated to port");
- }
- return port;
-}
-
void queryResource()
{
- switch(TEST_CASE)
+ switch(TestCase)
{
case TEST_DISCOVER_REQ:
break;
{
iter->sid = sid_cpy;
iter->uri = uri_cpy;
- iter->ip = getIPAddr(clientResponse);
- iter->port = getPort(clientResponse);
- iter->connType = clientResponse->connType;
+ iter->endpoint = clientResponse->devAddr;
iter->next = NULL;
}
else
OC_LOG(INFO, TAG, "*****************************************************");
OC_LOG_V(INFO, TAG, "sid = %s",iter->sid);
OC_LOG_V(INFO, TAG, "uri = %s", iter->uri);
- OC_LOG_V(INFO, TAG, "ip = %s", iter->ip);
- OC_LOG_V(INFO, TAG, "port = %s", iter->port);
- switch (iter->connType & CT_MASK_ADAPTER)
+ OC_LOG_V(INFO, TAG, "ip = %s", iter->endpoint.addr);
+ OC_LOG_V(INFO, TAG, "port = %d", iter->endpoint.port);
+ switch (iter->endpoint.adapter)
{
case OC_ADAPTER_IP:
OC_LOG(INFO, TAG, "connType = Default (IPv4)");
resourceList = resourceList->next;
OICFree((void *)temp->sid);
OICFree((void *)temp->uri);
- OICFree((void *)temp->ip);
- OICFree((void *)temp->port);
OICFree(temp);
}
resourceList = NULL;
switch(opt)
{
case 'u':
- UNICAST_DISCOVERY = atoi(optarg);
+ UnicastDiscovery = atoi(optarg);
break;
case 't':
- TEST_CASE = atoi(optarg);
+ TestCase = atoi(optarg);
break;
case 'c':
-
- CONNECTIVITY = atoi(optarg);
+ Connectivity = atoi(optarg);
break;
default:
PrintUsage();
}
}
- if ((UNICAST_DISCOVERY != 0 && UNICAST_DISCOVERY != 1) ||
- (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS) ||
- (CONNECTIVITY < CT_ADAPTER_DEFAULT || CONNECTIVITY >= MAX_CT))
+ if ((UnicastDiscovery != 0 && UnicastDiscovery != 1) ||
+ (TestCase < TEST_DISCOVER_REQ || TestCase >= MAX_TESTS) ||
+ (Connectivity < CT_ADAPTER_DEFAULT || Connectivity >= MAX_CT))
{
PrintUsage();
return -1;
}
/* Initialize OCStack*/
- if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK)
+ if (OCInit1(OC_CLIENT, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack init error");
return 0;
}
- if(CONNECTIVITY == CT_ADAPTER_DEFAULT || CONNECTIVITY == CT_IP)
+ if(Connectivity == CT_ADAPTER_DEFAULT || Connectivity == CT_IP)
{
- OC_CONNTYPE = CT_ADAPTER_IP;//CT_DEFAULT;
+ ConnType = CT_ADAPTER_IP;//CT_DEFAULT;
}
else
{
//-----------------------------------------------------------------------------
#define TAG "occlientbasicops"
#define DEFAULT_CONTEXT_VALUE 0x99
-#ifndef MAX_LENGTH_IPv4_ADDR
-#define MAX_LENGTH_IPv4_ADDR 16
-#endif
//-----------------------------------------------------------------------------
// Typedefs
{
const char * sid;
const char * uri;
- const char * ip;
- const char * port;
- OCConnectivityType connType;
+ OCDevAddr endpoint;
ResourceNode * next;
};
/* call getResult in common.cpp to get the result in string format. */
const char *getResult(OCStackResult result);
-/* Get the IP address of the server */
-const char * getIPAddr(const OCClientResponse * clientResponse);
-
-/* Get the port number the server is listening on */
-const char * getPort(const OCClientResponse * clientResponse);
-
/* Performs GET/PUT/POST query on most recently discovered resource*/
void queryResource();
* to the lower layers
*/
OCStackResult InvokeOCDoResource(std::ostringstream &query,
- OCMethod method, OCQualityOfService qos,
+ OCMethod method, OCDevAddr *dest, OCQualityOfService qos,
OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions);
/*
#include "payload_logging.h"
#include "logger.h"
const char *getResult(OCStackResult result);
-std::string getIPAddrTBServer(OCClientResponse * clientResponse);
-std::string getPortTBServer(OCClientResponse * clientResponse);
std::string getQueryStrForGetPut();
#define TAG PCF("occlient")
CT_ADAPTER_DEFAULT = 0,
CT_IP,
MAX_CT
-} CLIENT_CONNECTIVITY_TYPE;
+} CLIENT_ConnectivityType_TYPE;
-unsigned static int TEST = TEST_INVALID;
-unsigned static int CONNECTIVITY = 0;
+unsigned static int TestType = TEST_INVALID;
+unsigned static int ConnectivityType = 0;
typedef struct
{
//The following variable determines the interface protocol (IP, etc)
//to be used for sending unicast messages. Default set to IP.
-static OCConnectivityType OC_CONNTYPE = CT_ADAPTER_IP;
-static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res";
+static OCConnectivityType ConnType = CT_ADAPTER_IP;
+static const char * RESOURCE_DISCOVERY_QUERY = "/oic/res";
// The handle for the observe registration
OCDoHandle gObserveDoHandle;
}
}
}
- if(TEST == TEST_PUT_DEFAULT || TEST == TEST_PUT_BATCH || TEST == TEST_PUT_LINK_LIST)
+ if(TestType == TEST_PUT_DEFAULT || TestType == TEST_PUT_BATCH || TestType == TEST_PUT_LINK_LIST)
{
InitPutRequest(clientResponse);
}
return OC_STACK_KEEP_TRANSACTION;
}
-
// This is a function called back when a device is discovered
OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle /*handle*/,
- OCClientResponse * clientResponse)
+ OCClientResponse * clientResponse)
{
OC_LOG(INFO, TAG,
"Entering discoveryReqCB (Application Layer CB)");
clientResponse->devAddr.port);
OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
- OC_CONNTYPE = clientResponse->connType;
+ ConnType = clientResponse->connType;
- if(TEST == TEST_UNKNOWN_RESOURCE_GET_DEFAULT || TEST == TEST_UNKNOWN_RESOURCE_GET_BATCH ||\
- TEST == TEST_UNKNOWN_RESOURCE_GET_LINK_LIST)
+ if(TestType == TEST_UNKNOWN_RESOURCE_GET_DEFAULT || TestType == TEST_UNKNOWN_RESOURCE_GET_BATCH ||\
+ TestType == TEST_UNKNOWN_RESOURCE_GET_LINK_LIST)
{
InitGetRequestToUnavailableResource(clientResponse);
}
OCStackResult ret;
OCCallbackData cbData;
std::ostringstream getQuery;
- getQuery << "coap://" << clientResponse->devAddr.addr << ":" <<
- clientResponse->devAddr.port << "/SomeUnknownResource";
+ getQuery << "/SomeUnknownResource";
cbData.cb = getReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- ret = OCDoResource(NULL, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_CONNTYPE, OC_LOW_QOS,
- &cbData, NULL, 0);
+ ret = OCDoResource(NULL, OC_REST_GET, getQuery.str().c_str(),
+ &clientResponse->devAddr, 0, ConnType, OC_LOW_QOS,
+ &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
OCCallbackData cbData;
OCDoHandle handle;
std::ostringstream obsReg;
- obsReg << "coap://" << clientResponse->devAddr.addr << ":" <<
- clientResponse->devAddr.addr <<
- getQueryStrForGetPut();
+ obsReg << getQueryStrForGetPut();
cbData.cb = getReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
OC_LOG_PAYLOAD(INFO, TAG, payload);
OCPayloadDestroy(payload);
- ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_CONNTYPE,
- OC_LOW_QOS, &cbData, NULL, 0);
+ ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(),
+ &clientResponse->devAddr, 0, ConnType,
+ OC_LOW_QOS, &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
std::ostringstream getQuery;
getQuery << "coap://" << clientResponse->devAddr.addr << ":" <<
clientResponse->devAddr.port <<
- "/a/room" << queryInterface[TEST].text;
+ "/a/room" << queryInterface[TestType].text;
cbData.cb = putReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
OC_LOG_PAYLOAD(INFO, TAG, payload);
OCPayloadDestroy(payload);
- ret = OCDoResource(NULL, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload(),
- OC_CONNTYPE, OC_LOW_QOS, &cbData, NULL, 0);
+ ret = OCDoResource(NULL, OC_REST_PUT, getQuery.str().c_str(),
+ &clientResponse->devAddr, putPayload(), ConnType,
+ OC_LOW_QOS, &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
//* Make a GET query*/
std::ostringstream getQuery;
- getQuery << "coap://" << clientResponse->devAddr.addr << ":" <<
- clientResponse->devAddr.port <<
- "/a/room" << queryInterface[TEST].text;
+ getQuery << "/a/room" << queryInterface[TestType].text;
std::cout << "Get Query: " << getQuery.str() << std::endl;
cbData.cb = getReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- ret = OCDoResource(NULL, OC_REST_GET,
- getQuery.str().c_str(), 0, 0, OC_CONNTYPE, OC_LOW_QOS,
- &cbData, NULL, 0);
+ ret = OCDoResource(NULL, OC_REST_GET, getQuery.str().c_str(),
+ &clientResponse->devAddr, 0, ConnType, OC_LOW_QOS,
+ &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
/* Start a discovery query*/
char szQueryUri[64] = { 0 };
- strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY);
+ strcpy(szQueryUri, RESOURCE_DISCOVERY_QUERY);
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, OC_CONNTYPE,
+ ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, NULL, 0, ConnType,
OC_LOW_QOS,
&cbData, NULL, 0);
if (ret != OC_STACK_OK)
switch (opt)
{
case 't':
- TEST = atoi(optarg);
+ TestType = atoi(optarg);
break;
case 'c':
- CONNECTIVITY = atoi(optarg);
+ ConnectivityType = atoi(optarg);
break;
default:
PrintUsage();
return -1;
}
}
- if ((TEST <= TEST_INVALID || TEST >= MAX_TESTS) ||
- CONNECTIVITY >= MAX_CT)
+ if ((TestType <= TEST_INVALID || TestType >= MAX_TESTS) ||
+ ConnectivityType >= MAX_CT)
{
PrintUsage();
return -1;
return 0;
}
- if(CONNECTIVITY == CT_ADAPTER_DEFAULT || CONNECTIVITY == CT_IP)
+ if(ConnectivityType == CT_ADAPTER_DEFAULT || ConnectivityType == CT_IP)
{
- OC_CONNTYPE = CT_ADAPTER_IP;
+ ConnType = CT_ADAPTER_IP;
}
else
{
OC_LOG(INFO, TAG, "Default Connectivity type selected...");
- OC_CONNTYPE = CT_ADAPTER_IP;
+ ConnType = CT_ADAPTER_IP;
}
InitDiscovery();
#include "payload_logging.h"
// Tracking user input
-static int UNICAST_DISCOVERY = 0;
-static int TEST_CASE = 0;
-static int CONNECTIVITY = 0;
+static int UnicastDiscovery = 0;
+static int TestCase = 0;
+static int ConnectivityType = 0;
-static const char * UNICAST_DISCOVERY_QUERY = "coap://%s/oic/res";
-static std::string coapServerIP = "255.255.255.255";
-static uint16_t coapServerPort = 5683;
static std::string coapServerResource = "/a/led";
//The following variable determines the interface protocol (IP, etc)
//to be used for sending unicast messages. Default set to IP.
-static OCConnectivityType OC_CONNTYPE = CT_ADAPTER_IP;
-static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oic/res";
-static int IPV4_ADDR_SIZE = 24;
+static OCConnectivityType AdapterType = CT_ADAPTER_IP;
+static OCDevAddr endpoint;
+static const char *RESOURCE_DISCOVERY_QUERY = "%s/oic/res";
void StripNewLineChar(char* str);
int gQuitFlag = 0;
static void PrintUsage()
{
- OC_LOG(INFO, TAG, "Usage : occlient -c <0|1|2> -u <0|1> -t <1|2|3>");
+ OC_LOG(INFO, TAG, "Usage : occlient -c <0|1> -u <0|1> -t <1|2|3>");
OC_LOG(INFO, TAG, "-c 0 : Default auto-selection");
OC_LOG(INFO, TAG, "-c 1 : IP Connectivity Type");
OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources");
}
OCStackResult InvokeOCDoResource(std::ostringstream &query,
- OCMethod method, OCQualityOfService qos,
+ OCMethod method, OCDevAddr *dest, OCQualityOfService qos,
OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions)
{
OCStackResult ret;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- ret = OCDoResource(NULL, method, query.str().c_str(), 0,
+ ret = OCDoResource(NULL, method, query.str().c_str(), dest,
(method == OC_REST_PUT) ? putPayload() : NULL,
- OC_CONNTYPE, qos, &cbData, options, numOptions);
+ AdapterType, qos, &cbData, options, numOptions);
if (ret != OC_STACK_OK)
{
clientResponse->devAddr.addr, clientResponse->devAddr.port);
OC_LOG_PAYLOAD (INFO, TAG, clientResponse->payload);
- parseClientResponse(clientResponse);
+ endpoint = clientResponse->devAddr;
- switch(TEST_CASE)
+ switch(TestCase)
{
case TEST_NON_CON_OP:
InitGetRequest(OC_LOW_QOS);
}
}
- return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION ;
+ return UnicastDiscovery ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION ;
}
{
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
- query << "coap://" << coapServerIP << ":" << coapServerPort << coapServerResource;
+ query << coapServerResource;
OC_LOG_V (INFO, TAG, "Performing GET with query : %s", query.str().c_str());
- return (InvokeOCDoResource(query, OC_REST_GET, (qos == OC_HIGH_QOS)?
- OC_HIGH_QOS:OC_LOW_QOS, getReqCB, NULL, 0));
+ return (InvokeOCDoResource(query, OC_REST_GET, &endpoint,
+ (qos == OC_HIGH_QOS)? OC_HIGH_QOS : OC_LOW_QOS,
+ getReqCB, NULL, 0));
}
int InitPutRequest(OCQualityOfService qos)
{
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
- query << "coap://" << coapServerIP << ":" << coapServerPort << coapServerResource;
+ query << coapServerResource;
OC_LOG_V (INFO, TAG, "Performing PUT with query : %s", query.str().c_str());
- return (InvokeOCDoResource(query, OC_REST_PUT, (qos == OC_HIGH_QOS)?
- OC_HIGH_QOS:OC_LOW_QOS, getReqCB, NULL, 0));
+ return (InvokeOCDoResource(query, OC_REST_PUT, &endpoint,
+ (qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS,
+ getReqCB, NULL, 0));
}
int InitDiscovery()
{
OCStackResult ret;
OCCallbackData cbData;
- /* Start a discovery query*/
- char szQueryUri[64] = { 0 };
- if (UNICAST_DISCOVERY)
+ char queryUri[200];
+ char ipaddr[100] = { '\0' };
+
+ if (UnicastDiscovery)
{
- char ipv4addr[IPV4_ADDR_SIZE];
- OC_LOG(INFO, TAG, "Enter IPv4:port of the Server hosting resource"\
- "(Ex: 192.168.0.15:1234)");
- if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin))
+ OC_LOG(INFO, TAG, "Enter IP address (with optional port) of the Server hosting resource\n");
+ OC_LOG(INFO, TAG, "IPv4: 192.168.0.15:45454\n");
+ OC_LOG(INFO, TAG, "IPv6: [fe80::20c:29ff:fe1b:9c5]:45454\n");
+
+ if (fgets(ipaddr, sizeof (ipaddr), stdin))
{
- //Strip newline char from ipv4addr
- StripNewLineChar(ipv4addr);
- snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_DISCOVERY_QUERY, ipv4addr);
+ StripNewLineChar(ipaddr); //Strip newline char from ipaddr
}
else
{
- OC_LOG(ERROR, TAG, "!! Bad input for IPV4 address. !!");
+ OC_LOG(ERROR, TAG, "!! Bad input for IP address. !!");
return OC_STACK_INVALID_PARAM;
}
}
- else
- {
- OICStrcpy(szQueryUri, sizeof(szQueryUri), MULTICAST_RESOURCE_DISCOVERY_QUERY);
- }
+
+ snprintf(queryUri, sizeof (queryUri), RESOURCE_DISCOVERY_QUERY, ipaddr);
+
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
- if(UNICAST_DISCOVERY)
- {
- ret = OCDoResource(NULL, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
- OC_LOW_QOS, &cbData, NULL, 0);
- }
- else
- {
- ret = OCDoResource(NULL, OC_REST_DISCOVER, szQueryUri, 0, 0, CT_DEFAULT,
- OC_LOW_QOS, &cbData, NULL, 0);
- }
+
+ ret = OCDoResource(NULL, OC_REST_DISCOVER, queryUri, 0, 0, CT_DEFAULT,
+ OC_LOW_QOS, &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
switch(opt)
{
case 'u':
- UNICAST_DISCOVERY = atoi(optarg);
+ UnicastDiscovery = atoi(optarg);
break;
case 't':
- TEST_CASE = atoi(optarg);
+ TestCase = atoi(optarg);
break;
case 'c':
- CONNECTIVITY = atoi(optarg);
+ ConnectivityType = atoi(optarg);
break;
default:
PrintUsage();
}
}
- if ((UNICAST_DISCOVERY != 0 && UNICAST_DISCOVERY != 1) ||
- (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS) ||
- (CONNECTIVITY < CT_ADAPTER_DEFAULT || CONNECTIVITY >= MAX_CT))
+ if ((UnicastDiscovery != 0 && UnicastDiscovery != 1) ||
+ (TestCase < TEST_DISCOVER_REQ || TestCase >= MAX_TESTS) ||
+ (ConnectivityType < CT_ADAPTER_DEFAULT || ConnectivityType >= MAX_CT))
{
PrintUsage();
return -1;
return 0;
}
- if(CONNECTIVITY == CT_ADAPTER_DEFAULT || CONNECTIVITY == CT_IP)
+ if(ConnectivityType == CT_ADAPTER_DEFAULT || ConnectivityType == CT_IP)
{
- OC_CONNTYPE = CT_ADAPTER_IP;
+ AdapterType = CT_ADAPTER_IP;
}
else
{
OC_LOG(INFO, TAG, "Default Connectivity type selected...");
- OC_CONNTYPE = CT_ADAPTER_IP;
+ AdapterType = CT_ADAPTER_IP;
}
InitDiscovery();
return "/a/led";
}
-void parseClientResponse(OCClientResponse * clientResponse)
-{
- coapServerIP = clientResponse->devAddr.addr;
- coapServerPort = clientResponse->devAddr.port;
- coapServerResource = getQueryStrForGetPut(clientResponse);
-}
-
#include "common.h"
#define TAG "occlientbasicops"
-static int UNICAST_DISCOVERY = 0;
-static int TEST_CASE = 0;
-static int CONN_TYPE = 0;
+static int UnicastDiscovery = 0;
+static int TestCase = 0;
+static int ConnType = 0;
-static int IPV4_ADDR_SIZE = 24;
-static char UNICAST_DISCOVERY_QUERY[] = "coap://%s/oic/res";
-static char MULTICAST_DISCOVERY_QUERY[] = "/oic/res";
+static char DISCOVERY_QUERY[] = "%s/oic/res";
OCConnectivityType discoveryReqConnType = CT_ADAPTER_IP;
+static OCDevAddr endpoint;
-static std::string coapServerIP;
-static std::string coapServerPort;
static std::string coapServerResource;
static int coapSecureResource;
static OCConnectivityType ocConnType;
-
//Secure Virtual Resource database for Iotivity Client application
//It contains Client's Identity and the PSK credentials
//of other devices which the client trusts
" Initiate Nonconfirmable Get/Put/Post Requests");
OC_LOG(INFO, TAG, "-t 3 : Discover Resources and Initiate Confirmable Get/Put/Post Requests");
OC_LOG(INFO, TAG, "-c 0 : Default auto-selection");
- OC_LOG(INFO, TAG, "-c 1 : IPv4 Connectivity Type");
+ OC_LOG(INFO, TAG, "-c 1 : IP Connectivity Type");
}
OCStackResult InvokeOCDoResource(std::ostringstream &query,
- OCMethod method, OCQualityOfService qos,
- OCClientResponseHandler cb, OCHeaderOption * options, uint8_t numOptions)
+ OCMethod method,
+ const OCDevAddr *dest,
+ OCQualityOfService qos,
+ OCClientResponseHandler cb,
+ OCHeaderOption * options, uint8_t numOptions)
{
OCStackResult ret;
OCCallbackData cbData;
cbData.context = NULL;
cbData.cd = NULL;
- ret = OCDoResource(NULL, method, query.str().c_str(), 0,
+ ret = OCDoResource(NULL, method, query.str().c_str(), dest,
(method == OC_REST_PUT || method == OC_REST_POST) ? putPayload() : NULL,
ocConnType, qos, &cbData, options, numOptions);
return ret;
}
-OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse)
+OCStackApplicationResult putReqCB(void*, OCDoHandle, OCClientResponse * clientResponse)
{
OC_LOG(INFO, TAG, "Callback Context for PUT recvd successfully");
return OC_STACK_DELETE_TRANSACTION;
}
-OCStackApplicationResult postReqCB(void *ctx, OCDoHandle handle, OCClientResponse *clientResponse)
+OCStackApplicationResult postReqCB(void *, OCDoHandle, OCClientResponse *clientResponse)
{
OC_LOG(INFO, TAG, "Callback Context for POST recvd successfully");
return OC_STACK_DELETE_TRANSACTION;
}
-OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse)
+OCStackApplicationResult getReqCB(void*, OCDoHandle, OCClientResponse * clientResponse)
{
OC_LOG(INFO, TAG, "Callback Context for GET query recvd successfully");
}
// This is a function called back when a device is discovered
-OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
+OCStackApplicationResult discoveryReqCB(void*, OCDoHandle,
OCClientResponse * clientResponse)
{
OC_LOG(INFO, TAG, "Callback Context for DISCOVER query recvd successfully");
OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
ocConnType = clientResponse->connType;
+ endpoint = clientResponse->devAddr;
if (parseClientResponse(clientResponse) != -1)
{
- switch(TEST_CASE)
+ switch(TestCase)
{
case TEST_NON_CON_OP:
InitGetRequest(OC_LOW_QOS);
}
}
- return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION ;
+ return (UnicastDiscovery) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION ;
}
{
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
- query << (coapSecureResource ? "coaps://" : "coap://") << coapServerIP
- << ":" << coapServerPort << coapServerResource;
- return (InvokeOCDoResource(query, OC_REST_PUT,
+ query << coapServerResource;
+ endpoint.flags = (OCTransportFlags)(endpoint.flags|OC_SECURE);
+ return (InvokeOCDoResource(query, OC_REST_PUT, &endpoint,
((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS), putReqCB, NULL, 0));
}
OCStackResult result;
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
- query << (coapSecureResource ? "coaps://" : "coap://") << coapServerIP
- << ":" << coapServerPort << coapServerResource;
+ query << coapServerResource;
+ endpoint.flags = (OCTransportFlags)(endpoint.flags|OC_SECURE);
// First POST operation (to create an LED instance)
- result = InvokeOCDoResource(query, OC_REST_POST,
+ result = InvokeOCDoResource(query, OC_REST_POST, &endpoint,
((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
postReqCB, NULL, 0);
if (OC_STACK_OK != result)
}
// Second POST operation (to create an LED instance)
- result = InvokeOCDoResource(query, OC_REST_POST,
+ result = InvokeOCDoResource(query, OC_REST_POST, &endpoint,
((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
postReqCB, NULL, 0);
if (OC_STACK_OK != result)
}
// This POST operation will update the original resourced /a/led
- return (InvokeOCDoResource(query, OC_REST_POST,
+ return (InvokeOCDoResource(query, OC_REST_POST, &endpoint,
((qos == OC_HIGH_QOS) ? OC_HIGH_QOS: OC_LOW_QOS),
postReqCB, NULL, 0));
}
{
OC_LOG_V(INFO, TAG, "\n\nExecuting %s", __func__);
std::ostringstream query;
- query << (coapSecureResource ? "coaps://" : "coap://") << coapServerIP
- << ":" << coapServerPort << coapServerResource;
+ query << coapServerResource;
+ endpoint.flags = (OCTransportFlags)(endpoint.flags|OC_SECURE);
- return (InvokeOCDoResource(query, OC_REST_GET, (qos == OC_HIGH_QOS)?
- OC_HIGH_QOS:OC_LOW_QOS, getReqCB, NULL, 0));
+ return (InvokeOCDoResource(query, OC_REST_GET, &endpoint,
+ ((qos == OC_HIGH_QOS)? OC_HIGH_QOS:OC_LOW_QOS),
+ getReqCB, NULL, 0));
}
int InitDiscovery()
{
OCStackResult ret;
- OCMethod method;
OCCallbackData cbData;
- char szQueryUri[MAX_URI_LENGTH] = { 0 };
+ char queryUri[200];
+ char ipaddr[100] = { '\0' };
- if (UNICAST_DISCOVERY)
+ if (UnicastDiscovery)
{
- char ipv4addr[IPV4_ADDR_SIZE];
- OC_LOG(INFO, TAG, "Enter IPv4 address:port of the Server hosting secure resource"\
- "(Ex: 11.12.13.14:1234)\n");
- if (fgets(ipv4addr, IPV4_ADDR_SIZE, stdin))
+ OC_LOG(INFO, TAG, "Enter IP address (with optional port) of the Server hosting resource\n");
+ OC_LOG(INFO, TAG, "IPv4: 192.168.0.15:45454\n");
+ OC_LOG(INFO, TAG, "IPv6: [fe80::20c:29ff:fe1b:9c5]:45454\n");
+
+ if (fgets(ipaddr, sizeof (ipaddr), stdin))
{
- //Strip newline char from ipv4addr
- StripNewLineChar(ipv4addr);
- snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_DISCOVERY_QUERY, ipv4addr);
+ StripNewLineChar(ipaddr); //Strip newline char from ipaddr
}
else
{
- OC_LOG(ERROR, TAG, "!! Bad input for IPV4 address. !!");
+ OC_LOG(ERROR, TAG, "!! Bad input for IP address. !!");
return OC_STACK_INVALID_PARAM;
}
- method = OC_REST_GET;
- }
- else
- {
- //Send discovery request on Wifi and Ethernet interface
- discoveryReqConnType = CT_DEFAULT;
- OICStrcpy(szQueryUri, sizeof(szQueryUri), MULTICAST_DISCOVERY_QUERY);
- method = OC_REST_DISCOVER;
}
+ snprintf(queryUri, sizeof (queryUri), DISCOVERY_QUERY, ipaddr);
cbData.cb = discoveryReqCB;
cbData.context = NULL;
/* Start a discovery query*/
OC_LOG_V(INFO, TAG, "Initiating %s Resource Discovery : %s\n",
- (UNICAST_DISCOVERY) ? "Unicast" : "Multicast",
- szQueryUri);
+ (UnicastDiscovery) ? "Unicast" : "Multicast",
+ queryUri);
- ret = OCDoResource(NULL, method, szQueryUri, 0, 0,
- discoveryReqConnType, OC_LOW_QOS,
- &cbData, NULL, 0);
+ ret = OCDoResource(NULL, OC_REST_DISCOVER, queryUri, 0, 0, CT_DEFAULT,
+ OC_LOW_QOS, &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
switch(opt)
{
case 'u':
- UNICAST_DISCOVERY = atoi(optarg);
+ UnicastDiscovery = atoi(optarg);
break;
case 't':
- TEST_CASE = atoi(optarg);
+ TestCase = atoi(optarg);
break;
case 'c':
- CONN_TYPE = atoi(optarg);
+ ConnType = atoi(optarg);
break;
default:
PrintUsage();
}
}
- if ((UNICAST_DISCOVERY != 0 && UNICAST_DISCOVERY != 1) ||
- (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS)||
- (CONN_TYPE < CT_ADAPTER_DEFAULT || CONN_TYPE >= MAX_CT))
+ if ((UnicastDiscovery != 0 && UnicastDiscovery != 1) ||
+ (TestCase < TEST_DISCOVER_REQ || TestCase >= MAX_TESTS)||
+ (ConnType < CT_ADAPTER_DEFAULT || ConnType >= MAX_CT))
{
PrintUsage();
return -1;
}
- if(CONN_TYPE == CT_ADAPTER_DEFAULT || CONN_TYPE == CT_IP)
+ if(ConnType == CT_ADAPTER_DEFAULT || ConnType == CT_IP)
{
discoveryReqConnType = CT_DEFAULT;
}
// Initialize Persistent Storage for SVR database
- OCPersistentStorage ps = {};
- ps.open = client_fopen;
- ps.read = fread;
- ps.write = fwrite;
- ps.close = fclose;
- ps.unlink = unlink;
+ OCPersistentStorage ps = { client_fopen, fread, fwrite, fclose, unlink };
OCRegisterPersistentStorageHandler(&ps);
/* Initialize OCStack*/
return 0;
}
-std::string getPortTBServer(OCClientResponse * clientResponse)
-{
- if(!clientResponse) return "";
- std::ostringstream ss;
- ss << clientResponse->devAddr.port;
- return ss.str();
-}
-
int parseClientResponse(OCClientResponse * clientResponse)
{
OCResourcePayload* res = ((OCDiscoveryPayload*)clientResponse->payload)->resources;
// Initialize all global variables
coapServerResource.clear();
- coapServerPort.clear();
- coapServerIP.clear();
coapSecureResource = 0;
- while(res)
+ while (res)
{
coapServerResource.assign(res->uri);
OC_LOG_V(INFO, TAG, "Uri -- %s", coapServerResource.c_str());
- if(res->secure)
+ if (res->secure)
{
+ endpoint.port = res->port;
coapSecureResource = 1;
}
OC_LOG_V(INFO, TAG, "Secure -- %s", coapSecureResource == 1 ? "YES" : "NO");
- std::ostringstream ss;
- ss << res->port;
- coapServerPort = ss.str();
- std::cout<<"PORT: "<<coapServerPort;
-
// If we discovered a secure resource, exit from here
if (coapSecureResource)
{
res = res->next;
}
- coapServerIP = clientResponse->devAddr.addr;
-
- if(coapServerPort.length() == 0 || coapServerPort == "0")
- {
- coapServerPort = getPortTBServer(clientResponse);
- OC_LOG_V(INFO, TAG, "Hosting Server Port -- %s", coapServerPort.c_str());
- }
-
return 0;
}
{
(void) ipAddr;
(void) port;
-#ifdef RA_ADAPTER
- if(!gRASetInfo)
- {
- OC_LOG(ERROR, TAG, PCF("Need to call OCSetRAInfo before calling OCInit"));
- return OC_STACK_ERROR;
- }
-#endif
return OCInit1(mode, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS);
}
return OC_STACK_OK;
}
+#ifdef RA_ADAPTER
+ if(!gRASetInfo)
+ {
+ OC_LOG(ERROR, TAG, PCF("Need to call OCSetRAInfo before calling OCInit"));
+ return OC_STACK_ERROR;
+ }
+#endif
+
OCStackResult result = OC_STACK_ERROR;
OC_LOG(INFO, TAG, PCF("Entering OCInit"));
caglobals.serverFlags = (CATransportFlags_t)serverFlags;
if (!(caglobals.serverFlags & CA_IPFAMILY_MASK))
{
- caglobals.serverFlags = (CATransportFlags_t)(caglobals.serverFlags|CA_IPV4);
+ caglobals.serverFlags = (CATransportFlags_t)(caglobals.serverFlags|CA_IPV4|CA_IPV6);
}
caglobals.clientFlags = (CATransportFlags_t)clientFlags;
if (!(caglobals.clientFlags & CA_IPFAMILY_MASK))
{
- caglobals.clientFlags = (CATransportFlags_t)(caglobals.clientFlags|CA_IPV4);
+ caglobals.clientFlags = (CATransportFlags_t)(caglobals.clientFlags|CA_IPV4|CA_IPV6);
}
defaultDeviceHandler = NULL;