if target_os in ['darwin', 'ios']:
examples_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
-examples_env.AppendUnique(CPPDEFINES = ['CA_INT'])
-
######################################################################
# Source files and Targets
######################################################################
if not env.get('RELEASE'):
liboctbstack_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-liboctbstack_env.AppendUnique(CPPDEFINES = ['CA_INT'])
-
######################################################################
# Source files and Targets
######################################################################
INC_DIRS += -I$(CONNECTIVITY_DIR)/api
# TODO-CA Remove -fstack-protector-all before merging to master
-# TODO-CA Remove CA_INT flag after CA merging is finalized
-CC_FLAGS.debug := -O0 -g3 -Wall -fstack-protector-all -c -fmessage-length=0 -pedantic -fpic -DTB_LOG -DCA_INT
+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 -DCA_INT
+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
uint32_t GetTime(float afterSeconds);
-/**
- * Initialize the CoAP client or server with the its IPv4 address and CoAP port
- *
- * @param ipAddr
- * IP Address of host device
- * @param port
- * Port of host device
- * @param mode
- * Host device is client, server, or client-server
- *
- * @return
- * 0 - success
- * TBD - TBD error
- */
-OCStackResult OCInitCoAP(const char *address, uint16_t port, OCMode mode);
-
-/**
- * Discover OC resources
- *
- * @param method - method to perform on the resource
- * @param qos - CON or NON requests
- * @param token - pointer to the token data structure
- * @param Uri - URI of the resource to interact with
- * @param payload - CoAP PDU payload
- * @param options - The address of an array containing the vendor specific
- * header options to be sent with the request
- * @param numOptions - The number of header options to be included
- * @return
- * 0 - success
- * TBD - TBD error
- */
-#ifdef CA_INT
-OCStackResult OCDoCoAPResource(OCMethod method, OCQualityOfService qos, CAToken_t * token,
- const char *Uri, const char *payload, OCHeaderOption * options, uint8_t numOptions);
-#else
-OCStackResult OCDoCoAPResource(OCMethod method, OCQualityOfService qos, OCCoAPToken * token,
- const char *Uri, const char *payload, OCHeaderOption * options, uint8_t numOptions);
-#endif
-
-/**
- * Send a response to a request.
- *
- * @param response - pointer to OCServerProtocolResponse that contains all request and
- * response info necessary to send the response to the client
- * @return
- * OC_STACK_OK - No errors; Success
- * OC_STACK_ERROR - Error sending response
- */
-OCStackResult OCDoCoAPResponse(OCServerProtocolResponse *response);
-
-/**
- * Stop the CoAP client or server processing
- *
- * @return 0 - success, else - TBD error
- */
-OCStackResult OCStopCoAP();
-
-/**
- * Called in main loop of CoAP client or server. Allows low-level CoAP processing of
- * send, receive, timeout, discovery, callbacks, etc.
- *
- * @return 0 - success, else - TBD error
- */
-OCStackResult OCProcessCoAP();
-
-/**
- * This method is called to generate a token of MAX_TOKEN_LENGTH.
- * This token is used to co-relate client requests with server responses.
- *
- */
-void OCGenerateCoAPToken(OCCoAPToken * token);
-
-/**
- * Retrieve the end-point info where resource is being hosted.
- * Currently, this method only provides the IP port with which the socket
- * is bound. This internal method may be extended in future to retrieve
- * more info (such as IP address, transport technology) about the hosting end-point.
- *
- * @param resPtr - pointer to the resource
- * @param info - pointer to 16-bit integer to hold port number
- * @return 0 - success, else - TBD error
- */
-OCStackResult OCGetResourceEndPointInfo (OCResource *resPtr, void *info);
-
#endif /* OCCOAP_H_ */
#define MAX_URI_QUERY_BUF_SIZE ((MAX_URI_LENGTH) >= (MAX_QUERY_LENGTH) ?\
(MAX_URI_LENGTH) : (MAX_QUERY_LENGTH))
-#define COAP_WK_IPAddr_0 (224)
-#define COAP_WK_IPAddr_1 (0)
-#define COAP_WK_IPAddr_2 (1)
-#define COAP_WK_IPAddr_3 (187)
-
// checks if optionID is within vendor specific range
OCStackResult isVendorSpecific(uint16_t optionID);
-// Convert OCStack code to CoAP code
-uint8_t OCToCoAPResponseCode(OCStackResult result);
-
-//Convert OCQualityOfService to coap NON vs CON
-uint8_t OCToCoAPQoS(OCQualityOfService qos, uint8_t * ipAddr);
-
-// Convert CoAP code to OCStack code
-OCStackResult CoAPToOCResponseCode(uint8_t coapCode);
-
-// Internal function to generate a coap pdu based on passed parameters
-#ifdef CA_INT
-coap_pdu_t *
-GenerateCoAPPdu(uint8_t msgType, uint8_t code, unsigned short id,
- CAToken_t * token, unsigned char * payloadJSON,
- coap_list_t *options);
-#else
-coap_pdu_t *
-GenerateCoAPPdu(uint8_t msgType, uint8_t code, unsigned short id,
- OCCoAPToken * token, unsigned char * payloadJSON,
- coap_list_t *options);
-#endif
-
-// Internal function to send a coap pdu, it also handles NON and CON
-OCStackResult
-SendCoAPPdu(coap_context_t * gCoAPCtx, coap_address_t* dst, coap_pdu_t * pdu,
- coap_send_flags_t flag);
-
-// Call back function used by libcoap to order option in coap pdu
-int OrderOptions(void *a, void *b);
-
-// Internal function to create an option node for coap pdu
-coap_list_t *
-CreateNewOptionNode(unsigned short key, unsigned int length,
- unsigned char *data);
-
-// Internal function to retrieve Uri and Query from received coap pdu
-OCStackResult ParseCoAPPdu(coap_pdu_t * pdu, unsigned char * uriBuf,
- unsigned char * queryBuf, uint32_t * observeOption,
- uint32_t * maxAgeOption,
- uint8_t * numVendorSpecificHeaderOptions,
- OCHeaderOption * vendorSpecificHeaderOptions,
- coap_block_t * block1, coap_block_t * block2,
- uint16_t * size1, uint16_t * size2,
- unsigned char * payload);
-
-#ifdef CA_INT
-void RetrieveOCCoAPToken(const coap_pdu_t * pdu, CAToken_t * rcvdToken);
-#else
-void RetrieveOCCoAPToken(const coap_pdu_t * pdu, OCCoAPToken * rcvdToken);
-#endif
-
-// Internal function to create OCResponse struct at the client from a received coap pdu
-#ifdef CA_INT
OCStackResult FormOCResponse(OCResponse * * responseLoc, ClientCB * cbNode, uint32_t maxAge,
unsigned char * fullUri, unsigned char * rcvdUri, CAToken_t * rcvdToken,
OCClientResponse * clientResponse, unsigned char * bufRes);
-#else
-OCStackResult FormOCResponse(OCResponse * * responseLoc, ClientCB * cbNode, uint32_t maxAge,
- unsigned char * fullUri, unsigned char * rcvdUri, OCCoAPToken * rcvdToken,
- OCClientResponse * clientResponse, unsigned char * bufRes);
-#endif
// Internal function to create OCClientResponse struct at the client from a received coap pdu
OCStackResult FormOCClientResponse(OCClientResponse * clientResponse,
OCStackResult result, OCDevAddr * remote, uint32_t seqNum,
const unsigned char * resJSONPayload);
-// Internal function to handle the queued pdus in the send queue
-void HandleSendQueue(coap_context_t * gCoAPCtx);
-
-// Internal function to form the standard response option list
-OCStackResult FormOptionList(coap_list_t * * optListLoc, uint8_t * addMediaType,
- uint32_t * addMaxAge, uint32_t * observeOptionPtr,
- uint16_t * addPortNumber, uint8_t uriLength, unsigned char * uri,
- uint8_t queryLength, unsigned char * query, OCHeaderOption * vendorSpecificHeaderOptions,
- uint8_t numVendorSpecificHeaderOptions);
-
-// Internal function to retransmit a queue
-OCStackResult ReTXCoAPQueue(coap_context_t * ctx, coap_queue_t * queue);
-
-// Internal function called when sending/retransmission fails
-OCStackResult HandleFailedCommunication(coap_context_t * ctx, coap_queue_t * queue);
#endif /* OCCOAPHELPER_H_ */
//=============================================================================
#define COAP_BLOCK_FILL_VALUE (0xFF)
-//=============================================================================
-// Private Variables
-//=============================================================================
-
-static coap_context_t *gCoAPCtx = NULL;
-
-//=============================================================================
-// Helper Functions
-//=============================================================================
-
-//generate a coap token
-void OCGenerateCoAPToken(OCCoAPToken * token)
-{
- if (token)
- {
- token->tokenLength = MAX_TOKEN_LENGTH;
- OCFillRandomMem((uint8_t*)token->token, token->tokenLength);
- }
-}
-
-//This function is called back by libcoap when ack or rst are received
-static void HandleCoAPAckRst(struct coap_context_t * ctx, uint8_t msgType,
- const coap_queue_t * sentQueue){
-
- // silence warnings
- (void) ctx;
- coap_pdu_t * sentPdu = sentQueue->pdu;
- OCStackResult result = OC_STACK_ERROR;
- uint32_t observationOption = OC_OBSERVE_NO_OPTION;
- // {{0}} to eliminate warning for known compiler bug 53119
- // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
-
-#ifdef CA_INT
- CAToken_t sentToken = NULL;
-#else // CA_INT
- OCCoAPToken sentToken = {{0}};
-#endif // CA_INT
-
- result = ParseCoAPPdu(sentPdu, NULL, NULL, &observationOption, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL);
- VERIFY_SUCCESS(result, OC_STACK_OK);
-
- // fill OCCoAPToken structure
- RetrieveOCCoAPToken(sentPdu, &sentToken);
-
- if(msgType == COAP_MESSAGE_RST)
- {
- if(myStackMode != OC_CLIENT)
- {
- result = OCStackFeedBack(&sentToken, OC_OBSERVER_NOT_INTERESTED);
- if(result == OC_STACK_OK)
- {
-#ifdef CA_INT
- OC_LOG_V(DEBUG, TAG,
- "Received RST, removing all queues associated with Token %d bytes",
- CA_MAX_TOKEN_LEN);
- OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)sentToken, CA_MAX_TOKEN_LEN);
- coap_cancel_all_messages(ctx, &sentQueue->remote, (unsigned char *)sentToken,
- CA_MAX_TOKEN_LEN);
-#else
- OC_LOG_V(DEBUG, TAG,
- "Received RST, removing all queues associated with Token %d bytes",
- sentToken.tokenLength);
- OC_LOG_BUFFER(INFO, TAG, sentToken.token, sentToken.tokenLength);
- coap_cancel_all_messages(ctx, &sentQueue->remote, sentToken.token,
- sentToken.tokenLength);
-#endif
- }
- }
- }
- else if(observationOption != OC_OBSERVE_NO_OPTION && msgType == COAP_MESSAGE_ACK)
- {
-#ifdef CA_INT
-#else
- OC_LOG_V(DEBUG, TAG, "Received ACK, for Token %d bytes",sentToken.tokenLength);
- OC_LOG_BUFFER(INFO, TAG, sentToken.token, sentToken.tokenLength);
-#endif
- // now the observer is still interested
- if(myStackMode != OC_CLIENT)
- {
- OCStackFeedBack(&sentToken, OC_OBSERVER_STILL_INTERESTED);
- }
- }
-exit:
- return;
-}
-
-//This function is called back by libcoap when a request is received
-static void HandleCoAPRequests(struct coap_context_t *ctx,
- const coap_queue_t * rcvdRequest)
-{
- // silence warnings
- (void) ctx;
- OCServerProtocolRequest protocolRequest = {(OCMethod)0};
- coap_block_t rcvdBlock1;
- coap_block_t rcvdBlock2;
- memset(&rcvdBlock1, COAP_BLOCK_FILL_VALUE, sizeof(coap_block_t));
- memset(&rcvdBlock2, COAP_BLOCK_FILL_VALUE, sizeof(coap_block_t));
- uint16_t rcvdSize1 = 0;
- coap_pdu_t * rcvdPdu = rcvdRequest->pdu;
- coap_pdu_t * sendPdu = NULL;
- coap_send_flags_t sendFlag;
- OCStackResult result = OC_STACK_ERROR;
- OCStackResult requestResult = OC_STACK_ERROR;
-
- if(myStackMode == OC_CLIENT)
- {
- //TODO: should the client be responding to requests?
- return;
- }
-
- protocolRequest.observationOption = OC_OBSERVE_NO_OPTION;
- protocolRequest.qos = (rcvdPdu->hdr->type == COAP_MESSAGE_CON) ?
- OC_HIGH_QOS : OC_LOW_QOS;
- protocolRequest.coapID = rcvdPdu->hdr->id;
- protocolRequest.delayedResNeeded = rcvdRequest->delayedResNeeded;
- protocolRequest.secured = rcvdRequest->secure;
-
- // fill OCCoAPToken structure
- RetrieveOCCoAPToken(rcvdPdu, &protocolRequest.requestToken);
-#ifdef CA_INT
-#else
- OC_LOG_V(INFO, TAG, " Token received %d bytes",
- protocolRequest.requestToken.tokenLength);
- OC_LOG_BUFFER(INFO, TAG, protocolRequest.requestToken.token,
- protocolRequest.requestToken.tokenLength);
-#endif
-
- // fill OCDevAddr
- memcpy(&protocolRequest.requesterAddr, (OCDevAddr *) &rcvdRequest->remote,
- sizeof(OCDevAddr));
-
- // Retrieve Uri and Query from received coap pdu
- result = ParseCoAPPdu(rcvdPdu, protocolRequest.resourceUrl,
- protocolRequest.query,
- &(protocolRequest.observationOption), NULL,
- &(protocolRequest.numRcvdVendorSpecificHeaderOptions),
- protocolRequest.rcvdVendorSpecificHeaderOptions,
- &rcvdBlock1, &rcvdBlock2, &rcvdSize1, NULL,
- protocolRequest.reqJSONPayload);
- VERIFY_SUCCESS(result, OC_STACK_OK);
-
- switch (rcvdPdu->hdr->code)
- {
- case COAP_REQUEST_GET:
- {
- protocolRequest.method = OC_REST_GET;
- break;
- }
- case COAP_REQUEST_POST:
- {
- protocolRequest.method = OC_REST_POST;
- break;
- }
- case COAP_REQUEST_DELETE:
- {
- protocolRequest.method = OC_REST_DELETE;
- break;
- }
- case COAP_REQUEST_PUT:
- {
- protocolRequest.method = OC_REST_PUT;
- break;
- }
- default:
- {
- OC_LOG_V(ERROR, TAG, "Received CoAP method %d not supported",
- rcvdPdu->hdr->code);
- goto exit;
- }
- }
-
- if(rcvdBlock1.szx != 7)
- {
- protocolRequest.reqPacketSize = 1 << (rcvdBlock1.szx + 4);
- protocolRequest.reqMorePacket = rcvdBlock1.m;
- protocolRequest.reqPacketNum = rcvdBlock1.num;
- }
- else
- {
- // No block1 received
- rcvdSize1= strlen((const char*)protocolRequest.reqJSONPayload)+1;
- protocolRequest.reqTotalSize = rcvdSize1;
- }
-
- if(rcvdBlock2.szx != 7)
- {
- protocolRequest.resPacketSize = 1 << (rcvdBlock2.szx + 4);
- protocolRequest.resPacketNum = rcvdBlock2.num;
- }
-
- requestResult = HandleStackRequests(&protocolRequest);
-
- if(requestResult == OC_STACK_VIRTUAL_DO_NOT_HANDLE ||
- requestResult == OC_STACK_OK ||
- requestResult == OC_STACK_RESOURCE_CREATED ||
- requestResult == OC_STACK_RESOURCE_DELETED ||
- requestResult == OC_STACK_INVALID_DEVICE_INFO)
- {
- goto exit;
- }
- else if(requestResult == OC_STACK_NO_MEMORY ||
- requestResult == OC_STACK_ERROR ||
- requestResult == OC_STACK_NOTIMPL ||
- requestResult == OC_STACK_NO_RESOURCE ||
- requestResult == OC_STACK_RESOURCE_ERROR)
- {
- // TODO: should we send an error also when we receive a non-secured request to a secure resource?
- // TODO: should we consider some sort of error response
- OC_LOG(DEBUG, TAG, PCF("We should send some sort of error message"));
- // generate the pdu, if the request was CON, then the response is ACK, otherwire NON
- sendPdu = GenerateCoAPPdu((rcvdPdu->hdr->type == COAP_MESSAGE_CON)? COAP_MESSAGE_ACK : COAP_MESSAGE_NON,
- OCToCoAPResponseCode(requestResult), rcvdPdu->hdr->id,
- &protocolRequest.requestToken, NULL, NULL);
- VERIFY_NON_NULL(sendPdu);
- coap_show_pdu(sendPdu);
- sendFlag = (coap_send_flags_t)(rcvdRequest->secure ? SEND_SECURE_PORT : 0);
- if(SendCoAPPdu(gCoAPCtx, (coap_address_t*) &(rcvdRequest->remote), sendPdu,
- sendFlag)
- != OC_STACK_OK){
- OC_LOG(DEBUG, TAG, PCF("A problem occurred in sending a pdu"));
- }
- goto exit;
- }
- else if(requestResult == OC_STACK_SLOW_RESOURCE)
- {
- if(rcvdPdu->hdr->type == COAP_MESSAGE_CON)
- {
- // generate the pdu, if the request was CON, then the response is ACK, otherwire NON
- sendPdu = GenerateCoAPPdu(COAP_MESSAGE_ACK, 0, rcvdPdu->hdr->id,
- NULL, NULL, NULL);
- VERIFY_NON_NULL(sendPdu);
- coap_show_pdu(sendPdu);
-
- sendFlag = (coap_send_flags_t)(rcvdRequest->secure ? SEND_SECURE_PORT : 0);
- if(SendCoAPPdu(gCoAPCtx, (coap_address_t*) &(rcvdRequest->remote), sendPdu,
- sendFlag)
- != OC_STACK_OK){
- OC_LOG(DEBUG, TAG, PCF("A problem occurred in sending a pdu"));
- }
- }
- else
- {
- goto exit;
- }
- }
-exit:
- return;
-}
-
uint32_t GetTime(float afterSeconds)
{
coap_tick_t now;
return now + (uint32_t)(afterSeconds * COAP_TICKS_PER_SECOND);
}
-//This function is called back by libcoap when a response is received
-static void HandleCoAPResponses(struct coap_context_t *ctx,
- const coap_queue_t * rcvdResponse) {
- OCStackResult result = OC_STACK_OK;
-#ifdef CA_INT
- CAToken_t rcvdToken = NULL;
-#else // CA_INT
- OCCoAPToken rcvdToken = {{0}};
-#endif // CA_INT
- OCResponse * response = NULL;
- OCClientResponse * clientResponse = NULL;
- unsigned char bufRes[MAX_RESPONSE_LENGTH] = {0};
- coap_pdu_t * sendPdu = NULL;
- coap_pdu_t * recvPdu = NULL;
- uint8_t remoteIpAddr[4] = {0};
- uint16_t remotePortNu = 0;
- uint32_t sequenceNumber = OC_OBSERVE_NO_OPTION;
- uint32_t maxAge = 0;
- unsigned char fullUri[MAX_URI_LENGTH] = { 0 };
- unsigned char rcvdUri[MAX_URI_LENGTH] = { 0 };
- coap_block_t rcvdBlock1 = {COAP_BLOCK_FILL_VALUE};
- coap_block_t rcvdBlock2 = {COAP_BLOCK_FILL_VALUE};
- uint16_t rcvdSize2 = 0;
-
- VERIFY_NON_NULL(ctx);
- VERIFY_NON_NULL(rcvdResponse);
- recvPdu = rcvdResponse->pdu;
-
- clientResponse = (OCClientResponse *) OCCalloc(1, sizeof(OCClientResponse));
-
- result = ParseCoAPPdu(recvPdu, rcvdUri, NULL, &sequenceNumber, &maxAge,
- &(clientResponse->numRcvdVendorSpecificHeaderOptions),
- clientResponse->rcvdVendorSpecificHeaderOptions,
- &rcvdBlock1, &rcvdBlock2, NULL, &rcvdSize2, bufRes);
- VERIFY_SUCCESS(result, OC_STACK_OK);
-
- // get the address of the remote
- OCDevAddrToIPv4Addr((OCDevAddr *) &(rcvdResponse->remote), remoteIpAddr,
- remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
- OCDevAddrToPort((OCDevAddr *) &(rcvdResponse->remote), &remotePortNu);
- snprintf((char *)fullUri, MAX_URI_LENGTH, "coap://%d.%d.%d.%d:%d%s",
- remoteIpAddr[0],remoteIpAddr[1],remoteIpAddr[2],remoteIpAddr[3],
- remotePortNu,rcvdUri);
-
- // fill OCCoAPToken structure
- RetrieveOCCoAPToken(recvPdu, &rcvdToken);
-#ifdef CA_INT
-#else
- OC_LOG_V(INFO, TAG,"Received a pdu with Token", rcvdToken.tokenLength);
- OC_LOG_BUFFER(INFO, TAG, rcvdToken.token, rcvdToken.tokenLength);
-#endif
-
- // fill OCClientResponse structure
- result = FormOCClientResponse(clientResponse, CoAPToOCResponseCode(recvPdu->hdr->code),
- (OCDevAddr *) &(rcvdResponse->remote), sequenceNumber, NULL);
- VERIFY_SUCCESS(result, OC_STACK_OK);
-
-
- result = FormOCResponse(&response, NULL, maxAge, fullUri, rcvdUri,
- &rcvdToken, clientResponse, bufRes);
- VERIFY_SUCCESS(result, OC_STACK_OK);
-
- result = HandleStackResponses(response);
-
- if(result == OC_STACK_ERROR)
- {
- OC_LOG(INFO, TAG, PCF("Received a notification or response that is malformed or incorrect \
- ------------ sending RESET"));
- sendPdu = GenerateCoAPPdu(COAP_MESSAGE_RST, 0,
- recvPdu->hdr->id, NULL, NULL, NULL);
- VERIFY_NON_NULL(sendPdu);
- result = SendCoAPPdu(gCoAPCtx, (coap_address_t*) &rcvdResponse->remote, sendPdu,
- (coap_send_flags_t)(rcvdResponse->secure ? SEND_SECURE_PORT : 0));
- VERIFY_SUCCESS(result, OC_STACK_OK);
- }
- else if(result == OC_STACK_NO_MEMORY)
- {
- OC_LOG(ERROR, TAG, PCF("Received a notification or response. While processing, local " \
- "platform or memory pool ran out memory."));
- }
-
- if(recvPdu->hdr->type == COAP_MESSAGE_CON)
- {
- sendPdu = GenerateCoAPPdu(COAP_MESSAGE_ACK, 0,
- recvPdu->hdr->id, NULL, NULL, NULL);
- VERIFY_NON_NULL(sendPdu);
- result = SendCoAPPdu(gCoAPCtx, (coap_address_t*) &rcvdResponse->remote,
- sendPdu,
- (coap_send_flags_t)(rcvdResponse->secure ? SEND_SECURE_PORT : 0));
- VERIFY_SUCCESS(result, OC_STACK_OK);
- }
-
- exit:
- OCFree(response);
- OCFree(clientResponse);
-}
-
-//=============================================================================
-// Functions
-//=============================================================================
-
-/**
- * Initialize the CoAP client or server with its IPv4 address and CoAP port
- *
- * @param ipAddr
- * IP Address of host device
- * @param port
- * Port of host device
- * @param mode
- * Host device is client, server, or client-server
- *
- * @return
- * 0 - success
- * TBD - TBD error
- */
-OCStackResult OCInitCoAP(const char *address, uint16_t port, OCMode mode) {
-
- OCStackResult ret = OC_STACK_ERROR;
-
- TODO ("Below should go away and be replaced by OC_LOG");
- coap_log_t log_level = (coap_log_t)(LOG_DEBUG + 1);
- OCDevAddr mcastAddr;
- uint8_t ipAddr[4] = { 0 };
- uint16_t parsedPort = 0;
-
- OC_LOG(INFO, TAG, PCF("Entering OCInitCoAP"));
-
- coap_set_log_level(log_level);
-
- if (address)
- {
- if (!ParseIPv4Address((unsigned char *) address, ipAddr, &parsedPort))
- {
- ret = OC_STACK_ERROR;
- goto exit;
- }
-
- OC_LOG_V(INFO, TAG, "Parsed IP Address %d.%d.%d.%d",
- ipAddr[0],ipAddr[1],ipAddr[2],ipAddr[3]);
- }
-
- gCoAPCtx = coap_new_context(ipAddr, port);
- VERIFY_NON_NULL(gCoAPCtx);
-
- // To allow presence notification work we need to init socket gCoAPCtx->sockfd_wellknown
- // for servers as well as clients
- OCBuildIPv4Address(COAP_WK_IPAddr_0, COAP_WK_IPAddr_1, COAP_WK_IPAddr_2,
- COAP_WK_IPAddr_3, COAP_DEFAULT_PORT, &mcastAddr);
- VERIFY_SUCCESS(
- coap_join_wellknown_group(gCoAPCtx,
- (coap_address_t* )&mcastAddr), 0);
-
- coap_register_request_handler(gCoAPCtx, HandleCoAPRequests);
- coap_register_response_handler(gCoAPCtx, HandleCoAPResponses);
- coap_register_ack_rst_handler(gCoAPCtx, HandleCoAPAckRst);
-
- ret = OC_STACK_OK;
-
-exit:
- if (ret != OC_STACK_OK)
- {
- OCStopCoAP();
- }
- return ret;
-}
-
-/**
- * Discover OC resources
- *
- * @param method - method to perform on the resource
- * @param qos - Quality of Service the request will be sent on
- * @param token - token which will added to the request
- * @param Uri - URI of the resource to interact with
- * @param payload - the request payload to be added to the request before sending
- * by the stack when discovery or resource interaction is complete
- * @param options - The address of an array containing the vendor specific
- * header options to be sent with the request
- * @return
- * 0 - success
- * TBD - TBD error
- */
-#ifdef CA_INT
-OCStackResult OCDoCoAPResource(OCMethod method, OCQualityOfService qos, CAToken_t * token,
- const char *Uri, const char *payload, OCHeaderOption * options, uint8_t numOptions)
-#else
-OCStackResult OCDoCoAPResource(OCMethod method, OCQualityOfService qos, OCCoAPToken * token,
- const char *Uri, const char *payload, OCHeaderOption * options, uint8_t numOptions)
-#endif
-{
-
- OCStackResult ret = OC_STACK_ERROR;
- coap_pdu_t *pdu = NULL;
- coap_uri_t uri;
- OCDevAddr dst;
- uint8_t ipAddr[4] = { 0 };
- uint16_t port = 0;
- coap_list_t *optList = NULL;
- uint8_t coapMsgType;
- uint8_t coapMethod;
- uint32_t observeOption;
- coap_send_flags_t flag = (coap_send_flags_t)0;
-
- OC_LOG(INFO, TAG, PCF("Entering OCDoCoAPResource"));
-
- if (Uri) {
- OC_LOG_V(INFO, TAG, "URI = %s", Uri);
- VERIFY_SUCCESS(coap_split_uri((unsigned char * )Uri, strlen(Uri), &uri), OC_STACK_OK);
-
- // Generate the destination address
- if (uri.host.length && ParseIPv4Address(uri.host.s, ipAddr, &port)) {
- OCBuildIPv4Address(ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3], uri.port,
- &dst);
- } else {
- goto exit;
- }
-
- VERIFY_SUCCESS(FormOptionList(&optList, NULL, NULL, NULL,
- (uint16_t*)&uri.port, uri.path.length, uri.path.s, uri.query.length,
- uri.query.s, options, numOptions), OC_STACK_OK);
-
- //TODO : Investigate the scenario where there will be no uri for OCDoCoAPResource
- flag = (coap_send_flags_t) (uri.secure ? SEND_SECURE_PORT : 0);
- OC_LOG_V(DEBUG, TAG, "uri.host.s %s", uri.host.s);
- OC_LOG_V(DEBUG, TAG, "uri.path.s %s", uri.path.s);
- OC_LOG_V(DEBUG, TAG, "uri.port %d", uri.port);
- OC_LOG_V(DEBUG, TAG, "uri.query.s %s", uri.query.s);
- OC_LOG_V(DEBUG, TAG, "secure uri %d", uri.secure);
- }
-
- coapMsgType = OCToCoAPQoS(qos, ipAddr);
-
- // Decide method type
- switch (method) {
- case OC_REST_GET:
- coapMethod = COAP_REQUEST_GET;
- break;
- case OC_REST_PUT:
- coapMethod = COAP_REQUEST_PUT;
- break;
- case OC_REST_POST:
- coapMethod = COAP_REQUEST_POST;
- break;
- case OC_REST_DELETE:
- coapMethod = COAP_REQUEST_DELETE;
- break;
- case OC_REST_OBSERVE_ALL:
- case OC_REST_OBSERVE:
- case OC_REST_CANCEL_OBSERVE:
- coapMethod = COAP_REQUEST_GET;
- observeOption = (method == OC_REST_CANCEL_OBSERVE)?
- OC_OBSERVE_DEREGISTER:OC_OBSERVE_REGISTER;
- coap_insert(&optList, CreateNewOptionNode(COAP_OPTION_OBSERVE,
- sizeof(observeOption), (uint8_t *)&observeOption), OrderOptions);
- break;
- default:
- coapMethod = OC_REST_NOMETHOD;
- OC_LOG(FATAL, TAG, PCF("OCDoCoAPResource only supports GET, PUT, & OBSERVE methods"));
- break;
- }
-
- VERIFY_NON_NULL(gCoAPCtx);
- pdu = GenerateCoAPPdu(coapMsgType, coapMethod,
- coap_new_message_id(gCoAPCtx), token,
- (unsigned char*) payload, optList);
- VERIFY_NON_NULL(pdu);
-
- ret = SendCoAPPdu(gCoAPCtx, (coap_address_t*) &dst, pdu, flag);
-
-exit:
- if (ret!= OC_STACK_OK)
- {
- OC_LOG(DEBUG, TAG, PCF("A problem occurred in sending a pdu"));
- }
- return ret;
-}
-
-OCStackResult OCDoCoAPResponse(OCServerProtocolResponse *response)
-{
- OCStackResult result = OC_STACK_ERROR;
- coap_pdu_t * sendPdu = NULL;
- coap_list_t *optList = NULL;
- uint8_t msgType = COAP_MESSAGE_NON;
- uint8_t mediaType = COAP_MEDIATYPE_APPLICATION_JSON;
- uint32_t maxAge = 0x2ffff;
- coap_send_flags_t sendFlag = (coap_send_flags_t)0;
-
- //uint32_t observeOption = OC_OBSERVE_NO_OPTION;
- //OCStackResult responseResult;
-
- OC_LOG(INFO, TAG, PCF("Entering OCDoCoAPResponse"));
-
- if(response->notificationFlag && response->qos == OC_HIGH_QOS)
- {
- msgType = COAP_MESSAGE_CON;
- }
- else if(response->notificationFlag && response->qos != OC_HIGH_QOS)
- {
- msgType = COAP_MESSAGE_NON;
- }
- else if(!response->notificationFlag && !response->slowFlag && response->qos == OC_HIGH_QOS)
- {
- msgType = COAP_MESSAGE_ACK;
- }
- else if(!response->notificationFlag && response->slowFlag && response->qos == OC_HIGH_QOS)
- {
- msgType = COAP_MESSAGE_CON;
- }
- else if(!response->notificationFlag)
- {
- msgType = COAP_MESSAGE_NON;
- }
-
- if(response->coapID == 0)
- {
- response->coapID = coap_new_message_id(gCoAPCtx);
- }
-
- if (response->observationOption != OC_OBSERVE_NO_OPTION)
- {
- result = FormOptionList(&optList, &mediaType, &maxAge,
- &response->observationOption, NULL,
- strlen((char *)response->resourceUri), response->resourceUri,
- 0, NULL,
- response->sendVendorSpecificHeaderOptions,
- response->numSendVendorSpecificHeaderOptions);
- }
- else
- {
- result = FormOptionList(&optList, &mediaType, &maxAge,
- NULL, NULL,
- strlen((char *)response->resourceUri), response->resourceUri,
- 0, NULL,
- response->sendVendorSpecificHeaderOptions,
- response->numSendVendorSpecificHeaderOptions);
- }
- VERIFY_SUCCESS(result, OC_STACK_OK);
-
- sendPdu = GenerateCoAPPdu(msgType, OCToCoAPResponseCode(response->result),
- response->coapID, response->requestToken, (unsigned char *)response->payload,
- optList);
-
- VERIFY_NON_NULL(sendPdu);
- coap_show_pdu(sendPdu);
-
- sendFlag = (coap_send_flags_t)(response->delayedResNeeded ? SEND_DELAYED : 0);
- sendFlag = (coap_send_flags_t)( sendFlag | (response->secured ? SEND_SECURE_PORT : 0));
-
- if (SendCoAPPdu(gCoAPCtx, (coap_address_t *) (response->requesterAddr), sendPdu, sendFlag)
- != OC_STACK_OK)
- {
- OC_LOG(ERROR, TAG, PCF("A problem occurred in sending a pdu"));
- return OC_STACK_ERROR;
- }
- return OC_STACK_OK;
-exit:
- OC_LOG(ERROR, TAG, PCF("Error formatting server response"));
- return OC_STACK_ERROR;
-}
-
-/**
- * Stop the CoAP client or server processing
- *
- * @return 0 - success, else - TBD error
- */
-OCStackResult OCStopCoAP() {
- OC_LOG(INFO, TAG, PCF("Entering OCStopCoAP"));
- coap_free_context(gCoAPCtx);
- gCoAPCtx = NULL;
- return OC_STACK_OK;
-}
-
-/**
- * Called in main loop of CoAP client or server. Allows low-level CoAP processing of
- * send, receive, timeout, discovery, callbacks, etc.
- *
- * @return 0 - success, else - TBD error
- */
-OCStackResult OCProcessCoAP() {
- int read = 0;
- read = coap_read(gCoAPCtx, gCoAPCtx->sockfd);
- if(read > 0) {
- OC_LOG(INFO, TAG, PCF("This is a Unicast<============"));
- }
- if (-1 != gCoAPCtx->sockfd_wellknown) {
- read = coap_read(gCoAPCtx, gCoAPCtx->sockfd_wellknown);
- if(read > 0)
- {
- OC_LOG(INFO, TAG, PCF("This is a Multicast<==========="));
- }
- }
- if (-1 != gCoAPCtx->sockfd_dtls) {
- read = coap_read(gCoAPCtx, gCoAPCtx->sockfd_dtls);
- if(read > 0)
- {
- OC_LOG(INFO, TAG, PCF("This is a Secure packet<==========="));
- }
- }
- coap_dispatch(gCoAPCtx);
-
- HandleSendQueue(gCoAPCtx);
-
- return OC_STACK_OK;
-}
-
-
-/**
- * Retrieve the info about the end-point where resource is being hosted.
- * Currently, this method only provides the IP port with which the socket
- * is bound.
- *
- * @return 0 - success, else - TBD error
- */
-OCStackResult OCGetResourceEndPointInfo (OCResource *resPtr, void *info) {
-
- OCStackResult result = OC_STACK_ERROR;
- int sfd;
- OC_LOG(INFO, TAG, PCF("Entering OCGetResourceEndPointInfo"));
- VERIFY_NON_NULL(resPtr);
- VERIFY_NON_NULL(info);
-
- sfd = (resPtr->resourceProperties & OC_SECURE) ? gCoAPCtx->sockfd_dtls :
- gCoAPCtx->sockfd;
-
- if (OCGetSocketInfo(sfd, (uint16_t*)info) == ERR_SUCCESS)
- result = OC_STACK_OK;
-exit:
- return result;
-}
-
-
#include "coap_time.h"
#include "ocmalloc.h"
-#ifdef CA_INT
#include "cacommon.h"
-#endif
//-----------------------------------------------------------------------------
// Macros
return OC_STACK_INVALID_OPTION;
}
-// Convert OCStack code to CoAP code
-uint8_t OCToCoAPResponseCode(OCStackResult result)
-{
- uint8_t ret;
- switch(result)
- {
- case OC_STACK_OK :
- ret = COAP_RESPONSE_200;
- break;
-
- case OC_STACK_RESOURCE_CREATED:
- ret = COAP_RESPONSE_201;
- break;
-
- case OC_STACK_RESOURCE_DELETED:
- ret = COAP_RESPONSE_202;
- break;
-
- case OC_STACK_INVALID_QUERY :
- ret = COAP_RESPONSE_400;
- break;
-
- case OC_STACK_RESOURCE_ERROR:
- return COAP_RESPONSE_403;
- break;
-
- case OC_STACK_NO_RESOURCE :
- ret = COAP_RESPONSE_404;
- break;
-
- case OC_STACK_INVALID_METHOD :
- ret = COAP_RESPONSE_405;
- break;
-
- case OC_STACK_NOTIMPL :
- ret = COAP_RESPONSE_501;
- break;
-
- default:
- ret = COAP_RESPONSE_500;
- }
- return ret;
-}
-
-uint8_t OCToCoAPQoS(OCQualityOfService qos, uint8_t * ipAddr)
-{
- if(ipAddr[0] == COAP_WK_IPAddr_0 && ipAddr[1] == COAP_WK_IPAddr_1 &&
- ipAddr[2] == COAP_WK_IPAddr_2 && ipAddr[3] == COAP_WK_IPAddr_3)
- {
- return COAP_MESSAGE_NON;
- }
- switch (qos)
- {
- case OC_HIGH_QOS:
- return COAP_MESSAGE_CON;
- break;
- case OC_MEDIUM_QOS:
- case OC_LOW_QOS:
- case OC_NA_QOS:
- default:
- return COAP_MESSAGE_NON;
- break;
- }
-}
-
-OCQualityOfService CoAPToOCQoS(uint8_t qos)
-{
- switch (qos)
- {
- case COAP_MESSAGE_CON:
- return OC_HIGH_QOS;
- case COAP_MESSAGE_NON:
- return OC_LOW_QOS;
- default:
- return OC_NA_QOS;
- }
-}
-// Convert CoAP code to OCStack code
-OCStackResult CoAPToOCResponseCode(uint8_t coapCode)
-{
- OCStackResult ret;
- int decimal;
- switch(coapCode)
- {
- case COAP_RESPONSE_200 :
- ret = OC_STACK_OK;
- break;
-
- case COAP_RESPONSE_201 :
- ret = OC_STACK_RESOURCE_CREATED;
- break;
-
- case COAP_RESPONSE_202 :
- ret = OC_STACK_RESOURCE_DELETED;
- break;
-
- case COAP_RESPONSE_400 :
- ret = OC_STACK_INVALID_QUERY;
- break;
-
- case COAP_RESPONSE_403 :
- ret = OC_STACK_RESOURCE_ERROR;
- break;
-
- case COAP_RESPONSE_404 :
- ret = OC_STACK_NO_RESOURCE;
- break;
-
- case COAP_RESPONSE_405 :
- ret = OC_STACK_INVALID_METHOD;
- break;
-
- case COAP_RESPONSE_501 :
- ret = OC_STACK_NOTIMPL;
- break;
-
- default:
- decimal = ((coapCode >> 5) * 100) + (coapCode & 31);
- if (decimal >= 200 && decimal <= 231)
- {
- ret = OC_STACK_OK;
- }
- else
- {
- ret = OC_STACK_ERROR;
- }
- }
- return ret;
-}
-
-// Retrieve Uri and Query from received coap pdu
-OCStackResult ParseCoAPPdu(coap_pdu_t * pdu, unsigned char * uriBuf,
- unsigned char * queryBuf, uint32_t * observeOption,
- uint32_t * maxAgeOption,
- uint8_t * numVendorSpecificHeaderOptions,
- OCHeaderOption * vendorSpecificHeaderOptions,
- coap_block_t * block1, coap_block_t * block2,
- uint16_t * size1, uint16_t * size2,
- unsigned char * payload)
-{
- coap_opt_filter_t filter;
- coap_opt_iterator_t opt_iter;
- coap_opt_t *option = NULL;
- size_t optLen = 0;
- unsigned char * optVal = NULL;
- size_t uriBufLen = 0;
- size_t queryBufLen = 0;
- unsigned char * payloadLoc = NULL;
- size_t payloadLength = 0;
-
- coap_option_filter_clear(filter);
- if(uriBuf)
- {
- coap_option_setb(filter, COAP_OPTION_URI_PATH);
- }
- if(queryBuf)
- {
- coap_option_setb(filter, COAP_OPTION_URI_QUERY);
- }
- if(observeOption)
- {
- coap_option_setb(filter, COAP_OPTION_OBSERVE);
- }
- if(maxAgeOption)
- {
- coap_option_setb(filter, COAP_OPTION_MAXAGE);
- }
- if(block1)
- {
- coap_option_setb(filter, COAP_OPTION_BLOCK1);
- }
- if(block2)
- {
- coap_option_setb(filter, COAP_OPTION_BLOCK2);
- }
- if(size1)
- {
- coap_option_setb(filter, COAP_OPTION_SIZE1);
- }
- if(size2)
- {
- coap_option_setb(filter, COAP_OPTION_SIZE2);
- }
- if(vendorSpecificHeaderOptions)
- {
- coap_option_setbVendor(filter);
- }
- if(payload)
- {
- coap_get_data(pdu, &payloadLength, &payloadLoc);
- memcpy(payload, payloadLoc, payloadLength);
- }
- coap_option_iterator_init(pdu, &opt_iter, filter);
-
- while ((option = coap_option_next(&opt_iter)))
- {
- optLen = COAP_OPT_LENGTH(option);
- optVal = COAP_OPT_VALUE(option);
- switch(opt_iter.type)
- {
- case COAP_OPTION_URI_PATH:
- if (uriBufLen + 1 + optLen < MAX_URI_LENGTH)
- {
- //we still have room in the buffer
- uriBuf[uriBufLen++] = '/';
- memcpy(uriBuf + uriBufLen, optVal, optLen);
- uriBufLen += optLen;
- }
- else
- {
- return OC_STACK_NO_MEMORY;
- }
- break;
- case COAP_OPTION_URI_QUERY:
- if (queryBufLen + 1 + optLen < MAX_QUERY_LENGTH)
- {
- //we still have room in the buffer
- memcpy(queryBuf + queryBufLen, optVal, optLen);
- queryBufLen += optLen;
- queryBuf[queryBufLen++] = '&';
- }
- else
- {
- // TODO: we should check that resources do not have long uri
- // at the resource creation
- return OC_STACK_NO_MEMORY;
- }
- break;
- case COAP_OPTION_OBSERVE:
- memcpy(observeOption, optVal, optLen);
- OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing the observe option %u",
- *observeOption);
- break;
- case COAP_OPTION_MAXAGE:
- memcpy(maxAgeOption, optVal, optLen);
- OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing the max age option %u",
- *maxAgeOption);
- break;
- case COAP_OPTION_BLOCK1:
- block1->szx = COAP_OPT_BLOCK_SZX(option);
- block1->num = coap_opt_block_num(option);
- block1->m = 0;
- if(COAP_OPT_BLOCK_MORE(option))
- {
- block1->m = 1;
- }
- OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing block1 %u:%u:%u",
- block1->num, block1->m, block1->szx);
- break;
- case COAP_OPTION_BLOCK2:
- block2->szx = COAP_OPT_BLOCK_SZX(option);
- block2->num = coap_opt_block_num(option);
- block2->m = 0;
- if(COAP_OPT_BLOCK_MORE(option))
- {
- block2->m = 1;
- }
- OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing block2 %u:%u:%u",
- block1->num, block1->m, block1->szx);
- break;
- case COAP_OPTION_SIZE1:
- break;
- case COAP_OPTION_SIZE2:
- break;
- default:
- if(*numVendorSpecificHeaderOptions >= MAX_HEADER_OPTIONS ||
- optLen > MAX_HEADER_OPTION_DATA_LENGTH)
- {
- return OC_STACK_NO_MEMORY;
- }
- vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].protocolID = OC_COAP_ID;
- vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionID = opt_iter.type;
- vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionLength = optLen;
- memcpy(vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionData, optVal, optLen);
- OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^Parsing vendor specific option %u",
- vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionID);
- OC_LOG_BUFFER(DEBUG, TAG, vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionData,
- vendorSpecificHeaderOptions[*numVendorSpecificHeaderOptions].optionLength);
- (*numVendorSpecificHeaderOptions)++;
- }
- }
-
- if(uriBuf)
- {
- uriBuf[uriBufLen] = '\0';
- }
- // delete last '&' in the query
- if(queryBuf)
- {
- queryBuf[queryBufLen?queryBufLen-1:queryBufLen] = '\0';
- }
-
- OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^The final parsed uri is %s", uriBuf);
- OC_LOG_V(DEBUG, TAG, "^^^^^^^^^^^^The final parsed query is %s", queryBuf);
- return OC_STACK_OK;
-}
-
-// Retrieve the token from the PDU
-#ifdef CA_INT
-void RetrieveOCCoAPToken(const coap_pdu_t * pdu, CAToken_t * rcvdToken)
-#else
-void RetrieveOCCoAPToken(const coap_pdu_t * pdu, OCCoAPToken * rcvdToken)
-#endif
-{
- if (pdu && rcvdToken)
- {
-#ifdef CA_INT
- memcpy(*rcvdToken, pdu->hdr->token, CA_MAX_TOKEN_LEN);
-#else
- rcvdToken->tokenLength = pdu->hdr->token_length;
- memcpy(rcvdToken->token, pdu->hdr->token,
- rcvdToken->tokenLength);
-#endif
- }
-}
-
-#ifdef CA_INT
OCStackResult FormOCResponse(OCResponse * * responseLoc, ClientCB * cbNode, uint32_t maxAge,
unsigned char * fullUri, unsigned char * rcvdUri, CAToken_t * rcvdToken,
OCClientResponse * clientResponse, unsigned char * bufRes)
-#else
-OCStackResult FormOCResponse(OCResponse * * responseLoc, ClientCB * cbNode, uint32_t maxAge,
- unsigned char * fullUri, unsigned char * rcvdUri, OCCoAPToken * rcvdToken,
- OCClientResponse * clientResponse, unsigned char * bufRes)
-#endif
{
OCResponse * response = (OCResponse *) OCMalloc(sizeof(OCResponse));
if (!response)
return OC_STACK_OK;
}
-OCStackResult FormOptionList(coap_list_t * * optListLoc, uint8_t * addMediaType,
- uint32_t * addMaxAge, uint32_t * observeOptionPtr,
- uint16_t * addPortNumber, uint8_t uriLength, unsigned char * uri,
- uint8_t queryLength, unsigned char * query,
- OCHeaderOption * vendorSpecificHeaderOptions,
- uint8_t numVendorSpecificHeaderOptions)
-{
- coap_list_t * optNode = NULL;
- int res;
- size_t buflen;
- unsigned char _buf[MAX_URI_QUERY_BUF_SIZE];
- unsigned char *buf = _buf;
-
- if(addMediaType)
- {
- optNode = CreateNewOptionNode(COAP_OPTION_CONTENT_TYPE,
- sizeof(*addMediaType), addMediaType);
- VERIFY_NON_NULL(optNode);
- coap_insert(optListLoc, optNode, OrderOptions);
- }
-
- if(addMaxAge)
- {
- optNode = CreateNewOptionNode(COAP_OPTION_MAXAGE,
- sizeof(*addMaxAge), (uint8_t *)addMaxAge);
- VERIFY_NON_NULL(optNode);
- coap_insert(optListLoc, optNode, OrderOptions);
- }
-
- if(observeOptionPtr)
- {
- optNode = CreateNewOptionNode(COAP_OPTION_OBSERVE,
- sizeof(*observeOptionPtr), (uint8_t *)observeOptionPtr);
-
- VERIFY_NON_NULL(optNode);
- coap_insert(optListLoc, optNode, OrderOptions);
- }
- if(addPortNumber && *addPortNumber != COAP_DEFAULT_PORT)
- {
- optNode = CreateNewOptionNode(COAP_OPTION_URI_PORT,
- sizeof(*addPortNumber), (uint8_t *)addPortNumber);
- VERIFY_NON_NULL(optNode);
- coap_insert(optListLoc, optNode, OrderOptions);
- }
-
- if(uri && uriLength)
- {
- buf = _buf;
- buflen = MAX_URI_QUERY_BUF_SIZE;
- res = coap_split_path(uri, uriLength, buf, &buflen);
- while (res--) {
- optNode = CreateNewOptionNode(COAP_OPTION_URI_PATH,
- COAP_OPT_LENGTH(buf), COAP_OPT_VALUE(buf));
- VERIFY_NON_NULL(optNode);
- coap_insert(optListLoc, optNode, OrderOptions);
- buf += COAP_OPT_SIZE(buf);
- }
- }
-
- if(query && queryLength)
- {
- buf = _buf;
- buflen = MAX_URI_QUERY_BUF_SIZE;
- res = coap_split_query(query, queryLength, buf, &buflen);
- while (res--) {
- optNode = CreateNewOptionNode(COAP_OPTION_URI_QUERY,
- COAP_OPT_LENGTH(buf), COAP_OPT_VALUE(buf));
- VERIFY_NON_NULL(optNode);
- coap_insert(optListLoc, optNode, OrderOptions);
- buf += COAP_OPT_SIZE(buf);
- }
- }
-
- // make sure that options are valid
- if(vendorSpecificHeaderOptions && numVendorSpecificHeaderOptions)
- {
- uint8_t i = 0;
- for( i = 0; i < numVendorSpecificHeaderOptions; i++)
- {
- if(vendorSpecificHeaderOptions[i].protocolID == OC_COAP_ID)
- {
- if(isVendorSpecific(vendorSpecificHeaderOptions[i].optionID)
- == OC_STACK_OK &&
- vendorSpecificHeaderOptions[i].optionLength <=
- MAX_HEADER_OPTION_DATA_LENGTH)
- {
- OC_LOG_V(INFO, TAG, " Adding option %d with",
- vendorSpecificHeaderOptions[i].optionID);
- OC_LOG_BUFFER(INFO, TAG, vendorSpecificHeaderOptions[i].optionData,
- vendorSpecificHeaderOptions[i].optionLength);
- optNode = CreateNewOptionNode(vendorSpecificHeaderOptions[i].optionID,
- vendorSpecificHeaderOptions[i].optionLength,
- vendorSpecificHeaderOptions[i].optionData);
- VERIFY_NON_NULL(optNode);
- coap_insert(optListLoc, optNode, OrderOptions);
- }
- else
- {
- coap_delete_list(*optListLoc);
- return OC_STACK_INVALID_OPTION;
- }
- }
- }
- }
-
- return OC_STACK_OK;
- exit:
- coap_delete_list(*optListLoc);
- return OC_STACK_NO_MEMORY;
-}
-
-//Send a coap pdu
-OCStackResult
-SendCoAPPdu(coap_context_t * gCoAPCtx, coap_address_t* dst, coap_pdu_t * pdu,
- coap_send_flags_t flag)
-{
- coap_tid_t tid = COAP_INVALID_TID;
- OCStackResult res = OC_STACK_COMM_ERROR;
- uint8_t cache = 0;
-
- if (!(flag & SEND_DELAYED))
- {
- flag = (coap_send_flags_t)( flag |
- ((pdu->hdr->type == COAP_MESSAGE_CON) ? SEND_NOW_CON : SEND_NOW));
- }
-
- tid = coap_send(gCoAPCtx, dst, pdu, flag, &cache);
- OC_LOG_V(INFO, TAG, "TID %d", tid);
- if(tid != COAP_INVALID_TID)
- {
- OC_LOG(INFO, TAG, PCF("Sending a pdu with Token:"));
- OC_LOG_BUFFER(INFO,TAG, pdu->hdr->token, pdu->hdr->token_length);
- res = OC_STACK_OK;
- }
-
- if (( (pdu->hdr->type != COAP_MESSAGE_CON) && (!(flag & SEND_DELAYED)) && (!cache))
- || (tid == COAP_INVALID_TID))
- {
- OC_LOG(INFO, TAG, PCF("Deleting PDU"));
- coap_delete_pdu(pdu);
- }
- else
- {
- OC_LOG(INFO, TAG, PCF("Keeping PDU, we will handle the retry/delay of this pdu"));
- }
-
- return res;
-}
-
-//generate a coap message
-#ifdef CA_INT
-coap_pdu_t *
-GenerateCoAPPdu(uint8_t msgType, uint8_t code, unsigned short id,
- CAToken_t * token, unsigned char * payloadJSON,
- coap_list_t *options)
-#else
-coap_pdu_t *
-GenerateCoAPPdu(uint8_t msgType, uint8_t code, unsigned short id,
- OCCoAPToken * token, unsigned char * payloadJSON,
- coap_list_t *options)
-#endif
-{
- coap_pdu_t *pdu;
- coap_list_t *opt;
-
- if(token)
- {
- pdu = coap_pdu_init(msgType, code, id, COAP_MAX_PDU_SIZE);
- VERIFY_NON_NULL(pdu);
-#ifdef CA_INT
- pdu->hdr->token_length = CA_MAX_TOKEN_LEN;
- if (!coap_add_token(pdu, CA_MAX_TOKEN_LEN, (const unsigned char *)*token))
- {
- OC_LOG(FATAL, TAG, PCF("coap_add_token failed"));
- }
-#else
- pdu->hdr->token_length = token->tokenLength;
- if (!coap_add_token(pdu, token->tokenLength, token->token))
- {
- OC_LOG(FATAL, TAG, PCF("coap_add_token failed"));
- }
-#endif
- }
- else
- {
- pdu = coap_pdu_init(msgType, code, id, sizeof(coap_pdu_t));
- VERIFY_NON_NULL(pdu);
- }
-
- for (opt = options; opt; opt = opt->next)
- {
- coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *) opt->data),
- COAP_OPTION_LENGTH(*(coap_option *) opt->data),
- COAP_OPTION_DATA(*(coap_option *) opt->data));
- }
-
- if (payloadJSON)
- {
- coap_add_data(pdu, strlen((const char *) payloadJSON) + 1,
- (unsigned char*) payloadJSON);
- }
-
- // display the pdu for debugging purposes
- coap_show_pdu(pdu);
-
- // clean up
- coap_delete_list(options);
- return pdu;
-
- exit:
- coap_delete_list(options);
- return NULL;
-}
-
-//a function to help in ordering coap options
-int OrderOptions(void *a, void *b)
-{
- if (!a || !b)
- {
- return a < b ? -1 : 1;
- }
-
- if (COAP_OPTION_KEY(*(coap_option *)a)
- < COAP_OPTION_KEY(*(coap_option *)b) )
- {
- return -1;
- }
-
- return COAP_OPTION_KEY(*(coap_option *)a)
- == COAP_OPTION_KEY(*(coap_option *)b) ;
-}
-
-//a function to create a coap option
-coap_list_t *
-CreateNewOptionNode(unsigned short key, unsigned int length, unsigned char *data)
-{
- coap_option *option = NULL;
- coap_list_t *node;
-
- VERIFY_NON_NULL(data);
- option = (coap_option *)coap_malloc(sizeof(coap_option) + length);
- VERIFY_NON_NULL(option);
-
- COAP_OPTION_KEY(*option) = key;
- COAP_OPTION_LENGTH(*option) = length;
- memcpy(COAP_OPTION_DATA(*option), data, length);
-
- /* we can pass NULL here as delete function since option is released automatically */
- node = coap_new_listnode(option, NULL);
-
- if (node)
- {
- return node;
- }
-
-exit:
- OC_LOG(ERROR,TAG, PCF("new_option_node: malloc: was not created"));
- coap_free(option);
- return NULL;
-}
-
-OCStackResult ReTXCoAPQueue(coap_context_t * ctx, coap_queue_t * queue)
-{
- coap_tid_t tid = COAP_INVALID_TID;
- OCStackResult result = OC_STACK_ERROR;
- tid = coap_retransmit( ctx, queue);
- if(tid == COAP_INVALID_TID)
- {
- OC_LOG_V(DEBUG, TAG, "Retransmission Failed TID %d",
- queue->id);
- result = OC_STACK_COMM_ERROR;
- }
- else
- {
- OC_LOG_V(DEBUG, TAG, "Retransmission TID %d, this is attempt %d",
- queue->id, queue->retransmit_cnt);
- result = OC_STACK_OK;
- }
- return result;
-}
-
-OCStackResult HandleFailedCommunication(coap_context_t * ctx, coap_queue_t * queue)
-{
- //TODO: this function should change to only use OCStackFeedBack
- OCResponse * response = NULL;
- ClientCB * cbNode = NULL;
- OCClientResponse clientResponse;
-
- #ifdef CA_INT
- //token for the observe request
- CAToken_t token;
- #else // CA_INT
- // CoAP token for the observe request
- OCCoAPToken token;
- #endif // CA_INT
-
- OCStackResult result = OC_STACK_OK;
-
- RetrieveOCCoAPToken(queue->pdu, &token);
-
- cbNode = GetClientCB(&token, NULL, NULL);
- if(!cbNode)
- {
- goto observation;
- }
- result = FormOCClientResponse(&clientResponse, OC_STACK_COMM_ERROR,
- (OCDevAddr *) &(queue->remote), 0, NULL);
- if(result != OC_STACK_OK)
- {
- goto observation;
- }
- result = FormOCResponse(&response, cbNode, 0, NULL, NULL, &token, &clientResponse, NULL);
- if(result != OC_STACK_OK)
- {
- goto observation;
- }
- HandleStackResponses(response);
-
-observation:
- result = OCStackFeedBack(&token, OC_OBSERVER_FAILED_COMM);
-#ifdef CA_INT
- if(result == OC_STACK_OK)
- {
- coap_cancel_all_messages(ctx, &queue->remote, (unsigned char *)token, CA_MAX_TOKEN_LEN);
- }
-#else
- if(result == OC_STACK_OK)
- {
- coap_cancel_all_messages(ctx, &queue->remote, token.token, token.tokenLength);
- }
-#endif
- OCFree(response);
- return result;
-}
-
-// a function to handle the send queue in the passed context
-void HandleSendQueue(coap_context_t * ctx)
-{
- coap_tick_t now;
- coap_queue_t *nextQueue = NULL;
-
- coap_ticks(&now);
- nextQueue = coap_peek_next( ctx );
- while (nextQueue && nextQueue->t <= now - ctx->sendqueue_basetime)
- {
- nextQueue = coap_pop_next( ctx );
- if((uint8_t)nextQueue->delayedResNeeded)
- {
- OC_LOG_V(DEBUG, TAG, "Sending Delayed response TID %d",
- nextQueue->id);
- if(SendCoAPPdu(ctx, &nextQueue->remote, nextQueue->pdu,
- (coap_send_flags_t)(nextQueue->secure ? SEND_SECURE_PORT : 0))
- == OC_STACK_COMM_ERROR)
- {
- OC_LOG(DEBUG, TAG, PCF("A problem occurred in sending a pdu"));
- HandleFailedCommunication(ctx, nextQueue);
- }
- nextQueue->pdu = NULL;
- coap_delete_node(nextQueue);
- }
- else
- {
- OC_LOG_V(DEBUG, TAG, "Retrying a CON pdu TID %d",nextQueue->id);
- if(ReTXCoAPQueue(ctx, nextQueue) == OC_STACK_COMM_ERROR)
- {
- OC_LOG(DEBUG, TAG, PCF("A problem occurred in retransmitting a pdu"));
- HandleFailedCommunication(ctx, nextQueue);
- coap_delete_node(nextQueue);
- }
- }
- nextQueue = coap_peek_next( ctx );
- }
-}
#include <ocstack.h>
#include <ocresource.h>
-#ifdef CA_INT
#include "cacommon.h"
-#else
-#include "occoaptoken.h"
-#endif
typedef struct OCPresence {
// This is the TTL associated with presence
// callback method to delete context data
OCClientContextDeleter deleteCallback;
// when a response is recvd with this token, above callback will be invoked
-#ifdef CA_INT
CAToken_t token;
-#else // CA_INT
- OCCoAPToken token;
-#endif // CA_INT
// Invocation handle tied to original call to OCDoResource()
OCDoHandle handle;
// This is used to determine if all responses should be consumed or not.
*/
//------------------------------------------------------------------------
OCStackResult
-#ifdef CA_INT
AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
CAToken_t * token, OCDoHandle *handle, OCMethod method,
unsigned char * requestUri, unsigned char * resourceTypeName);
-#else // CA_INT
-AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
- OCCoAPToken * token, OCDoHandle *handle, OCMethod method,
- unsigned char * requestUri, unsigned char * resourceTypeName);
-#endif // CA_INT
//-- DeleteClientCB -----------------------------------------------------------
/** @ingroup ocstack
* @retval address of the node if found, otherwise NULL
*/
//------------------------------------------------------------------------
-#ifdef CA_INT
ClientCB* GetClientCB(const CAToken_t * token, OCDoHandle handle, const unsigned char * requestUri);
-#else // CA_INT
-ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, const unsigned char * requestUri);
-#endif // CA_INT
-
/**
* Inserts a new resource type filter into this clientCB node.
unsigned char *resUri;
// Query
unsigned char *query;
-#ifdef CA_INT
//token for the observe request
CAToken_t token;
-#else // CA_INT
- // CoAP token for the observe request
- OCCoAPToken token;
-#endif // CA_INT
// Resource handle
OCResource *resource;
// IP address & port of client registered for observe
OCDevAddr *addr;
-#ifdef CA_INT
/** Remote Endpoint address **/
CAAddress_t addressInfo;
/** Connectivity of the endpoint**/
CAConnectivityType_t connectivityType;
-#endif
// Quality of service of the request
OCQualityOfService qos;
// number of times the server failed to reach the observer
OCStackResult GenerateObserverId (OCObservationId *observationId);
-
-
-#ifdef CA_INT
OCStackResult AddObserver (const char *resUri,
const char *query,
OCObservationId obsId,
OCStackResult DeleteObserverUsingToken (CAToken_t * token);
ResourceObserver* GetObserverUsingToken (const CAToken_t * token);
-#else
-OCStackResult AddObserver (const char *resUri,
- const char *query,
- OCObservationId obsId,
- OCCoAPToken *token,
- OCDevAddr *addr,
- OCResource *resHandle,
- OCQualityOfService qos);
-
-OCStackResult DeleteObserverUsingToken (OCCoAPToken * token);
-ResourceObserver* GetObserverUsingToken (const OCCoAPToken * token);
-#endif
ResourceObserver* GetObserverUsingId (const OCObservationId observeId);
-#ifdef CA_INT
-
OCStackResult
CreateObserveHeaderOption (CAHeaderOption_t **caHdrOpt,
OCHeaderOption *ocHdrOpt,
GetObserveHeaderOption (uint32_t * observationOption,
CAHeaderOption_t *options,
uint8_t * numOptions);
-#endif // CA_INT
#endif //OC_OBSERVE_H
void DeleteDeviceInfo();
-#ifdef CA_INT
OCStackResult
BuildVirtualResourceResponse(OCResource *resourcePtr, uint8_t filterOn,
char *filterValue, char * out, uint16_t *remaining,
CAConnectivityType_t connType );
-#else
-OCStackResult
-BuildVirtualResourceResponse(OCResource *resourcePtr, uint8_t filterOn,
- char *filterValue, char * out, uint16_t *remaining);
-#endif
OCStackResult EntityHandlerCodeToOCStackCode(OCEntityHandlerResult ehResult);
#include "occoap.h"
-#ifdef CA_INT
- #include "cacommon.h"
- #include "cainterface.h"
-#endif
+#include "cacommon.h"
+#include "cainterface.h"
/**
* The signature of the internal call back functions to handle responses from entity handler
*/
OCStackResult observeResult;
uint8_t numResponses;
OCEHResponseHandler ehResponseHandler;
-#ifdef CA_INT
/** Remote Endpoint address **/
CAAddress_t addressInfo;
/** Connectivity of the endpoint**/
CAConnectivityType_t connectivityType;
-#endif
//////////////////////////////////////////////////////////
// IP address & port of client registered for observe //These
OCDevAddr requesterAddr; //Members
-#ifdef CA_INT
// token for the observe request
CAToken_t requestToken;
-#else
- // CoAP token for the observe request //Might
- OCCoAPToken requestToken; //Be
-#endif // CA_INT
// The ID of CoAP pdu //Kept in
uint16_t coapID; //CoAP
uint8_t delayedResNeeded;
OCRequestHandle requestHandle;
} OCServerResponse;
-#ifdef CA_INT
OCServerRequest * GetServerRequestUsingToken (const CAToken_t token);
-#else
-OCServerRequest * GetServerRequestUsingToken (const OCCoAPToken token);
-#endif // CA_INT
OCServerRequest * GetServerRequestUsingHandle (const OCServerRequest * handle);
OCServerResponse * GetServerResponseUsingHandle (const OCServerRequest * handle);
-#ifdef CA_INT
OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method,
uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
unsigned char * reqJSONPayload, CAToken_t * requestToken,
OCDevAddr * requesterAddr, unsigned char * resourceUrl, size_t reqTotalSize,
CAAddress_t *addressInfo, CAConnectivityType_t connectivityType);
-#else
-OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
- uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method,
- uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
- OCQualityOfService qos, unsigned char * query,
- OCHeaderOption * rcvdVendorSpecificHeaderOptions,
- unsigned char * reqJSONPayload, OCCoAPToken * requestToken,
- OCDevAddr * requesterAddr, unsigned char * resourceUrl, size_t reqTotalSize);
-#endif // CA_INT
OCStackResult AddServerResponse (OCServerResponse ** response, OCRequestHandle requestHandle);
#include <logger.h>
#include <ocrandom.h>
-#ifdef CA_INT
#include "cacommon.h"
#include "cainterface.h"
-#else
-#include "occoaptoken.h"
-#endif
#ifdef __cplusplus
extern "C" {
// IP address & port of client registered for observe
OCDevAddr *subAddr;
-#ifdef CA_INT
CAToken_t *token;
-#else // CA_INT
- // token for the observe request
- OCCoAPToken *token;
-#endif // CA_INT
// The result of the observe request
OCStackResult result;
// An array of the received vendor specific header options
uint8_t numRcvdVendorSpecificHeaderOptions;
OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
-#ifdef CA_INT
/** Remote Endpoint address **/
CAAddress_t addressInfo;
/** Connectivity of the endpoint**/
CAConnectivityType_t connectivityType;
-#endif
//////////////////////////////////////////////////////////
// TODO: Consider moving these member to CoAP
// IP address & port of client registered for observe
OCDevAddr requesterAddr;
-#ifdef CA_INT
//token for the observe request
CAToken_t requestToken;
-#else // CA_INT
- // CoAP token for the observe request
- OCCoAPToken requestToken;
-#endif // CA_INT
// The ID of CoAP pdu
uint16_t coapID;
// IP address & port of client registered for observe
OCDevAddr *requesterAddr;
-#ifdef CA_INT
CAToken_t *requestToken;
-#else // CA_INT
- // CoAP token for the observe request
- OCCoAPToken *requestToken;
-#endif // CA_INT
// The ID of CoAP pdu
uint16_t coapID;
// This is the received payload.
unsigned char * bufRes;
-#ifdef CA_INT
// This is the token received OTA.
CAToken_t * rcvdToken;
-#else // CA_INT
- // This is the token received OTA.
- OCCoAPToken * rcvdToken;
-#endif // CA_INT
// this structure will be passed to client
OCClientResponse * clientResponse;
// Internal function prototypes
//-----------------------------------------------------------------------------
-#ifdef CA_INT
OCStackResult OCStackFeedBack(CAToken_t * token, uint8_t status);
-#else // CA_INT
-OCStackResult OCStackFeedBack(OCCoAPToken * token, uint8_t status);
-#endif // CA_INT
OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest);
OCStackResult HandleStackResponses(OCResponse * response);
//TODO: May want to refactor this in upcoming sprints.
//Don't want to expose to application layer that lower level stack is using CoAP.
-#ifdef CA_INT
#define OC_WELL_KNOWN_QUERY "224.0.1.187:5683/oc/core"
#define OC_EXPLICIT_DEVICE_DISCOVERY_URI "224.0.1.187:5683/oc/core/d?rt=core.led"
#define OC_MULTICAST_PREFIX "224.0.1.187:5683"
#define OC_MULTICAST_IP "224.0.1.187"
-#else
-#define OC_WELL_KNOWN_QUERY "coap://224.0.1.187:5683/oc/core"
-#define OC_EXPLICIT_DEVICE_DISCOVERY_URI "coap://224.0.1.187:5683/oc/core/d?rt=core.led"
-#define OC_MULTICAST_PREFIX "coap://224.0.1.187:5683"
-#define OC_MULTICAST_IP "coap://224.0.1.187"
-#endif
-
#define USE_RANDOM_PORT (0)
#ifdef WITH_PRESENCE
#define OC_DEFAULT_PRESENCE_TTL (60)
OC_COAP_ID = (1 << 1)
} OCTransportProtocolID;
-#ifdef CA_INT
/**
* Adaptor types
*/
OC_LE,
OC_ALL //Multicast message: send over all the interfaces.
} OCConnectivityType;
-#endif
/**
* Declares Stack Results & Errors
typedef struct {
// Address of remote server
OCDevAddr * addr;
- #ifdef CA_INT
// Indicates adaptor type on which the response was received
OCConnectivityType connType;
- #endif
// the is the result of our stack, OCStackResult should contain coap/other error codes;
OCStackResult result;
// If associated with observe, this will represent the sequence of notifications from server.
* OC_STACK_INVALID_QUERY - number of resource types specified for filtering presence
* notifications exceeds @ref MAX_PRESENCE_FILTERS.
*/
-#ifdef CA_INT
OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
const char *referenceUri, const char *request, OCConnectivityType conType,
OCQualityOfService qos, OCCallbackData *cbData,
OCHeaderOption * options, uint8_t numOptions);
-#else
- OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
- const char *referenceUri, const char *request, OCQualityOfService qos,
- OCCallbackData *cbData, OCHeaderOption * options, uint8_t numOptions);
-#endif
/**
* Cancel a request associated with a specific @ref OCDoResource invocation.
samples_env.AppendUnique(LIBS = ['tinydtls'])
samples_env.ParseConfig('pkg-config --libs glib-2.0');
-samples_env.AppendUnique(CPPDEFINES = ['CA_INT', 'TB_LOG'])
+samples_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
######################################################################
# Source files and Targets
# TODO-CA Remove -fstack-protector-all before merging to master
CC_FLAGS.debug := -O0 -g3 -Wall -fstack-protector-all -ffunction-sections -fdata-sections -fno-exceptions \
- -std=c++0x -pedantic $(INC_DIRS) -L$(ROOT_DIR)/linux/$(BUILD) -DTB_LOG -DCA_INT
+ -std=c++0x -pedantic $(INC_DIRS) -L$(ROOT_DIR)/linux/$(BUILD) -DTB_LOG
# TODO-CA Remove -fstack-protector-all before merging to master
CC_FLAGS.release := -Os -Wall -fstack-protector-all -fdata-sections -Wl,--gc-sections -Wl,-s -fno-exceptions \
- -std=c++0x $(INC_DIRS) -L$(ROOT_DIR)/linux/$(BUILD) -DTB_LOG -DCA_INT
+ -std=c++0x $(INC_DIRS) -L$(ROOT_DIR)/linux/$(BUILD) -DTB_LOG
LDLIBS += -loctbstack -lpthread -L$(CONNECTIVITY_DIR)/build/out -lconnectivity_abstraction
CPPFLAGS += $(CC_FLAGS.$(BUILD)) $(LDLIBS)
static const char * TEST_APP_UNICAST_DISCOVERY_QUERY = "coap://0.0.0.0:5683/oc/core";
static const char * TEST_APP_UNICAST_DEVICE_DISCOVERY_QUERY = "coap://0.0.0.0:5683/oc/core/d";
-#ifdef CA_INT
static const char * MULTICAST_DEVICE_DISCOVERY_QUERY = "/oc/core/d";
-#else //CA_INT
-static const char * TEST_APP_MULTICAST_DEVICE_DISCOVERY_QUERY = "coap://224.0.1.187:5683/oc/core/d";
-#endif //CA_INT
-#ifdef CA_INT
static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core";
//The following variable determines the interface (wifi, ethernet etc.)
//to be used for sending unicast messages. Default set to WIFI.
static OCConnectivityType OC_CONNTYPE = OC_WIFI;
-#endif
static std::string putPayload = "{\"state\":\"on\",\"power\":5}";
static std::string coapServerIP = "255.255.255.255";
static std::string coapServerPort = "5683";
static void PrintUsage()
{
-#ifdef CA_INT
OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3|4|5|6|7> -c <0|1>");
-#else
- OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3|4|5|6|7>");
-#endif
OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources");
-#ifdef CA_INT
OC_LOG(INFO, TAG, "-c <0|1> : Send unicast messages over Ethernet or WIFI");
-#endif
OC_LOG(INFO, TAG, "-t 1 : Discover Resources");
OC_LOG(INFO, TAG, "-t 2 : Discover Resources and Initiate Nonconfirmable Get Request");
OC_LOG(INFO, TAG, "-t 3 : Discover Resources and Initiate Nonconfirmable Put Requests");
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
ret = OCDoResource(&handle, method, query.str().c_str(), 0,
(method == OC_REST_PUT) ? putPayload.c_str() : NULL,
(OC_CONNTYPE), qos, &cbData, options, numOptions);
-#else
- ret = OCDoResource(&handle, method, query.str().c_str(), 0,
- (method == OC_REST_PUT) ? putPayload.c_str() : NULL,
- qos, &cbData, options, numOptions);
-#endif
if (ret != OC_STACK_OK)
{
remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-#ifdef CA_INT
std::string connectionType = getConnectivityType (clientResponse->connType);
OC_LOG_V(INFO, TAG, "Discovered on %s", connectionType.c_str());
-#endif
OC_LOG_V(INFO, TAG,
"Device =============> Discovered %s @ %d.%d.%d.%d:%d",
clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
break;
}
}
-#ifdef CA_INT
return OC_STACK_KEEP_TRANSACTION;
-#else
- return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION ;
-#endif
-
}
OCStackApplicationResult DeviceDiscoveryReqCB (void* ctx, OCDoHandle handle,
else
{
-#ifdef CA_INT
strncpy(szQueryUri, MULTICAST_DEVICE_DISCOVERY_QUERY,
(strlen(MULTICAST_DEVICE_DISCOVERY_QUERY) + 1));
-
-#else
- strncpy(szQueryUri, TEST_APP_MULTICAST_DEVICE_DISCOVERY_QUERY,
- (strlen(TEST_APP_MULTICAST_DEVICE_DISCOVERY_QUERY) + 1));
-#endif
}
-#ifdef CA_INT
if(UNICAST_DISCOVERY)
{
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
OC_LOW_QOS, &cbData, NULL, 0);
}
-#else
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0);
-#endif
if (ret != OC_STACK_OK)
{
}
else
{
-#ifdef CA_INT
strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY);
-#else
- strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
-#endif
}
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
if(UNICAST_DISCOVERY)
{
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
OC_LOW_QOS, &cbData, NULL, 0);
}
-#else
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0);
-#endif
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
uint8_t ifname[] = "eth0";
int opt;
-#ifdef CA_INT
while ((opt = getopt(argc, argv, "u:t:c:")) != -1)
-#else
- while ((opt = getopt(argc, argv, "u:t:")) != -1)
-#endif
{
switch(opt)
{
case 't':
TEST_CASE = atoi(optarg);
break;
- #ifdef CA_INT
case 'c':
OC_CONNTYPE = OCConnectivityType(atoi(optarg));
break;
- #endif
default:
PrintUsage();
return -1;
//----------------------------------------------------------------------------
// Function prototype
//----------------------------------------------------------------------------
-#ifdef CA_INT
std::string getConnectivityType (OCConnectivityType connType);
-#endif
/* call getResult in common.cpp to get the result in string format. */
const char *getResult(OCStackResult result);
static std::string coapServerPort = "5683";
static std::string coapServerResource = "/a/led";
-#ifdef CA_INT
//The following variable determines the interface (wifi, ethernet etc.)
//to be used for sending unicast messages. Default set to WIFI.
static OCConnectivityType OC_CONNTYPE = OC_WIFI;
static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core";
-#endif
int gQuitFlag = 0;
static void PrintUsage()
{
-#ifdef CA_INT
OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1>");
-#else
- OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3>");
-#endif
OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources");
-#ifdef CA_INT
OC_LOG(INFO, TAG, "-c <0|1> : Send unicast messages over Ethernet or WIFI");
-#endif
OC_LOG(INFO, TAG, "-t 1 : Discover Resources");
OC_LOG(INFO, TAG, "-t 2 : Discover Resources and"
" Initiate Nonconfirmable Get/Put/Post Requests");
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
ret = OCDoResource(&handle, method, query.str().c_str(), 0,
(method == OC_REST_PUT || method == OC_REST_POST) ? putPayload.c_str() : NULL,
OC_CONNTYPE, qos, &cbData, options, numOptions);
-#else
- ret = OCDoResource(&handle, method, query.str().c_str(), 0,
- (method == OC_REST_PUT || method == OC_REST_POST) ? putPayload.c_str() : NULL,
- qos, &cbData, options, numOptions);
-#endif
if (ret != OC_STACK_OK)
{
}
else
{
-#ifdef CA_INT
strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY);
-#else
- strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
-#endif
}
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
if (UNICAST_DISCOVERY)
{
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_CONNTYPE),
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, (OC_ALL),
OC_LOW_QOS, &cbData, NULL, 0);
}
-#else
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0);
-#endif
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
uint8_t ifname[] = "eth0";
int opt;
-#ifdef CA_INT
while ((opt = getopt(argc, argv, "u:t:c:")) != -1)
-#else
- while ((opt = getopt(argc, argv, "u:t:")) != -1)
-#endif
{
switch(opt)
{
case 't':
TEST_CASE = atoi(optarg);
break;
- #ifdef CA_INT
case 'c':
OC_CONNTYPE = OCConnectivityType(atoi(optarg));
break;
- #endif
default:
PrintUsage();
return -1;
static std::string putPayload = "{\"state\":\"off\",\"power\":\"0\"}";
-#ifdef CA_INT
//The following variable determines the interface (wifi, ethernet etc.)
//to be used for sending unicast messages. Default set to WIFI.
static OCConnectivityType OC_CONNTYPE = OC_WIFI;
static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core";
-#endif
// The handle for the observe registration
OCDoHandle gObserveDoHandle;
void PrintUsage()
{
-#ifdef CA_INT
OC_LOG(INFO, TAG, "Usage : occlientcoll -t <Test Case> -c <CA connectivity Type>");
OC_LOG(INFO, TAG, "-c <0|1> : Send messages over Ethernet or WIFI");
-#else
- OC_LOG(INFO, TAG, "Usage : occlientcoll -t <Test Case>");
-#endif
OC_LOG(INFO, TAG, "Test Case 1 : Discover Resources && Initiate GET Request on an"\
"available resource using default interface.");
OC_LOG(INFO, TAG, "Test Case 2 : Discover Resources && Initiate GET Request on an"\
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_CONNTYPE, OC_LOW_QOS,
&cbData, NULL, 0);
-#else
- ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS,
- &cbData, NULL, 0);
-#endif
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
cbData.cd = NULL;
OC_LOG_V(INFO, TAG, "OBSERVE payload from client = %s ", putPayload.c_str());
-#ifdef CA_INT
ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_CONNTYPE,
OC_LOW_QOS, &cbData, NULL, 0);
-#else
- ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_LOW_QOS,
- &cbData, NULL, 0);
-#endif
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
cbData.cd = NULL;
OC_LOG_V(INFO, TAG, "PUT payload from client = %s ", putPayload.c_str());
-#ifdef CA_INT
ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(),
OC_CONNTYPE, OC_LOW_QOS, &cbData, NULL, 0);
-#else
- ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(),
- OC_LOW_QOS, &cbData, NULL, 0);
-#endif
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
cbData.cb = getReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_CONNTYPE, OC_LOW_QOS,
&cbData, NULL, 0);
-#else
- ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_LOW_QOS,
- &cbData, NULL, 0);
-#endif
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
/* Start a discovery query*/
char szQueryUri[64] = { 0 };
-#ifdef CA_INT
strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY);
-#else
- strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
-#endif
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_ALL,
OC_LOW_QOS,
&cbData, NULL, 0);
-#else
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS,
- &cbData, NULL, 0);
-#endif
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
uint8_t ifname[] = "eth0";
int opt;
-#ifdef CA_INT
while ((opt = getopt(argc, argv, "t:c:")) != -1)
-#else
- while ((opt = getopt(argc, argv, "t:")) != -1)
-#endif
{
switch(opt)
{
case 't':
TEST = atoi(optarg);
break;
- #ifdef CA_INT
case 'c':
OC_CONNTYPE = OCConnectivityType(atoi(optarg));
break;
- #endif
default:
PrintUsage();
return -1;
static std::string coapServerPort = "5683";
static std::string coapServerResource = "/a/led";
-#ifdef CA_INT
//The following variable determines the interface (wifi, ethernet etc.)
//to be used for sending unicast messages. Default set to WIFI.
static OCConnectivityType OC_CONNTYPE = OC_WIFI;
static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core";
-#endif
int gQuitFlag = 0;
static void PrintUsage()
{
-#ifdef CA_INT
OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3> -c <0|1>");
OC_LOG(INFO, TAG, "-c <0|1> : Send unicast messages over Ethernet or WIFI");
-#else
- OC_LOG(INFO, TAG, "Usage : occlient -u <0|1> -t <1|2|3>");
-#endif
OC_LOG(INFO, TAG, "-u <0|1> : Perform multicast/unicast discovery of resources");
OC_LOG(INFO, TAG, "-t 1 : Discover Resources");
OC_LOG(INFO, TAG, "-t 2 : Discover Resources and Initiate Nonconfirmable Get Request");
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
ret = OCDoResource(&handle, method, query.str().c_str(), 0,
NULL, OC_CONNTYPE, qos, &cbData, options, numOptions);
-#else
- ret = OCDoResource(&handle, method, query.str().c_str(), 0,
- NULL, qos, &cbData, options, numOptions);
-#endif
if (ret != OC_STACK_OK)
{
}
else
{
-#ifdef CA_INT
strcpy(szQueryUri, MULTICAST_RESOURCE_DISCOVERY_QUERY);
-#else
- strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
-#endif
}
cbData.cb = discoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
-#ifdef CA_INT
if(UNICAST_DISCOVERY)
{
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_CONNTYPE,
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_ALL,
OC_LOW_QOS, &cbData, NULL, 0);
}
-#else
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_LOW_QOS, &cbData, NULL, 0);
-#endif
if (ret != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack resource error");
uint8_t ifname[] = "eth0";
int opt;
-#ifdef CA_INT
while ((opt = getopt(argc, argv, "u:t:c:")) != -1)
-#else
- while ((opt = getopt(argc, argv, "u:t:")) != -1)
-#endif
{
switch(opt)
{
case 't':
TEST_CASE = atoi(optarg);
break;
- #ifdef CA_INT
case 'c':
OC_CONNTYPE = OCConnectivityType(atoi(optarg));
break;
- #endif
default:
PrintUsage();
return -1;
if target_os in ['darwin', 'ios']:
samples_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
-samples_env.AppendUnique(CPPDEFINES = ['CA_INT', 'CA_INT_DTLS', 'TB_LOG'])
+samples_env.AppendUnique(CPPDEFINES = ['CA_INT_DTLS', 'TB_LOG'])
######################################################################
# Source files and Targets
ret = OCDoResource(&handle, method, query.str().c_str(), 0,
(method == OC_REST_PUT || method == OC_REST_POST) ? putPayload.c_str() : NULL,
-#ifdef CA_INT
(OC_WIFI),
-#endif
qos, &cbData, options, numOptions);
if (ret != OC_STACK_OK)
cbData.context = NULL;
cbData.cd = NULL;
ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0,
-#ifdef CA_INT
(OC_WIFI),
-#endif
OC_LOW_QOS, &cbData, NULL, 0);
if (ret != OC_STACK_OK)
{
#include "ocmalloc.h"
#include <string.h>
-#ifdef CA_INT
#include "cacommon.h"
#include "cainterface.h"
-#endif
/// Module Name
#define TAG PCF("occlientcb")
OCMulticastNode * mcPresenceNodes = NULL;
OCStackResult
-#ifdef CA_INT
AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
CAToken_t * token, OCDoHandle *handle, OCMethod method,
unsigned char * requestUri, unsigned char * resourceTypeName)
-#else // CA_INT
-AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
- OCCoAPToken * token, OCDoHandle *handle, OCMethod method,
- unsigned char * requestUri, unsigned char * resourceTypeName)
-#endif // CA_INT
{
ClientCB *cbNode = NULL;
cbNode->callBack = cbData->cb;
cbNode->context = cbData->context;
cbNode->deleteCallback = cbData->cd;
-#ifdef CA_INT
//Note: token memory is allocated in the caller OCDoResource
//but freed in DeleteClientCB
cbNode->token = *token;
-#else // CA_INT
- memcpy(&(cbNode->token), token, sizeof(OCCoAPToken));
-#endif // CA_INT
cbNode->handle = *handle;
cbNode->method = method;
cbNode->sequenceNumber = 0;
if(cbNode) {
LL_DELETE(cbList, cbNode);
OC_LOG(INFO, TAG, PCF("deleting tokens"));
-#ifdef CA_INT
CADestroyToken (cbNode->token);
OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)cbNode->token, CA_MAX_TOKEN_LEN);
-#else
- OC_LOG_BUFFER(INFO, TAG, cbNode->token.token, cbNode->token.tokenLength);
-#endif // CA_INT
OCFree(cbNode->handle);
OCFree(cbNode->requestUri);
if(cbNode->deleteCallback)
}
}
-#ifdef CA_INT
ClientCB* GetClientCB(const CAToken_t * token, OCDoHandle handle, const unsigned char * requestUri)
-#else // CA_INT
-ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, const unsigned char * requestUri)
-#endif // CA_INT
{
ClientCB* out = NULL;
if(token) {
LL_FOREACH(cbList, out) {
OC_LOG(INFO, TAG, PCF("comparing tokens"));
-#ifdef CA_INT
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);
if(memcmp(out->token, *token, CA_MAX_TOKEN_LEN) == 0)
{
return out;
}
-#else // CA_INT
- OC_LOG_BUFFER(INFO, TAG, token->token, token->tokenLength);
- OC_LOG_BUFFER(INFO, TAG, out->token.token, out->token.tokenLength);
- if((out->token.tokenLength == token->tokenLength) &&
- (memcmp(out->token.token, token->token, token->tokenLength) == 0) ) {
- return out;
- }
-#endif // CA_INT
}
}
else if(handle) {
OCResource* temp = collResource->rsrcResources[i];
if (temp)
{
-#ifdef CA_INT
//TODO : Update needed here to get correct connectivity type
//from ServerRequest data structure
ret = BuildVirtualResourceResponse(temp, filterOn, filterValue,
(char*)ptr, &remaining, CA_WIFI );
-#else
- ret = BuildVirtualResourceResponse(temp, filterOn, filterValue,
- (char*)ptr, &remaining);
-#endif
if (ret != OC_STACK_OK)
{
break;
#endif
qos = DetermineObserverQoS(method, resourceObserver, qos);
-#ifdef CA_INT
result = AddServerRequest(&request, 0, 0, 0, 1, OC_REST_GET,
0, resPtr->sequenceNum, qos, resourceObserver->query,
NULL, NULL,
&resourceObserver->token, resourceObserver->addr,
resourceObserver->resUri, 0,
&(resourceObserver->addressInfo), resourceObserver->connectivityType);
-#else
- result = AddServerRequest(&request, 0, 0, 0, 1, OC_REST_GET,
- 0, resPtr->sequenceNum, qos, resourceObserver->query,
- NULL, NULL,
- &resourceObserver->token, resourceObserver->addr,
- resourceObserver->resUri, 0);
-#endif // CA_INT
request->observeResult = OC_STACK_OK;
if(request && result == OC_STACK_OK)
unsigned char presenceResBuf[MAX_RESPONSE_LENGTH] = {0};
//This is effectively the implementation for the presence entity handler.
OC_LOG(DEBUG, TAG, PCF("This notification is for Presence"));
-#ifdef CA_INT
result = AddServerRequest(&request, 0, 0, 0, 1, OC_REST_GET,
0, resPtr->sequenceNum, qos, resourceObserver->query,
NULL, NULL,
resourceObserver->resUri, 0,
&(resourceObserver->addressInfo), resourceObserver->connectivityType);
-#else
- result = AddServerRequest(&request, 0, 0, 0, 1, OC_REST_GET,
- 0, OC_OBSERVE_NO_OPTION, OC_LOW_QOS,
- NULL, NULL, NULL, &resourceObserver->token,
- resourceObserver->addr, resourceObserver->resUri, 0);
-#endif
if(result == OC_STACK_OK)
{
// we create the payload here
qos = DetermineObserverQoS(OC_REST_GET, observation, qos);
-#ifdef CA_INT
result = AddServerRequest(&request, 0, 0, 0, 1, OC_REST_GET,
0, resource->sequenceNum, qos, observation->query,
NULL, NULL, &observation->token,
observation->addr, observation->resUri, 0,
&(observation->addressInfo), observation->connectivityType);
-#else
- result = AddServerRequest(&request, 0, 0, 0, 1, OC_REST_GET,
- 0, resource->sequenceNum, qos, observation->query,
- NULL, NULL, &observation->token,
- observation->addr, observation->resUri, 0);
-#endif //CA_INT
request->observeResult = OC_STACK_OK;
if(request && result == OC_STACK_OK)
return OC_STACK_ERROR;
}
-#ifdef CA_INT
OCStackResult AddObserver (const char *resUri,
const char *query,
OCObservationId obsId,
OCQualityOfService qos,
CAAddress_t *addressInfo,
CAConnectivityType_t connectivityType)
-#else
-OCStackResult AddObserver (const char *resUri,
- const char *query,
- OCObservationId obsId,
- OCCoAPToken *token,
- OCDevAddr *addr,
- OCResource *resHandle,
- OCQualityOfService qos)
-#endif // CA_INT
{
ResourceObserver *obsNode = NULL;
memcpy (obsNode->query, query, strlen(query)+1);
}
-#ifdef CA_INT
obsNode->token = (CAToken_t)OCMalloc(CA_MAX_TOKEN_LEN+1);
VERIFY_NON_NULL (obsNode->token);
memset(obsNode->token, 0, CA_MAX_TOKEN_LEN + 1);
memcpy(obsNode->token, *token, CA_MAX_TOKEN_LEN);
-#else
- obsNode->token.tokenLength = token->tokenLength;
- memcpy (obsNode->token.token, token->token, token->tokenLength);
-#endif // CA_INT
obsNode->addr = (OCDevAddr *)OCMalloc(sizeof(OCDevAddr));
VERIFY_NON_NULL (obsNode->addr);
memcpy (obsNode->addr, addr, sizeof(OCDevAddr));
-#ifdef CA_INT
obsNode->addressInfo = *addressInfo;
obsNode->connectivityType = connectivityType;
-#endif
obsNode->resource = resHandle;
LL_APPEND (serverObsList, obsNode);
return OC_STACK_OK;
return NULL;
}
-#ifdef CA_INT
ResourceObserver* GetObserverUsingToken (const CAToken_t * token)
-#else
-ResourceObserver* GetObserverUsingToken (const OCCoAPToken * token)
-#endif
{
ResourceObserver *out = NULL;
{
LL_FOREACH (serverObsList, out)
{
-#ifdef CA_INT
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);
{
return out;
}
-#else
- OC_LOG(INFO, TAG,PCF("comparing tokens"));
- OC_LOG_BUFFER(INFO, TAG, token->token, token->tokenLength);
- OC_LOG_BUFFER(INFO, TAG, out->token.token, out->token.tokenLength);
- if((out->token.tokenLength == token->tokenLength) &&
- (memcmp(out->token.token, token->token, token->tokenLength) == 0))
- {
- return out;
- }
-#endif // CA_INT
}
}
OC_LOG(INFO, TAG, PCF("Observer node not found!!"));
return NULL;
}
-#ifdef CA_INT
OCStackResult DeleteObserverUsingToken (CAToken_t * token)
-#else
-OCStackResult DeleteObserverUsingToken (OCCoAPToken * token)
-#endif
{
ResourceObserver *obsNode = NULL;
if (obsNode)
{
OC_LOG_V(INFO, TAG, PCF("deleting tokens"));
-#ifdef CA_INT
OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)obsNode->token, CA_MAX_TOKEN_LEN);
-#else
- OC_LOG_BUFFER(INFO, TAG, obsNode->token.token, obsNode->token.tokenLength);
-#endif
LL_DELETE (serverObsList, obsNode);
OCFree(obsNode->resUri);
OCFree(obsNode->query);
serverObsList = NULL;
}
-#ifdef CA_INT
OCStackResult
CreateObserveHeaderOption (CAHeaderOption_t **caHdrOpt,
OCHeaderOption *ocHdrOpt,
}
return OC_STACK_OK;
}
-#endif // CA_INT
#include "debug.h"
#include "cJSON.h"
-#ifdef CA_INT
- #include "cacommon.h"
- #include "cainterface.h"
-#endif
+#include "cacommon.h"
+#include "cainterface.h"
/// Module Name
return OC_EH_OK; // Making sure that the Default EH and the Vendor EH have matching signatures
}
-#ifdef CA_INT
/* This method will return the port at which the secure resource is hosted */
static OCStackResult GetSecurePortInfo(CAConnectivityType_t connType, uint32_t *port)
{
free(info);
return ret;
}
-#endif
static OCStackResult ValidateUrlQuery (unsigned char *url, unsigned char *query,
uint8_t *filterOn, char **filterValue)
}
-#ifdef CA_INT
OCStackResult
BuildVirtualResourceResponse(OCResource *resourcePtr, uint8_t filterOn,
char *filterValue, char * out, uint16_t *remaining,
CAConnectivityType_t connType )
-#else
-OCStackResult
-BuildVirtualResourceResponse(OCResource *resourcePtr, uint8_t filterOn,
- char *filterValue, char * out, uint16_t *remaining)
-#endif
{
OCResourceType *resourceTypePtr;
OCResourceInterface *interfacePtr;
if (resourcePtr->resourceProperties & OC_SECURE) {
cJSON_AddNumberToObject (propObj, OC_RSRVD_SECURE, OC_RESOURCE_SECURE);
//Set the IP port also as secure resources are hosted on a different port
-#ifdef CA_INT
uint32_t port;
if (GetSecurePortInfo (connType, &port) == OC_STACK_OK) {
-#else
- uint16_t port;
- if (OCGetResourceEndPointInfo (resourcePtr, &port) == OC_STACK_OK) {
-#endif
cJSON_AddNumberToObject (propObj, OC_RSRVD_HOSTING_PORT, port);
}
}
remaining--;
}
firstLoopDone = 1;
-#ifdef CA_INT
result = BuildVirtualResourceResponse(resource, filterOn, filterValue,
(char*)ptr, &remaining, request->connectivityType );
-#else
- result = BuildVirtualResourceResponse(resource, filterOn, filterValue,
- (char*)ptr, &remaining);
-#endif
if (result != OC_STACK_OK)
{
OC_LOG(INFO, TAG, PCF("Registering observation requested"));
result = GenerateObserverId(&ehRequest.obsInfo.obsId);
VERIFY_SUCCESS(result, OC_STACK_OK);
-#ifdef CA_INT
result = AddObserver ((const char*)(request->resourceUrl),
(const char *)(request->query),
ehRequest.obsInfo.obsId, &request->requestToken,
&request->requesterAddr, resource, request->qos,
&request->addressInfo, request->connectivityType);
-#else
- result = AddObserver ((const char*)(request->resourceUrl),
- (const char *)(request->query),
- ehRequest.obsInfo.obsId, &request->requestToken,
- &request->requesterAddr, resource, request->qos);
-#endif //CA_INT
if(result == OC_STACK_OK)
{
OC_LOG(DEBUG, TAG, PCF("Added observer successfully"));
#include "ocresourcehandler.h"
-#ifdef CA_INT
#include "cacommon.h"
#include "cainterface.h"
-#endif
// Module Name
#define VERIFY_NON_NULL(arg) { if (!arg) {OC_LOG(FATAL, TAG, #arg " is NULL"); goto exit;} }
static struct OCServerRequest * serverRequestList = NULL;
static struct OCServerResponse * serverResponseList = NULL;
-#ifdef CA_INT
OCServerRequest * GetServerRequestUsingToken (const CAToken_t token)
-#else // CA_INT
-OCServerRequest * GetServerRequestUsingToken (const OCCoAPToken token)
-#endif // CA_INT
{
OCServerRequest * out = NULL;
LL_FOREACH (serverRequestList, out)
{
-#ifdef CA_INT
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);
{
return out;
}
-#else // CA_INT
- OC_LOG(INFO, TAG,PCF("comparing tokens"));
- OC_LOG_BUFFER(INFO, TAG, token.token, token.tokenLength);
- OC_LOG_BUFFER(INFO, TAG, out->requestToken.token, out->requestToken.tokenLength);
- if((out->requestToken.tokenLength == token.tokenLength) &&
- (memcmp(out->requestToken.token, token.token, token.tokenLength) == 0))
- {
- return out;
- }
-#endif // CA_INT
}
OC_LOG(INFO, TAG, PCF("Server Request not found!!"));
return NULL;
return NULL;
}
-#ifdef CA_INT
OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method,
uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
unsigned char * reqJSONPayload, CAToken_t * requestToken,
OCDevAddr * requesterAddr, unsigned char * resourceUrl, size_t reqTotalSize,
CAAddress_t *addressInfo, CAConnectivityType_t connectivityType)
-#else // CA_INT
-OCStackResult AddServerRequest (OCServerRequest ** request, uint16_t coapID,
- uint8_t delayedResNeeded, uint8_t secured, uint8_t notificationFlag, OCMethod method,
- uint8_t numRcvdVendorSpecificHeaderOptions, uint32_t observationOption,
- OCQualityOfService qos, unsigned char * query,
- OCHeaderOption * rcvdVendorSpecificHeaderOptions,
- unsigned char * reqJSONPayload, OCCoAPToken * requestToken,
- OCDevAddr * requesterAddr, unsigned char * resourceUrl, size_t reqTotalSize)
-#endif // CA_INT
{
OCServerRequest * serverRequest = NULL;
serverRequest->requestComplete = 0;
if(requestToken)
{
-#ifdef CA_INT
serverRequest->requestToken = (CAToken_t)OCMalloc(CA_MAX_TOKEN_LEN+1);
VERIFY_NON_NULL (serverRequest->requestToken);
memset(serverRequest->requestToken, 0, CA_MAX_TOKEN_LEN + 1);
memcpy(serverRequest->requestToken, *requestToken, CA_MAX_TOKEN_LEN);
-#else // CA_INT
- memcpy(&serverRequest->requestToken, requestToken, sizeof(OCCoAPToken));
-#endif // CA_INT
}
if(requesterAddr)
{
{
memcpy(serverRequest->resourceUrl, resourceUrl, strlen((const char *)resourceUrl) + 1);
}
-#ifdef CA_INT
if (addressInfo)
{
serverRequest->addressInfo = *addressInfo;
}
serverRequest->connectivityType = connectivityType;
-#endif
*request = serverRequest;
OC_LOG(INFO, TAG, PCF("Server Request Added!!"));
OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse)
{
-#ifdef CA_INT
OCStackResult result = OC_STACK_ERROR;
CARemoteEndpoint_t responseEndpoint;
CAResponseInfo_t responseInfo;
//Delete the request
FindAndDeleteServerRequest(serverRequest);
return result;
-#else
- OCStackResult result = OC_STACK_ERROR;
- OCServerProtocolResponse protocolResponse;
- memset(&protocolResponse, 0, sizeof(OCServerProtocolResponse));
-
- OC_LOG_V(INFO, TAG, "Inside HandleSingleResponse: %s", ehResponse->payload);
-
- OCServerRequest *serverRequest = (OCServerRequest *)ehResponse->requestHandle;
- // Format protocol response structure with data needed for
- // sending the response
- protocolResponse.qos = serverRequest->qos;
-
- if((OCResource *)ehResponse->resourceHandle &&
- ((OCResource *)ehResponse->resourceHandle)->resourceProperties == (OCResourceProperty) 0)
- {
- ehResponse->ehResult = OC_EH_RESOURCE_DELETED;
- }
- protocolResponse.result = EntityHandlerCodeToOCStackCode(ehResponse->ehResult);
- protocolResponse.requesterAddr = &serverRequest->requesterAddr;
- protocolResponse.requestToken = &serverRequest->requestToken;
- protocolResponse.numSendVendorSpecificHeaderOptions = ehResponse->numSendVendorSpecificHeaderOptions;
- protocolResponse.sendVendorSpecificHeaderOptions = ehResponse->sendVendorSpecificHeaderOptions;
- protocolResponse.resourceUri = ehResponse->resourceUri;
- protocolResponse.delayedResNeeded = serverRequest->delayedResNeeded;
- protocolResponse.secured = serverRequest->secured;
- protocolResponse.slowFlag = serverRequest->slowFlag;
- protocolResponse.notificationFlag = serverRequest->notificationFlag;
-
- //should we put the prefix and suffix here?
- protocolResponse.payload = (unsigned char *) OCMalloc(MAX_RESPONSE_LENGTH);
- if(!protocolResponse.payload)
- {
- return OC_STACK_NO_MEMORY;
- }
- strcpy((char *)protocolResponse.payload, (const char *)OC_JSON_PREFIX);
- strcat((char *)protocolResponse.payload, (const char *)ehResponse->payload);
- strcat((char *)protocolResponse.payload, (const char *)OC_JSON_SUFFIX);
- protocolResponse.payloadSize = strlen((const char *)protocolResponse.payload) + 1;
- protocolResponse.resourceUri = ehResponse->resourceUri;
-
- //revise the following
- protocolResponse.coapID = serverRequest->coapID;
- if(serverRequest->observeResult == OC_STACK_OK)
- {
- protocolResponse.observationOption = serverRequest->observationOption;
- }
- else
- {
- protocolResponse.observationOption = OC_OBSERVE_NO_OPTION;
- }
- // Make call to OCCoAP layer
- result = OCDoCoAPResponse(&protocolResponse);
-
- OCFree(protocolResponse.payload);
- //Delete the request
- FindAndDeleteServerRequest(serverRequest);
- return result;
-#endif
}
OCStackResult HandleAggregateResponse(OCEntityHandlerResponse * ehResponse)
#include "ocmalloc.h"
#include "ocserverrequest.h"
-#ifdef CA_INT
- #include "cacommon.h"
- #include "cainterface.h"
- #include <arpa/inet.h>
-#endif
+#include "cacommon.h"
+#include "cainterface.h"
+#include <arpa/inet.h>
//-----------------------------------------------------------------------------
// This internal function is called to update the stack with the status of
// observers and communication failures
-#ifdef CA_INT
OCStackResult OCStackFeedBack(CAToken_t * token, uint8_t status)
-#else // CA_INT
-OCStackResult OCStackFeedBack(OCCoAPToken * token, uint8_t status)
-#endif // CA_INT
{
OCStackResult result = OC_STACK_ERROR;
ResourceObserver * observer = NULL;
return result;
}
-#ifdef CA_INT
OCStackResult CAToOCStackResult(CAResponseResult_t caCode)
{
OCStackResult ret = OC_STACK_ERROR;
OC_LOG(INFO, TAG, PCF("Exit HandleCARequests"));
}
-#endif // CA_INT
-
//This function will be called back by occoap layer when a request is received
OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest)
{
if(!request)
{
OC_LOG(INFO, TAG, PCF("This is a new Server Request"));
-#ifdef CA_INT
result = AddServerRequest(&request, protocolRequest->coapID,
protocolRequest->delayedResNeeded, protocolRequest->secured, 0,
protocolRequest->method, protocolRequest->numRcvdVendorSpecificHeaderOptions,
&protocolRequest->requesterAddr, protocolRequest->resourceUrl,
protocolRequest->reqTotalSize,
&protocolRequest->addressInfo, protocolRequest->connectivityType);
-#else
- result = AddServerRequest(&request, protocolRequest->coapID,
- protocolRequest->delayedResNeeded, protocolRequest->secured, 0,
- protocolRequest->method, protocolRequest->numRcvdVendorSpecificHeaderOptions,
- protocolRequest->observationOption, protocolRequest->qos,
- protocolRequest->query, protocolRequest->rcvdVendorSpecificHeaderOptions,
- protocolRequest->reqJSONPayload, &protocolRequest->requestToken,
- &protocolRequest->requesterAddr, protocolRequest->resourceUrl,
- protocolRequest->reqTotalSize);
-#endif
if (OC_STACK_OK != result)
{
OC_LOG(ERROR, TAG, PCF("Error adding server request"));
}
OCSeedRandom();
-#ifdef CA_INT
CAInitialize();
//It is ok to select network to CA_WIFI for now
CAResult_t caResult = CASelectNetwork(CA_WIFI|CA_ETHERNET);
result = OC_STACK_ERROR;
}
}
-#else
- switch (mode)
- {
- case OC_CLIENT:
- OC_LOG(INFO, TAG, PCF("Client mode"));
- break;
- case OC_SERVER:
- OC_LOG(INFO, TAG, PCF("Server mode"));
- break;
- case OC_CLIENT_SERVER:
- OC_LOG(INFO, TAG, PCF("Client-server mode"));
- break;
- default:
- OC_LOG(ERROR, TAG, PCF("Invalid mode"));
- return OC_STACK_ERROR;
- break;
- }
-
- // Make call to OCCoAP layer
- result = OCInitCoAP(ipAddr, (uint16_t) port, myStackMode);
-#endif //CA_INT
myStackMode = mode;
defaultDeviceHandler = NULL;
-#if defined(CA_INT) && defined(__WITH_DTLS__)
+#if defined(__WITH_DTLS__)
caResult = CARegisterDTLSCredentialsHandler(GetDtlsPskCredentials);
result = (caResult == CA_STATUS_OK) ? OC_STACK_OK : OC_STACK_ERROR;
-#endif //(CA_INT) && (__WITH_DTLS__)
+#endif // (__WITH_DTLS__)
+
#ifdef WITH_PRESENCE
PresenceTimeOutSize = sizeof(PresenceTimeOut)/sizeof(PresenceTimeOut[0]) - 1;
#endif // WITH_PRESENCE
// Free memory dynamically allocated for resources
deleteAllResources();
DeleteDeviceInfo();
-#ifdef CA_INT
CATerminate();
//CATerminate does not return any error code. It is OK to assign result to OC_STACK_OK.
result = OC_STACK_OK;
-#else //CA_INT
- result = OCStopCoAP();
-#endif //CA_INT
if (result == OC_STACK_OK)
{
* Note: IN case of CA, when using multicast, the required URI should not contain IP address.
* Instead, it just contains the URI to the resource such as "/oc/core".
*/
-#ifdef CA_INT
OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
const char *referenceUri, const char *request, OCConnectivityType conType,
OCQualityOfService qos, OCCallbackData *cbData,
OCHeaderOption * options, uint8_t numOptions)
-#else
-OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
- const char *referenceUri, const char *request,
- OCQualityOfService qos, OCCallbackData *cbData,
- OCHeaderOption * options, uint8_t numOptions)
-#endif
{
OCStackResult result = OC_STACK_ERROR;
ClientCB *clientCB = NULL;
unsigned char * query = NULL;
char * newUri = (char *)requiredUri;
(void) referenceUri;
-#ifdef CA_INT
CARemoteEndpoint_t* endpoint = NULL;
CAResult_t caResult;
CAToken_t token = NULL;
// To track if memory is allocated for additional header options
uint8_t hdrOptionMemAlloc = 0;
-#else
-OCCoAPToken token;
-#endif // CA_INT
OC_LOG(INFO, TAG, PCF("Entering OCDoResource"));
goto exit;
}
-#ifdef CA_INT
memset(&requestData, 0, sizeof(CAInfo_t));
memset(&requestInfo, 0, sizeof(CARequestInfo_t));
memset(&grpEnd, 0, sizeof(CAGroupEndpoint_t));
goto exit;
}
-#else // CA_INT
-
- // Generate token which will be used by OCStack to match responses received
- // with the request
- OCGenerateCoAPToken(&token);
-
- if((result = AddClientCB(&clientCB, cbData, &token, handle, method, requestUri, resourceType))
- != OC_STACK_OK)
- {
- result = OC_STACK_NO_MEMORY;
- goto exit;
- }
-
- // Make call to OCCoAP layer
- result = OCDoCoAPResource(method, qos, &token, newUri, request, options, numOptions);
-#endif // CA_INT
-
exit:
if(newUri != requiredUri)
{
OC_LOG(ERROR, TAG, PCF("OCDoResource error"));
FindAndDeleteClientCB(clientCB);
}
-#ifdef CA_INT
CADestroyRemoteEndpoint(endpoint);
OCFree(grpEnd.resourceUri);
if (hdrOptionMemAlloc)
{
OCFree(requestData.options);
}
-#endif // CA_INT
return result;
}
* Remove the callback associated on client side.
*/
OCStackResult ret = OC_STACK_OK;
-#ifdef CA_INT
CARemoteEndpoint_t* endpoint = NULL;
CAResult_t caResult;
CAInfo_t requestData;
CARequestInfo_t requestInfo;
// Track if memory is allocated for additional header options
uint8_t hdrOptionMemAlloc = 0;
-#endif // CA_INT
if(!handle) {
return OC_STACK_INVALID_PARAM;
{
case OC_REST_OBSERVE:
case OC_REST_OBSERVE_ALL:
- #ifdef CA_INT
//TODO-CA : Why CA_WIFI alone?
caResult = CACreateRemoteEndpoint((char *)clientCB->requestUri, CA_WIFI,
&endpoint);
{
ret = OC_STACK_OK;
}
- #else // CA_INT
- if(qos == OC_HIGH_QOS)
- {
- ret = OCDoCoAPResource(OC_REST_CANCEL_OBSERVE, qos,
- &(clientCB->token), (const char *) clientCB->requestUri, NULL, options,
- numOptions);
- }
- else
- {
- FindAndDeleteClientCB(clientCB);
- }
- break;
- #endif // CA_INT
#ifdef WITH_PRESENCE
case OC_REST_PRESENCE:
FindAndDeleteClientCB(clientCB);
return OC_STACK_INVALID_METHOD;
}
}
-#ifdef CA_INT
CADestroyRemoteEndpoint(endpoint);
if (hdrOptionMemAlloc)
{
OCFree(requestData.options);
}
-#endif // CA_INT
return ret;
}
#ifdef WITH_PRESENCE
-#ifdef CA_INT
OCStackResult OCProcessPresence()
{
OCStackResult result = OC_STACK_OK;
}
return result;
}
-#else
-OCStackResult OCProcessPresence()
-{
- OCStackResult result = OC_STACK_OK;
- uint8_t ipAddr[4] = { 0 };
- uint16_t port = 0;
-
- ClientCB* cbNode = NULL;
- OCDevAddr dst;
- OCClientResponse clientResponse;
- OCResponse * response = NULL;
-
- LL_FOREACH(cbList, cbNode) {
- if(OC_REST_PRESENCE == cbNode->method)
- {
- if(cbNode->presence)
- {
- uint32_t now = GetTime(0);
- OC_LOG_V(DEBUG, TAG, "----------------this TTL level %d", cbNode->presence->TTLlevel);
- OC_LOG_V(DEBUG, TAG, "----------------current ticks %d", now);
-
-
- if(cbNode->presence->TTLlevel >= (PresenceTimeOutSize + 1))
- {
- goto exit;
- }
-
- if(cbNode->presence->TTLlevel < PresenceTimeOutSize){
- OC_LOG_V(DEBUG, TAG, "----------------timeout ticks %d",
- cbNode->presence->timeOut[cbNode->presence->TTLlevel]);
- }
-
- if(cbNode->presence->TTLlevel >= PresenceTimeOutSize)
- {
- OC_LOG(DEBUG, TAG, PCF("----------------No more timeout ticks"));
- if (ParseIPv4Address( cbNode->requestUri, ipAddr, &port))
- {
- OCBuildIPv4Address(ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3], port,
- &dst);
- result = FormOCClientResponse(&clientResponse, OC_STACK_PRESENCE_TIMEOUT,
- (OCDevAddr *) &dst, 0, NULL);
- if(result != OC_STACK_OK)
- {
- goto exit;
- }
- result = FormOCResponse(&response, cbNode, 0, NULL, NULL,
- &cbNode->token, &clientResponse, NULL);
- if(result != OC_STACK_OK)
- {
- goto exit;
- }
-
- // Increment the TTLLevel (going to a next state), so we don't keep
- // sending presence notification to client.
- cbNode->presence->TTLlevel++;
- OC_LOG_V(DEBUG, TAG, "----------------moving to TTL level %d",
- cbNode->presence->TTLlevel);
- }
- else
- {
- result = OC_STACK_INVALID_IP;
- goto exit;
- }
- HandleStackResponses(response);
- }
- if(now >= cbNode->presence->timeOut[cbNode->presence->TTLlevel])
- {
- OC_LOG(DEBUG, TAG, PCF("time to test server presence =========="));
-
-#ifdef CA_INT
- CAToken_t token = NULL;
- CAResult_t caResult = CAGenerateToken(&token);
- if (caResult != CA_STATUS_OK)
- {
- CADestroyToken(token);
- goto exit;
- }
-#else
- OCCoAPToken token;
- OCGenerateCoAPToken(&token);
-
- result = OCDoCoAPResource(OC_REST_GET, OC_LOW_QOS,
- &token, (const char *)cbNode->requestUri, NULL, NULL, 0);
-
- if(result != OC_STACK_OK)
- {
- goto exit;
- }
-#endif // CA_INT
- cbNode->presence->TTLlevel++;
- OC_LOG_V(DEBUG, TAG, "----------------moving to TTL level %d", cbNode->presence->TTLlevel);
- }
- }
- }
- }
-exit:
- if (result != OC_STACK_OK)
- {
- OC_LOG(ERROR, TAG, PCF("OCProcessPresence error"));
- }
- return result;
-}
-#endif // CA_INT
#endif // WITH_PRESENCE
/**
#ifdef WITH_PRESENCE
OCProcessPresence();
#endif
-#ifdef CA_INT
CAHandleRequestResponse();
-#else
- OCProcessCoAP();
-#endif // CA_INT
return OC_STACK_OK;
}
OCBuildIPv4Address(224, 0, 1, 187, 5683, &multiCastAddr);
-#ifdef CA_INT
CAAddress_t addressInfo;
strncpy(addressInfo.IP.ipAddress, "224.0.1.187", CA_IPADDR_SIZE);
addressInfo.IP.port = 5683;
AddObserver(OC_PRESENCE_URI, NULL, 0, &caToken,
&multiCastAddr, (OCResource *)presenceResource.handle, OC_LOW_QOS,
&addressInfo, CA_WIFI);
-#else
- OCCoAPToken token;
- OCGenerateCoAPToken(&token);
- //add the presence observer
- AddObserver(OC_PRESENCE_URI, NULL, 0, &token, &multiCastAddr,
- (OCResource *)presenceResource.handle, OC_LOW_QOS);
-#endif
}
// Each time OCStartPresence is called
cbdata.cd = &ActionSetCD;
cbdata.context = (void *) 0x99;
-#ifdef CA_INT
return OCDoResource(handle, OC_REST_PUT, targetUri,
//temp->rsrcType->resourcetypename,
NULL, (char *) action, OC_WIFI, OC_NA_QOS, &cbdata, NULL, 0);
-#else
- return OCDoResource(handle, OC_REST_PUT, targetUri,
- //temp->rsrcType->resourcetypename,
- NULL, (char *) action, OC_NA_QOS, &cbdata, NULL, 0);
-#endif
}
OCStackResult BuildCollectionGroupActionJSONResponse(OCMethod method/*OCEntityHandlerFlag flag*/,
if target_os in ['darwin', 'ios']:
examples_env.AppendUnique(CPPDEFINES = ['_DARWIN_C_SOURCE'])
-examples_env.AppendUnique(CPPDEFINES = ['CA_INT'])
-
######################################################################
# Source files and Targets
######################################################################
ostringstream requestURI;
std::string deviceDiscoveryURI = "/oc/core/d";
-#ifdef CA_INT
OCConnectivityType connectivityType = OC_WIFI;
if(argc == 2)
std::cout << "connectivityType 0: ETHERNET" << std::endl;
std::cout << "connectivityType 1: WIFI" << std::endl;
}
-#endif
// Create PlatformConfig object
PlatformConfig cfg {
OC::ServiceType::InProc,
{
requestURI << OC_MULTICAST_PREFIX << deviceDiscoveryURI;
-#ifdef CA_INT
OCPlatform::getDeviceInfo("", requestURI.str(), connectivityType,
&receivedDeviceInfo);
-#else
- OCPlatform::getDeviceInfo("", requestURI.str(), &receivedDeviceInfo);
-#endif
std::cout<< "Querying for device information... " <<std::endl;
// A condition variable will free the mutex it is given, then do a non-
const uint16_t API_VERSION = 2048;
const uint16_t TOKEN = 3000;
-#ifdef CA_INT
static OCConnectivityType connectivityType = OC_WIFI;
-#endif
class ClientFridge
{
requestURI << OC_WELL_KNOWN_QUERY << "?rt=intel.fridge";
std::cout << "Fridge Client has started " <<std::endl;
FindCallback f (std::bind(&ClientFridge::foundDevice, this, PH::_1));
-#ifdef CA_INT
OCStackResult result = OCPlatform::findResource(
"", requestURI.str(), connectivityType, f);
-#else
- OCStackResult result = OCPlatform::findResource(
- "", requestURI.str(), f);
-#endif
if(OC_STACK_OK != result)
{
// server, and query them.
std::vector<std::string> lightTypes = {"intel.fridge.light"};
std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
-#ifdef CA_INT
OCResource::Ptr light = constructResourceObject(resource->host(),
"/light", connectivityType, false, lightTypes, ifaces);
-#else
- OCResource::Ptr light = constructResourceObject(resource->host(),
- "/light", false, lightTypes, ifaces);
-#endif
if(!light)
{
}
std::vector<std::string> doorTypes = {"intel.fridge.door"};
-#ifdef CA_INT
OCResource::Ptr leftdoor = constructResourceObject(resource->host(),
"/door/left", connectivityType, false, doorTypes, ifaces);
-#else
- OCResource::Ptr leftdoor = constructResourceObject(resource->host(),
- "/door/left", false, doorTypes, ifaces);
-#endif
if(!leftdoor)
{
return;
}
-#ifdef CA_INT
OCResource::Ptr rightdoor = constructResourceObject(resource->host(),
"/door/right", connectivityType, false, doorTypes, ifaces);
-#else
- OCResource::Ptr rightdoor = constructResourceObject(resource->host(),
- "/door/right", false, doorTypes, ifaces);
-#endif
if(!rightdoor)
{
return;
}
-#ifdef CA_INT
OCResource::Ptr randomdoor = constructResourceObject(resource->host(),
"/door/random", connectivityType, false, doorTypes, ifaces);
-#else
- OCResource::Ptr randomdoor = constructResourceObject(resource->host(),
- "/door/random", false, doorTypes, ifaces);
-#endif
if(!randomdoor)
{
std::cout << "Error: Random Door Resource Object construction returned null\n";
int main(int argc, char* argv[])
{
-#ifdef CA_INT
if(argc == 2)
{
try
std::cout<<"ConnectivityType 0: ETHERNET\n";
std::cout<<"ConnectivityType 1: WIFI\n";
}
-#endif
PlatformConfig cfg
{
ostringstream requestURI;
-#ifdef CA_INT
OCConnectivityType connectivityType = OC_WIFI;
if(argc == 2)
std::cout<<"ConnectivityType 0: ETHERNET\n";
std::cout<<"ConnectivityType 1: WIFI\n";
}
-#endif
// Create PlatformConfig object
PlatformConfig cfg {
// Find all resources
requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.garage";
-#ifdef CA_INT
OCPlatform::findResource("", requestURI.str(),
connectivityType, &foundResource);
-#else
- OCPlatform::findResource("", requestURI.str(),
- &foundResource);
-#endif
+
std::cout<< "Finding Resource... " <<std::endl;
// A condition variable will free the mutex it is given, then do a non-
ostringstream requestURI;
requestURI << OC_WELL_KNOWN_QUERY << "?rt=a.collection";
-#ifdef CA_INT
OCConnectivityType connectivityType = OC_WIFI;
if(argc == 2)
std::cout<<"ConnectivityType 0: ETHERNET\n";
std::cout<<"ConnectivityType 1: WIFI\n";
}
-#endif
PlatformConfig config
{ OC::ServiceType::InProc, ModeType::Client, "0.0.0.0", 0, OC::QualityOfService::LowQos };
OCPlatform::Configure(config);
string resourceTypeName = "a.collection";
-#ifdef CA_INT
+
OCPlatform::findResource("", requestURI.str(),
connectivityType, &foundResource);
-#else
- OCPlatform::findResource("", requestURI.str(), &foundResource);
-#endif
//Non-intensive block until foundResource callback is called by OCPlatform
//and onGet gets resource.
{
ostringstream requestURI;
-#ifdef CA_INT
OCConnectivityType connectivityType = OC_WIFI;
if(argc == 2)
std::cout<<"ConnectivityType 0: ETHERNET\n";
std::cout<<"ConnectivityType 1: WIFI\n";
}
-#endif
PlatformConfig config
{ OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
-#ifdef CA_INT
OCPlatform::findResource("", requestURI.str(),
connectivityType, &foundResource);
-#else
- OCPlatform::findResource("", requestURI.str(), &foundResource);
-#endif
OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
OUT_DIR := $(BUILD)
#TODO-CA Remove the CA Flag later
-CXX_FLAGS.debug := -O0 -g3 -std=c++0x -Wall -pthread -DCA_INT
+CXX_FLAGS.debug := -O0 -g3 -std=c++0x -Wall -pthread
-CXX_FLAGS.release := -O3 -std=c++0x -Wall -pthread -DCA_INT
+CXX_FLAGS.release := -O3 -std=c++0x -Wall -pthread
CXX_INC := -I../include/
CXX_INC += -I../oc_logger/include
static int TEST_CASE = 0;
-#ifdef CA_INT
static OCConnectivityType connectivityType = OC_WIFI;
-#endif
/**
* List of methods that can be inititated from the client
void printUsage()
{
-#ifdef CA_INT
std::cout << "Usage : presenceclient -t <1|2> -c <0|1>" << std::endl;
-#else
- std::cout << "Usage : presenceclient -t <1|2>" << std::endl;
-#endif
std::cout << "-t 1 : Discover Resources and Initiate Unicast Presence" << std::endl;
std::cout << "-t 2 : Discover Resources and Initiate Unicast Presence with Filter"
<< std::endl;
<< std::endl;
std::cout << "-t 6 : Discover Resources and Initiate Multicast Presence with two Filters"
<< std::endl;
-#ifdef CA_INT
std::cout<<"ConnectivityType: Default WIFI" << std::endl;
std::cout << "-c 0 : Send message over ETHERNET interface" << std::endl;
std::cout << "-c 1 : Send message over WIFI interface" << std::endl;
-#endif
}
// Callback to presence
if(TEST_CASE == TEST_UNICAST_PRESENCE_NORMAL)
{
-#ifdef CA_INT
result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
connectivityType, &presenceHandler);
-#else
- result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
- &presenceHandler);
-#endif
if(result == OC_STACK_OK)
{
std::cout<< "Subscribed to unicast address: " << hostAddress << std::endl;
if(TEST_CASE == TEST_UNICAST_PRESENCE_WITH_FILTER ||
TEST_CASE == TEST_UNICAST_PRESENCE_WITH_FILTERS)
{
-#ifdef CA_INT
result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
"core.light", connectivityType, &presenceHandler);
-#else
- result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
- "core.light", &presenceHandler);
-#endif
if(result == OC_STACK_OK)
{
std::cout<< "Subscribed to unicast address: " << hostAddress;
}
if(TEST_CASE == TEST_UNICAST_PRESENCE_WITH_FILTERS)
{
-#ifdef CA_INT
result = OCPlatform::subscribePresence(presenceHandle, hostAddress, "core.fan",
connectivityType, &presenceHandler);
-#else
- result = OCPlatform::subscribePresence(presenceHandle, hostAddress, "core.fan",
- &presenceHandler);
-#endif
if(result == OC_STACK_OK)
{
std::cout<< "Subscribed to unicast address: " << hostAddress;
int opt;
-#ifdef CA_INT
int optionSelected;
-#endif
try
{
-#ifdef CA_INT
while ((opt = getopt(argc, argv, "t:c:")) != -1)
- #else
- while ((opt = getopt(argc, argv, "t:")) != -1)
- #endif
{
switch(opt)
{
case 't':
TEST_CASE = stoi(optarg);
break;
-#ifdef CA_INT
case 'c':
std::size_t inputValLen;
optionSelected = stoi(optarg, &inputValLen);
<< std::endl;
}
break;
-#endif
default:
printUsage();
return -1;
if(TEST_CASE == TEST_MULTICAST_PRESENCE_NORMAL)
{
-#ifdef CA_INT
result = OCPlatform::subscribePresence(presenceHandle,
OC_MULTICAST_IP, connectivityType, presenceHandler);
-#else
- result = OCPlatform::subscribePresence(presenceHandle,
- OC_MULTICAST_IP, presenceHandler);
-#endif
if(result == OC_STACK_OK)
{
}
else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTER)
{
-#ifdef CA_INT
result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
connectivityType, &presenceHandler);
-#else
- result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
- &presenceHandler);
-#endif
if(result == OC_STACK_OK)
{
std::cout << "Subscribed to multicast presence with resource type";
}
else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTERS)
{
-#ifdef CA_INT
result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
connectivityType, &presenceHandler);
-#else
- result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
- &presenceHandler);
-#endif
if(result == OC_STACK_OK)
{
std::cout << "Subscribed to multicast presence with resource type";
}
std::cout << "\"core.light\"." << std::endl;
-#ifdef CA_INT
result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.fan",
connectivityType, &presenceHandler);
-#else
- result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.fan",
- &presenceHandler);
-#endif
if(result == OC_STACK_OK)
{
std::cout<< "Subscribed to multicast presence with resource type";
// Find all resources
requestURI << OC_WELL_KNOWN_QUERY;
-#ifdef CA_INT
result = OCPlatform::findResource("", requestURI.str(),
connectivityType, &foundResource);
-#else
- result = OCPlatform::findResource("", requestURI.str(), &foundResource);
-#endif
if(result == OC_STACK_OK)
{
std::cout << "Finding Resource... " << std::endl;
ostringstream requestURI;
-#ifdef CA_INT
OCConnectivityType connectivityType = OC_WIFI;
if(argc == 2)
{
std::cout << "connectivityType 0: ETHERNET" << std::endl;
std::cout << "connectivityType 1: WIFI" << std::endl;
}
-#endif
// Create PlatformConfig object
PlatformConfig cfg {
// Find all resources
requestURI << OC_WELL_KNOWN_QUERY;
-#ifdef CA_INT
OCPlatform::findResource("", requestURI.str(), connectivityType, &foundResource);
-#else
- OCPlatform::findResource("", requestURI.str(), &foundResource);
-#endif
std::cout<< "Finding Resource... " <<std::endl;
// A condition variable will free the mutex it is given, then do a non-
void PrintUsage()
{
std::cout << std::endl;
-#ifdef CA_INT
std::cout << "Usage : simpleclient <ObserveType> <ConnectivityType>" << std::endl;
-#else
- std::cout << "Usage : simpleclient <ObserveType>" << std::endl;
-#endif
std::cout << " ObserveType : 1 - Observe" << std::endl;
std::cout << " ObserveType : 2 - ObserveAll" << std::endl;
-#ifdef CA_INT
std::cout<<" connectivityType: Default WIFI" << std::endl;
std::cout << " ConnectivityType : 0 - ETHERNET"<< std::endl;
std::cout << " ConnectivityType : 1 - WIFI"<< std::endl;
-#endif
}
int main(int argc, char* argv[]) {
ostringstream requestURI;
-#ifdef CA_INT
OCConnectivityType connectivityType = OC_WIFI;
-#endif
+
try
{
if (argc == 1)
{
OBSERVE_TYPE_TO_USE = ObserveType::Observe;
}
-#ifdef CA_INT
else if (argc >= 2)
-#else
- else if (argc == 2)
-#endif
{
int value = stoi(argv[1]);
if (value == 1)
OBSERVE_TYPE_TO_USE = ObserveType::ObserveAll;
else
OBSERVE_TYPE_TO_USE = ObserveType::Observe;
-#ifdef CA_INT
if(argc == 3)
{
std::size_t inputValLen;
<< std::endl;
}
}//if arg = 3
-#endif
}
else
{
// Find all resources
requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
-#ifdef CA_INT
OCPlatform::findResource("", requestURI.str(),
connectivityType, &foundResource);
-#else
- OCPlatform::findResource("", requestURI.str(), &foundResource);
-#endif
std::cout<< "Finding Resource... " <<std::endl;
// Find resource is done twice so that we discover the original resources a second time.
// These resources will have the same uniqueidentifier (yet be different objects), so that
// we can verify/show the duplicate-checking code in foundResource(above);
-#ifdef CA_INT
OCPlatform::findResource("", requestURI.str(),
connectivityType, &foundResource);
-#else
- OCPlatform::findResource("", requestURI.str(), &foundResource);
-#endif
std::cout<< "Finding Resource for second time..." << std::endl;
// A condition variable will free the mutex it is given, then do a non-
void PrintUsage()
{
std::cout << std::endl;
-#ifdef CA_INT
std::cout << "Usage : simpleclientHQ <ObserveType> <ConnectivityType>" << std::endl;
-#else
- std::cout << "Usage : simpleclientHQ <ObserveType>" << std::endl;
-#endif
std::cout << " ObserveType : 1 - Observe" << std::endl;
std::cout << " ObserveType : 2 - ObserveAll" << std::endl;
-#ifdef CA_INT
std::cout<<" ConnectivityType: Default WIFI" << std::endl;
std::cout << " ConnectivityType : 0 - ETHERNET"<< std::endl;
std::cout << " ConnectivityType : 1 - WIFI"<< std::endl;
-#endif
}
int main(int argc, char* argv[]) {
ostringstream requestURI;
-#ifdef CA_INT
OCConnectivityType connectivityType = OC_WIFI;
-#endif
try
{
if (argc == 1)
{
OBSERVE_TYPE_TO_USE = ObserveType::Observe;
}
-#ifdef CA_INT
else if (argc >= 2)
-#else
- else if (argc == 2)
-#endif
{
int value = stoi(argv[1]);
if (value == 1)
else
OBSERVE_TYPE_TO_USE = ObserveType::Observe;
-#ifdef CA_INT
if(argc == 3)
{
std::size_t inputValLen;
<< std::endl;
}
}
-#endif
}
else
{
// Find all resources
requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.light";
-#ifdef CA_INT
OCPlatform::findResource("", requestURI.str(),
connectivityType, &foundResource, OC::QualityOfService::LowQos);
-#else
- OCPlatform::findResource("", requestURI.str(), &foundResource,
- OC::QualityOfService::LowQos);
-#endif
std::cout<< "Finding Resource... " <<std::endl;
// Find resource is done twice so that we discover the original resources a second time.
// These resources will have the same uniqueidentifier (yet be different objects), so that
// we can verify/show the duplicate-checking code in foundResource(above);
-#ifdef CA_INT
OCPlatform::findResource("", requestURI.str(),
connectivityType, &foundResource, OC::QualityOfService::LowQos);
-#else
- OCPlatform::findResource("", requestURI.str(), &foundResource,
- OC::QualityOfService::LowQos);
-#endif
std::cout<< "Finding Resource for second time... " <<std::endl;
// A condition variable will free the mutex it is given, then do a non-
#include "OCApi.h"
using namespace OC;
-#ifdef CA_INT
OCConnectivityType connectivityType = OC_WIFI;
-#endif
class ClientWorker
{
std::cout<<"Starting Client find:"<<std::endl;
FindCallback f (std::bind(&ClientWorker::foundResource, this, std::placeholders::_1));
-#ifdef CA_INT
std::cout<<"result:" <<
OCPlatform::findResource("", requestURI.str(), connectivityType, f)
<< std::endl;
-#else
- std::cout<<"result:" <<
- OCPlatform::findResource("", requestURI.str(), f)
- << std::endl;
-#endif
std::cout<<"Finding Resource..."<<std::endl;
int main(int argc, char* argv[])
{
-#ifdef CA_INT
if(argc == 2)
{
try
std::cout << " ConnectivityType : 0 - ETHERNET" << std::endl;
std::cout << " ConnectivityType : 1 - WIFI" << std::endl;
}
-#endif
PlatformConfig cfg {
OC::ServiceType::InProc,
#include "OCApi.h"
using namespace OC;
-#ifdef CA_INT
static OCConnectivityType connectivityType = OC_WIFI;
-#endif
static std::ostringstream requestURI;
void client1()
{
std::cout << "in client1\n";
-#ifdef CA_INT
std::cout<<"result1:" << OCPlatform::findResource("", requestURI.str(),
connectivityType, foundResource1)<< std::endl;
-#else
- std::cout<<"result1:" << OCPlatform::findResource("", requestURI.str(),
- foundResource1)<< std::endl;
-#endif
// A condition variable will free the mutex it is given, then do a non-
// intensive block until 'notify' is called on it. In this case, since we
void client2()
{
std::cout << "in client2\n";
-#ifdef CA_INT
std::cout<<"result2:" << OCPlatform::findResource("",
requestURI.str(),
connectivityType, foundResource2)<< std::endl;
-#else
- std::cout<<"result2:" << OCPlatform::findResource("",
- requestURI.str(),
- foundResource2)<< std::endl;
-#endif
// A condition variable will free the mutex it is given, then do a non-
// intensive block until 'notify' is called on it. In this case, since we
int main(int argc, char* argv[])
{
-#ifdef CA_INT
if(argc == 2)
{
try
std::cout << " ConnectivityType : 0 - ETHERNET" << std::endl;
std::cout << " ConnectivityType : 1 - WIFI" << std::endl;
}
-#endif
requestURI << OC_WELL_KNOWN_QUERY << "?rt=core.foo";
IClientWrapper()
{}
-#ifdef CA_INT
virtual OCStackResult ListenForResource(const std::string& serviceUrl,
const std::string& resourceType, OCConnectivityType connectivityType,
FindCallback& callback,
OCConnectivityType connectivityType, const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions, ObserveCallback& callback,
QualityOfService QoS)=0;
-#else
- virtual OCStackResult ListenForResource(const std::string& serviceUrl,
- const std::string& resourceType, FindCallback& callback,
- QualityOfService QoS) = 0;
-
- virtual OCStackResult ListenForDevice(const std::string& serviceUrl,
- const std::string& deviceURI, FindDeviceCallback& callback,
- QualityOfService QoS) = 0;
-
- virtual OCStackResult GetResourceRepresentation(const std::string& host,
- const std::string& uri, const QueryParamsMap& queryParams,
- const HeaderOptions& headerOptions,
- GetCallback& callback, QualityOfService QoS)=0;
-
- virtual OCStackResult PutResourceRepresentation(const std::string& host,
- const std::string& uri, const OCRepresentation& rep,
- const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
- PutCallback& callback, QualityOfService QoS) = 0;
- virtual OCStackResult PostResourceRepresentation(const std::string& host,
- const std::string& uri, const OCRepresentation& rep,
- const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
- PostCallback& callback, QualityOfService QoS) = 0;
-
- virtual OCStackResult DeleteResource(const std::string& host, const std::string& uri,
- const HeaderOptions& headerOptions, DeleteCallback& callback,
- QualityOfService QoS) = 0;
-
- virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
- const std::string& host, const std::string& uri,
- const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
- ObserveCallback& callback, QualityOfService QoS)=0;
-#endif
virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
const std::string& uri, const HeaderOptions& headerOptions, QualityOfService QoS)=0;
-#ifdef CA_INT
virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
const std::string& resourceType, OCConnectivityType connectivityType,
SubscribeCallback& presenceHandler)=0;
-#else
- virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
- const std::string& resourceType, SubscribeCallback& presenceHandler)=0;
-#endif
+
virtual OCStackResult UnsubscribePresence(OCDoHandle handle) =0;
virtual OCStackResult GetDefaultQos(QualityOfService& qos) = 0;
PlatformConfig cfg);
virtual ~InProcClientWrapper();
-#ifdef CA_INT
virtual OCStackResult ListenForResource(const std::string& serviceUrl,
const std::string& resourceType, OCConnectivityType connectivityType,
FindCallback& callback, QualityOfService QoS);
const std::string& host, const std::string& uri, OCConnectivityType connectivityType,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
ObserveCallback& callback, QualityOfService QoS);
-#else
- virtual OCStackResult ListenForResource(const std::string& serviceUrl,
- const std::string& resourceType, FindCallback& callback,
- QualityOfService QoS);
-
- virtual OCStackResult ListenForDevice(const std::string& serviceUrl,
- const std::string& deviceURI, FindDeviceCallback& callback,
- QualityOfService QoS);
-
- virtual OCStackResult GetResourceRepresentation(const std::string& host,
- const std::string& uri, const QueryParamsMap& queryParams,
- const HeaderOptions& headerOptions,
- GetCallback& callback, QualityOfService QoS);
-
- virtual OCStackResult PutResourceRepresentation(const std::string& host,
- const std::string& uri, const OCRepresentation& attributes,
- const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
- PutCallback& callback, QualityOfService QoS);
- virtual OCStackResult PostResourceRepresentation(const std::string& host,
- const std::string& uri, const OCRepresentation& attributes,
- const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
- PostCallback& callback, QualityOfService QoS);
-
- virtual OCStackResult DeleteResource(const std::string& host, const std::string& uri,
- const HeaderOptions& headerOptions, DeleteCallback& callback, QualityOfService QoS);
-
- virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
- const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
- const HeaderOptions& headerOptions, ObserveCallback& callback, QualityOfService QoS);
-#endif
virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
const std::string& uri, const HeaderOptions& headerOptions, QualityOfService QoS);
-#ifdef CA_INT
virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
const std::string& resourceType, OCConnectivityType connectivityType,
SubscribeCallback& presenceHandler);
-#else
- virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
- const std::string& resourceType, SubscribeCallback& presenceHandler);
-#endif
virtual OCStackResult UnsubscribePresence(OCDoHandle handle);
OCStackResult GetDefaultQos(QualityOfService& QoS);
* as BTH etc.
* NOTE: OCStackResult is defined in ocstack.h.
*/
-#ifdef CA_INT
OCStackResult findResource(const std::string& host, const std::string& resourceURI,
OCConnectivityType connectivityType, FindCallback resourceHandler);
OCStackResult findResource(const std::string& host, const std::string& resourceURI,
OCConnectivityType connectivityType, FindCallback resourceHandler,
QualityOfService QoS);
-#else
- OCStackResult findResource(const std::string& host, const std::string& resourceURI,
- FindCallback resourceHandler);
- OCStackResult findResource(const std::string& host, const std::string& resourceURI,
- FindCallback resourceHandler, QualityOfService QoS);
-#endif
/**
* API for Device Discovery
* @param QualityOfService the quality of communication
*
*/
-#ifdef CA_INT
OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
QualityOfService QoS);
-#else
- OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
- FindDeviceCallback deviceInfoHandler);
- OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
- FindDeviceCallback deviceInfoHandler, QualityOfService QoS);
-#endif
/**
* This API registers a resource with the server
*
* @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
*/
-#ifdef CA_INT
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
const std::string& resourceType, OCConnectivityType connectivityType,
SubscribeCallback presenceHandler);
-#else
- OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
- SubscribeCallback presenceHandler);
- OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
- const std::string& resourceType, SubscribeCallback presenceHandler);
-#endif
/**
* unsubscribes from a previously subscribed server's presence events. Note that
* @param interfaces - a collection of interfaces that the resource supports/implements
* @return OCResource::Ptr - a shared pointer to the new resource object
*/
-#ifdef CA_INT
OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
OCConnectivityType connectivityType, bool isObservable,
const std::vector<std::string>& resourceTypes,
const std::vector<std::string>& interfaces);
-#else
- OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
- bool isObservable, const std::vector<std::string>& resourceTypes,
- const std::vector<std::string>& interfaces);
-#endif
/**
* Allows application entity handler to send response to an incoming request.
* as BTH etc.
* NOTE: OCStackResult is defined in ocstack.h.
*/
-#ifdef CA_INT
OCStackResult findResource(const std::string& host, const std::string& resourceURI,
OCConnectivityType connectivityType, FindCallback resourceHandler);
OCStackResult findResource(const std::string& host, const std::string& resourceURI,
OCConnectivityType connectivityType, FindCallback resourceHandler,
QualityOfService QoS);
-#else
- OCStackResult findResource(const std::string& host, const std::string& resourceURI,
- FindCallback resourceHandler);
- OCStackResult findResource(const std::string& host, const std::string& resourceURI,
- FindCallback resourceHandler, QualityOfService QoS);
-#endif
/**
* API for Device Discovery
*
* @param QualityOfService the quality of communication
*
*/
-#ifdef CA_INT
OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
QualityOfService QoS);
-#else
- OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
- FindDeviceCallback deviceInfoHandler);
- OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
- FindDeviceCallback deviceInfoHandler, QualityOfService QoS);
-#endif
/**
* This API registers a resource with the server
*
* @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
*/
-#ifdef CA_INT
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
const std::string& resourceType, OCConnectivityType connectivityType,
SubscribeCallback presenceHandler);
-#else
- OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
- SubscribeCallback presenceHandler);
- OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
- const std::string& resourceType, SubscribeCallback presenceHandler);
-#endif
/**
* unsubscribes from a previously subscribed server's presence events. Note that
* you may for a short time still receive events from the server since it may take time
* @param interfaces - a collection of interfaces that the resource supports/implements
* @return OCResource::Ptr - a shared pointer to the new resource object
*/
-#ifdef CA_INT
OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
OCConnectivityType connectivityType, bool isObservable,
const std::vector<std::string>& resourceTypes,
const std::vector<std::string>& interfaces);
-#else
- OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
- bool isObservable, const std::vector<std::string>& resourceTypes,
- const std::vector<std::string>& interfaces);
-#endif
/**
* Allows application entity handler to send response to an incoming request.
*
*/
std::string uri() const;
-#ifdef CA_INT
/**
* Function to get the connectivity type of this resource
* @return uint8_t connectivity type
*/
OCConnectivityType connectivityType() const;
-#endif
/**
* Function to provide ability to check if this resource is observable or not
std::string m_uri;
OCResourceIdentifier m_resourceId;
std::string m_host;
-#ifdef CA_INT
OCConnectivityType m_connectivityType;
-#endif
bool m_isObservable;
bool m_isCollection;
std::vector<std::string> m_resourceTypes;
HeaderOptions m_headerOptions;
private:
-#ifdef CA_INT
OCResource(std::weak_ptr<IClientWrapper> clientWrapper, const std::string& host,
const std::string& uri, const std::string& serverId,
OCConnectivityType m_connectivityType, bool observable,
const std::vector<std::string>& resourceTypes,
const std::vector<std::string>& interfaces);
-#else
- OCResource(std::weak_ptr<IClientWrapper> clientWrapper, const std::string& host,
- const std::string& uri, const std::string& serverId, bool observable,
- const std::vector<std::string>& resourceTypes,
- const std::vector<std::string>& interfaces);
-#endif
};
} // namespace OC
ar(resources);
}
public:
-#ifdef CA_INT
ListenOCContainer(std::weak_ptr<IClientWrapper> cw, const OCDevAddr& address,
OCConnectivityType connectivityType, std::stringstream& json):
m_clientWrapper(cw), m_address(address), m_connectivityType(connectivityType)
-#else
- ListenOCContainer(std::weak_ptr<IClientWrapper> cw, const OCDevAddr& address,
- std::stringstream& json):
- m_clientWrapper(cw), m_address(address)
-#endif
{
LoadFromJson(json);
}
{
if(res.loaded())
{
-#ifdef CA_INT
m_resources.push_back(std::shared_ptr<OCResource>(
new OCResource(m_clientWrapper,
ConvertOCAddrToString(res.secureType(),res.port()),
res.m_uri, res.m_serverId, m_connectivityType, res.observable(),
res.resourceTypes(), res.interfaces())));
-#else
- m_resources.push_back(std::shared_ptr<OCResource>(
- new OCResource(m_clientWrapper,
- ConvertOCAddrToString(res.secureType(),res.port()),
- res.m_uri, res.m_serverId, res.observable(),
- res.resourceTypes(), res.interfaces())));
-#endif
}
}
PlatformConfig cfg)
{}
-#ifdef CA_INT
virtual OCStackResult ListenForResource(const std::string& serviceUrl,
const std::string& resourceType, OCConnectivityType connectivityType,
FindCallback& callback, QualityOfService QoS)
const std::string& host, const std::string& uri, OCConnectivityType connectivityType,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
ObserveCallback& callback, QualityOfService QoS){return OC_STACK_NOTIMPL;}
-#else
- virtual OCStackResult ListenForResource(const std::string& serviceUrl,
- const std::string& resourceType, FindCallback& callback, QualityOfService QoS)
- {return OC_STACK_NOTIMPL;}
-
- virtual OCStackResult ListenForDevice(const std::string& serviceUrl,
- const std::string& deviceURI, FindDeviceCallback& callback,
- QualityOfService QoS)
- {return OC_STACK_NOTIMPL;}
-
- virtual OCStackResult GetResourceRepresentation(const std::string& host,
- const std::string& uri, const QueryParamsMap& queryParams,
- const HeaderOptions& headerOptions, GetCallback& callback,
- QualityOfService QoS)
- {return OC_STACK_NOTIMPL;}
-
- virtual OCStackResult PutResourceRepresentation(const std::string& host,
- const std::string& uri, const OCRepresentation& attributes,
- const QueryParamsMap& queryParams,
- const HeaderOptions& headerOptions, PutCallback& callback,
- QualityOfService QoS)
- {return OC_STACK_NOTIMPL;}
-
- virtual OCStackResult PostResourceRepresentation(const std::string& host,
- const std::string& uri, const OCRepresentation& attributes,
- const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
- PostCallback& callback, QualityOfService QoS)
- {return OC_STACK_NOTIMPL;}
-
- virtual OCStackResult DeleteResource(const std::string& host, const std::string& uri,
- const HeaderOptions& headerOptions, DeleteCallback& callback,
- QualityOfService QoS) {return OC_STACK_NOTIMPL;}
-
- virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
- const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
- const HeaderOptions& headerOptions,
- ObserveCallback& callback, QualityOfService QoS){return OC_STACK_NOTIMPL;}
-#endif
virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
const std::string& uri,
const HeaderOptions& headerOptions, QualityOfService QoS){return OC_STACK_NOTIMPL;}
-#ifdef CA_INT
virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
const std::string& resourceType, OCConnectivityType connectivityType,
SubscribeCallback& presenceHandler)
{return OC_STACK_NOTIMPL;}
-#else
- virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
- const std::string& resourceType, SubscribeCallback& presenceHandler)
- {return OC_STACK_NOTIMPL;}
-#endif
virtual OCStackResult UnsubscribePresence(OCDoHandle handle){return OC_STACK_NOTIMPL;}
virtual OCStackResult GetDefaultQos(QualityOfService& QoS){return OC_STACK_NOTIMPL;}
OBJ_DIR := $(OUT_DIR)/obj
#TODO-CA Need to remove flag later
-CXX_FLAGS.debug := -g3 -std=c++0x -Wall -pthread -O0 -DCA_INT
-CXX_FLAGS.release := -std=c++0x -Wall -pthread -O3 -DCA_INT
+CXX_FLAGS.debug := -g3 -std=c++0x -Wall -pthread -O0
+CXX_FLAGS.release := -std=c++0x -Wall -pthread -O3
CXX_INC := -I./include/
CXX_INC += -I./oc_logger/include
try
{
-#ifdef CA_INT
ListenOCContainer container(clientWrapper, *clientResponse->addr,
clientResponse->connType, requestStream);
-#else
- ListenOCContainer container(clientWrapper, *clientResponse->addr,
- requestStream);
-#endif
// loop to ensure valid construction of all resources
for(auto resource : container.Resources())
{
return OC_STACK_KEEP_TRANSACTION;
}
-#ifdef CA_INT
OCStackResult InProcClientWrapper::ListenForResource(const std::string& serviceUrl,
const std::string& resourceType, OCConnectivityType connectivityType,
FindCallback& callback, QualityOfService QoS)
-#else
- OCStackResult InProcClientWrapper::ListenForResource(const std::string& serviceUrl,
- const std::string& resourceType, FindCallback& callback, QualityOfService QoS)
-#endif
{
OCStackResult result;
{
std::lock_guard<std::recursive_mutex> lock(*cLock);
OCDoHandle handle;
-#ifdef CA_INT
result = OCDoResource(&handle, OC_REST_GET,
resourceType.c_str(),
nullptr, nullptr, connectivityType,
static_cast<OCQualityOfService>(QoS),
&cbdata,
NULL, 0);
-#else
- result = OCDoResource(&handle, OC_REST_GET,
- resourceType.c_str(),
- nullptr, nullptr,
- static_cast<OCQualityOfService>(QoS),
- &cbdata,
- NULL, 0);
-#endif
}
else
{
return OC_STACK_KEEP_TRANSACTION;
}
-#ifdef CA_INT
OCStackResult InProcClientWrapper::ListenForDevice(const std::string& serviceUrl,
const std::string& deviceURI, OCConnectivityType connectivityType,
FindDeviceCallback& callback, QualityOfService QoS)
-#else
- OCStackResult InProcClientWrapper::ListenForDevice(const std::string& serviceUrl,
- const std::string& deviceURI, FindDeviceCallback& callback, QualityOfService QoS)
-#endif
{
OCStackResult result;
{
std::lock_guard<std::recursive_mutex> lock(*cLock);
OCDoHandle handle;
-#ifdef CA_INT
result = OCDoResource(&handle, OC_REST_GET,
deviceURI.c_str(),
nullptr, nullptr, connectivityType,
static_cast<OCQualityOfService>(QoS),
&cbdata,
NULL, 0);
-#else
- result = OCDoResource(&handle, OC_REST_GET,
- deviceURI.c_str(),
- nullptr, nullptr,
- static_cast<OCQualityOfService>(QoS),
- &cbdata,
- NULL, 0);
-#endif
}
else
{
return OC_STACK_DELETE_TRANSACTION;
}
-#ifdef CA_INT
OCStackResult InProcClientWrapper::GetResourceRepresentation(const std::string& host,
const std::string& uri, OCConnectivityType connectivityType,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
GetCallback& callback, QualityOfService QoS)
-#else
- OCStackResult InProcClientWrapper::GetResourceRepresentation(const std::string& host,
- const std::string& uri, const QueryParamsMap& queryParams,
- const HeaderOptions& headerOptions, GetCallback& callback,
- QualityOfService QoS)
-#endif
{
OCStackResult result;
OCCallbackData cbdata = {0};
OCHeaderOption options[MAX_HEADER_OPTIONS];
assembleHeaderOptions(options, headerOptions);
-#ifdef CA_INT
+
result = OCDoResource(&handle, OC_REST_GET, os.str().c_str(),
nullptr, nullptr, connectivityType,
static_cast<OCQualityOfService>(QoS),
&cbdata,
options, headerOptions.size());
-#else
- result = OCDoResource(&handle, OC_REST_GET, os.str().c_str(),
- nullptr, nullptr,
- static_cast<OCQualityOfService>(QoS),
- &cbdata,
- options, headerOptions.size());
-#endif
}
else
{
return ocInfo.getJSONRepresentation(OCInfoFormat::IncludeOC);
}
-#ifdef CA_INT
OCStackResult InProcClientWrapper::PostResourceRepresentation(const std::string& host,
const std::string& uri, OCConnectivityType connectivityType, const OCRepresentation& rep,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
PostCallback& callback, QualityOfService QoS)
-#else
- OCStackResult InProcClientWrapper::PostResourceRepresentation(const std::string& host,
- const std::string& uri, const OCRepresentation& rep,
- const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
- PostCallback& callback, QualityOfService QoS)
-#endif
{
OCStackResult result;
OCCallbackData cbdata = {0};
OCDoHandle handle;
assembleHeaderOptions(options, headerOptions);
-#ifdef CA_INT
result = OCDoResource(&handle, OC_REST_POST,
os.str().c_str(), nullptr,
assembleSetResourcePayload(rep).c_str(), connectivityType,
static_cast<OCQualityOfService>(QoS),
&cbdata, options, headerOptions.size());
-#else
- result = OCDoResource(&handle, OC_REST_POST,
- os.str().c_str(), nullptr,
- assembleSetResourcePayload(rep).c_str(),
- static_cast<OCQualityOfService>(QoS),
- &cbdata, options, headerOptions.size());
-#endif
}
else
{
return result;
}
-#ifdef CA_INT
OCStackResult InProcClientWrapper::PutResourceRepresentation(const std::string& host,
const std::string& uri, OCConnectivityType connectivityType, const OCRepresentation& rep,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
PutCallback& callback, QualityOfService QoS)
-#else
- OCStackResult InProcClientWrapper::PutResourceRepresentation(const std::string& host,
- const std::string& uri, const OCRepresentation& rep,
- const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
- PutCallback& callback, QualityOfService QoS)
-#endif
{
OCStackResult result;
OCCallbackData cbdata = {0};
OCHeaderOption options[MAX_HEADER_OPTIONS];
assembleHeaderOptions(options, headerOptions);
-#ifdef CA_INT
result = OCDoResource(&handle, OC_REST_PUT,
os.str().c_str(), nullptr,
assembleSetResourcePayload(rep).c_str(), connectivityType,
static_cast<OCQualityOfService>(QoS),
&cbdata,
options, headerOptions.size());
-#else
- result = OCDoResource(&handle, OC_REST_PUT,
- os.str().c_str(), nullptr,
- assembleSetResourcePayload(rep).c_str(),
- static_cast<OCQualityOfService>(QoS),
- &cbdata,
- options, headerOptions.size());
-#endif
}
else
{
return OC_STACK_DELETE_TRANSACTION;
}
-#ifdef CA_INT
OCStackResult InProcClientWrapper::DeleteResource(const std::string& host,
const std::string& uri, OCConnectivityType connectivityType,
const HeaderOptions& headerOptions, DeleteCallback& callback, QualityOfService QoS)
-#else
- OCStackResult InProcClientWrapper::DeleteResource(const std::string& host,
- const std::string& uri, const HeaderOptions& headerOptions,
- DeleteCallback& callback, QualityOfService QoS)
-#endif
{
OCStackResult result;
OCCallbackData cbdata = {0};
assembleHeaderOptions(options, headerOptions);
std::lock_guard<std::recursive_mutex> lock(*cLock);
-#ifdef CA_INT
+
result = OCDoResource(&handle, OC_REST_DELETE,
os.str().c_str(), nullptr,
nullptr, connectivityType,
static_cast<OCQualityOfService>(m_cfg.QoS),
&cbdata, options, headerOptions.size());
-#else
- result = OCDoResource(&handle, OC_REST_DELETE,
- os.str().c_str(), nullptr,
- nullptr, static_cast<OCQualityOfService>(m_cfg.QoS),
- &cbdata, options, headerOptions.size());
-#endif
}
else
{
return OC_STACK_KEEP_TRANSACTION;
}
-#ifdef CA_INT
OCStackResult InProcClientWrapper::ObserveResource(ObserveType observeType, OCDoHandle* handle,
const std::string& host, const std::string& uri, OCConnectivityType connectivityType,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
ObserveCallback& callback, QualityOfService QoS)
-#else
- OCStackResult InProcClientWrapper::ObserveResource(ObserveType observeType, OCDoHandle* handle,
- const std::string& host, const std::string& uri, const QueryParamsMap& queryParams,
- const HeaderOptions& headerOptions, ObserveCallback& callback, QualityOfService QoS)
-#endif
{
OCStackResult result;
OCCallbackData cbdata = {0};
OCHeaderOption options[MAX_HEADER_OPTIONS];
assembleHeaderOptions(options, headerOptions);
-#ifdef CA_INT
result = OCDoResource(handle, method,
os.str().c_str(), nullptr,
nullptr, connectivityType,
static_cast<OCQualityOfService>(QoS),
&cbdata,
options, headerOptions.size());
-#else
- result = OCDoResource(handle, method,
- os.str().c_str(), nullptr,
- nullptr,
- static_cast<OCQualityOfService>(QoS),
- &cbdata,
- options, headerOptions.size());
-#endif
}
else
{
return OC_STACK_KEEP_TRANSACTION;
}
-#ifdef CA_INT
OCStackResult InProcClientWrapper::SubscribePresence(OCDoHandle* handle,
const std::string& host, const std::string& resourceType,
OCConnectivityType connectivityType, SubscribeCallback& presenceHandler)
-#else
- OCStackResult InProcClientWrapper::SubscribePresence(OCDoHandle* handle,
- const std::string& host, const std::string& resourceType,
- SubscribeCallback& presenceHandler)
-#endif
{
OCCallbackData cbdata = {0};
return OC_STACK_ERROR;
}
-#ifdef CA_INT
return OCDoResource(handle, OC_REST_PRESENCE, os.str().c_str(), nullptr, nullptr,
connectivityType, OC_LOW_QOS, &cbdata, NULL, 0);
-#else
- return OCDoResource(handle, OC_REST_PRESENCE, os.str().c_str(), nullptr, nullptr,
- OC_LOW_QOS, &cbdata, NULL, 0);
-#endif
}
OCStackResult InProcClientWrapper::UnsubscribePresence(OCDoHandle handle)
observationIds, pResponse, QoS);
}
-#ifdef CA_INT
OCResource::Ptr constructResourceObject(const std::string& host,
const std::string& uri,
OCConnectivityType connectivityType,
return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, connectivityType,
deviceInfoHandler, QoS);
}
-#else
-
- OCStackResult findResource(const std::string& host,
- const std::string& resourceName,
- FindCallback resourceHandler)
- {
- return OCPlatform_impl::Instance().findResource(host, resourceName, resourceHandler);
- }
-
- OCStackResult findResource(const std::string& host,
- const std::string& resourceName,
- FindCallback resourceHandler, QualityOfService QoS)
- {
- return OCPlatform_impl::Instance().findResource(host, resourceName,
- resourceHandler, QoS);
- }
-
- OCResource::Ptr constructResourceObject(const std::string& host,
- const std::string& uri,
- bool isObservable,
- const std::vector<std::string>& resourceTypes,
- const std::vector<std::string>& interfaces)
- {
- return OCPlatform_impl::Instance().constructResourceObject(host, uri, isObservable,
- resourceTypes, interfaces);
- }
-
- OCStackResult getDeviceInfo(const std::string& host,
- const std::string& deviceURI,
- FindDeviceCallback deviceInfoHandler)
- {
- return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, deviceInfoHandler);
- }
-
- OCStackResult getDeviceInfo(const std::string& host,
- const std::string& deviceURI,
- FindDeviceCallback deviceInfoHandler,
- QualityOfService QoS)
- {
- return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, deviceInfoHandler, QoS);
- }
-#endif
OCStackResult registerResource(OCResourceHandle& resourceHandle,
std::string& resourceURI,
return OCPlatform_impl::Instance().stopPresence();
}
-#ifdef CA_INT
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
const std::string& host,
OCConnectivityType connectivityType,
return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
resourceType, connectivityType, presenceHandler);
}
-#else
- OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
- const std::string& host,
- SubscribeCallback presenceHandler)
- {
- return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
- presenceHandler);
- }
-
- OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
- const std::string& host,
- const std::string& resourceType,
- SubscribeCallback presenceHandler)
- {
- return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
- resourceType, presenceHandler);
- }
-#endif
OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle)
{
static_cast<OCQualityOfService>(QoS)));
}
-#ifdef CA_INT
OCResource::Ptr OCPlatform_impl::constructResourceObject(const std::string& host,
const std::string& uri,
OCConnectivityType connectivityType,
host, deviceURI, connectivityType, deviceInfoHandler, QoS);
}
-#else
- OCResource::Ptr OCPlatform_impl::constructResourceObject(const std::string& host,
- const std::string& uri,
- bool isObservable,
- const std::vector<std::string>& resourceTypes,
- const std::vector<std::string>& interfaces)
- {
- if(!m_client)
- {
- return std::shared_ptr<OCResource>();
- }
-
- return std::shared_ptr<OCResource>(new OCResource(m_client,
- host,
- uri,
- "", // 'created' Resources have no way of knowing their
- // server ID, so this has to be blank initially.
- isObservable,
- resourceTypes,
- interfaces));
- }
-
- OCStackResult OCPlatform_impl::findResource(const std::string& host,
- const std::string& resourceName,
- FindCallback resourceHandler)
- {
- return findResource(host, resourceName, resourceHandler, m_cfg.QoS);
- }
-
- OCStackResult OCPlatform_impl::findResource(const std::string& host,
- const std::string& resourceName,
- FindCallback resourceHandler, QualityOfService QoS)
- {
-
- return checked_guard(m_client, &IClientWrapper::ListenForResource,
- host, resourceName, resourceHandler, QoS);
- }
-
- OCStackResult OCPlatform_impl::getDeviceInfo(const std::string& host,
- const std::string& deviceURI,
- FindDeviceCallback deviceInfoHandler)
- {
- return result_guard(getDeviceInfo(host, deviceURI, deviceInfoHandler, m_cfg.QoS));
- }
-
- OCStackResult OCPlatform_impl::getDeviceInfo(const std::string& host,
- const std::string& deviceURI,
- FindDeviceCallback deviceInfoHandler,
- QualityOfService QoS)
- {
- return checked_guard(m_client, &IClientWrapper::ListenForDevice,
- host, deviceURI, deviceInfoHandler, QoS);
- }
-
-#endif
-
OCStackResult OCPlatform_impl::registerResource(OCResourceHandle& resourceHandle,
std::string& resourceURI,
const std::string& resourceTypeName,
return checked_guard(m_server, &IServerWrapper::stopPresence);
}
-#ifdef CA_INT
OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle,
const std::string& host,
OCConnectivityType connectivityType,
&presenceHandle, host, resourceType, connectivityType,
presenceHandler);
}
-#else
- OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle,
- const std::string& host,
- SubscribeCallback presenceHandler)
- {
- return subscribePresence(presenceHandle, host, "", presenceHandler);
- }
-
- OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle,
- const std::string& host,
- const std::string& resourceType,
- SubscribeCallback presenceHandler)
- {
- return checked_guard(m_client, &IClientWrapper::SubscribePresence,
- &presenceHandle, host, resourceType,
- presenceHandler);
- }
-#endif
OCStackResult OCPlatform_impl::unsubscribePresence(OCPresenceHandle presenceHandle)
{
using OC::result_guard;
using OC::checked_guard;
-#ifdef CA_INT
OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper, const std::string& host,
const std::string& uri, const std::string& serverId,
OCConnectivityType connectivityType, bool observable,
interfaces.empty(), m_clientWrapper.expired(), false, false);
}
}
-#else
-OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper, const std::string& host,
- const std::string& uri, const std::string& serverId, bool observable,
- const std::vector<std::string>& resourceTypes,
- const std::vector<std::string>& interfaces)
- : m_clientWrapper(clientWrapper), m_uri(uri), m_resourceId(serverId, m_uri), m_host(host),
- m_isObservable(observable), m_isCollection(false), m_resourceTypes(resourceTypes),
- m_interfaces(interfaces), m_observeHandle(nullptr)
-{
- m_isCollection = std::find(m_interfaces.begin(), m_interfaces.end(), LINK_INTERFACE)
- != m_interfaces.end();
-
- if (m_uri.empty() ||
- resourceTypes.empty() ||
- interfaces.empty()||
- m_clientWrapper.expired())
- {
- throw ResourceInitException(m_uri.empty(), resourceTypes.empty(),
- interfaces.empty(), m_clientWrapper.expired(), false, false);
- }
-}
-#endif
OCResource::~OCResource()
{
OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap,
GetCallback attributeHandler, QualityOfService QoS)
{
-#ifdef CA_INT
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetResourceRepresentation,
m_host, m_uri, m_connectivityType, queryParametersMap, m_headerOptions,
attributeHandler, QoS);
-#else
- return checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetResourceRepresentation,
- m_host, m_uri, queryParametersMap, m_headerOptions, attributeHandler, QoS);
-#endif
}
OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap,
const QueryParamsMap& queryParametersMap, PutCallback attributeHandler,
QualityOfService QoS)
{
-#ifdef CA_INT
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PutResourceRepresentation,
m_host, m_uri, m_connectivityType, rep, queryParametersMap,
m_headerOptions, attributeHandler, QoS);
-#else
- return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PutResourceRepresentation,
- m_host, m_uri, rep, queryParametersMap, m_headerOptions, attributeHandler, QoS);
-#endif
}
OCStackResult OCResource::put(const OCRepresentation& rep,
const QueryParamsMap& queryParametersMap, PostCallback attributeHandler,
QualityOfService QoS)
{
-#ifdef CA_INT
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation,
m_host, m_uri, m_connectivityType, rep, queryParametersMap,
m_headerOptions, attributeHandler, QoS);
-#else
- return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation,
- m_host, m_uri, rep, queryParametersMap, m_headerOptions, attributeHandler, QoS);
-#endif
}
OCStackResult OCResource::post(const OCRepresentation& rep,
OCStackResult OCResource::deleteResource(DeleteCallback deleteHandler, QualityOfService QoS)
{
-#ifdef CA_INT
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource,
m_host, m_uri, m_connectivityType, m_headerOptions, deleteHandler, QoS);
-#else
- return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource,
- m_host, m_uri, m_headerOptions, deleteHandler, QoS);
-#endif
}
OCStackResult OCResource::deleteResource(DeleteCallback deleteHandler)
return result_guard(OC_STACK_INVALID_PARAM);
}
-#ifdef CA_INT
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::ObserveResource,
observeType, &m_observeHandle, m_host,
m_uri, m_connectivityType, queryParametersMap, m_headerOptions,
observeHandler, QoS);
-#else
- return checked_guard(m_clientWrapper.lock(), &IClientWrapper::ObserveResource,
- observeType, &m_observeHandle, m_host,
- m_uri, queryParametersMap, m_headerOptions, observeHandler, QoS);
-#endif
}
OCStackResult OCResource::observe(ObserveType observeType,
return m_uri;
}
-#ifdef CA_INT
OCConnectivityType OCResource::connectivityType() const
{
return m_connectivityType;
}
-#endif
bool OCResource::isObservable() const
{
oclib_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
oclib_env.AppendUnique(LIBS = ['octbstack', 'coap', 'oc_logger'])
-oclib_env.AppendUnique(CPPDEFINES = ['CA_INT'])
-
######################################################################
# Source files and Targets
######################################################################
CXX_LIBS += $(GTEST_LIBS) -L$(CONNECTIVITY_DIR)/build/out -lconnectivity_abstraction
CC_FLAGS.debug := -g -O0 -g3 -Wall -ffunction-sections -fdata-sections \
- -std=c++0x -pedantic $(INC_DIRS) -L$(ROOT_DIR)/$(BUILD) -DTB_LOG -DCA_INT
+ -std=c++0x -pedantic $(INC_DIRS) -L$(ROOT_DIR)/$(BUILD) -DTB_LOG
CC_FLAGS.release := -Os -Wall -fdata-sections -Wl,--gc-sections -Wl,-s \
- -std=c++0x $(INC_DIRS) -L$(ROOT_DIR)/$(BUILD) -DCA_INT
+ -std=c++0x $(INC_DIRS) -L$(ROOT_DIR)/$(BUILD)
-CPPFLAGS += $(CC_FLAGS.$(BUILD)) $(CXX_LIBS) -lpthread -DCA_INT
+CPPFLAGS += $(CC_FLAGS.$(BUILD)) $(CXX_LIBS) -lpthread
if env.get('SECURED') == '1':
sample_env.AppendUnique(LIBS = ['tinydtls'])
-sample_env.AppendUnique(CPPDEFINES = ['CA_INT'])
-
sample_env.ParseConfig('pkg-config --libs glib-2.0')
######################################################################
std::cout << "starting findResource = core.fan" << std::endl;
// Find all resources
-#ifdef CA_INT
OCPlatform::findResource("", requestURI, OC_WIFI,
&foundResourceFan);
-#else
- OCPlatform::findResource("", requestURI, &foundResourceFan);
-#endif
// Get time of day
timer = time(NULL);
// Converts date/time to a structure
std::cout << "starting findResource = core.light" << std::endl;
// Find all resources
-#ifdef CA_INT
OCPlatform::findResource("", requestURI, OC_WIFI,
&foundResourceLight);
-#else
- OCPlatform::findResource("", requestURI, &foundResourceLight);
-#endif
// Get time of day
timer = time(NULL);
// Converts date/time to a structure
soft_sensor_manager_env.Replace(CC = env.get('CXX'))
soft_sensor_manager_env.Replace(CFLAGS = env.get('CXXFLAGS'))
-soft_sensor_manager_env.AppendUnique(CPPDEFINES = ['CA_INT'])
-
######################################################################
# Build flags
######################################################################
switch (result)
{
case OC_STACK_OK:
-#ifdef CA_INT
ret = OC::OCPlatform::findResource("",
"coap://" + hostAddress + ":5298" + "/oc/core?rt=SoftSensorManager.Sensor", OC_ALL,
std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
-#else
- ret = OC::OCPlatform::findResource("",
- "coap://" + hostAddress + "/oc/core?rt=SoftSensorManager.Sensor",
- std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
-#endif
if (ret != OC_STACK_OK)
SSM_CLEANUP_ASSERT(SSM_E_FAIL);
SSMRESULT res = SSM_E_FAIL;
OCStackResult ret = OC_STACK_ERROR;
-#ifdef CA_INT
ret = OC::OCPlatform::findResource("",
"coap://224.0.1.187:5298/oc/core?rt=SoftSensorManager.Sensor", OC_ALL,
std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
-#else
- ret = OC::OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=SoftSensorManager.Sensor",
- std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
-#endif
if (ret != OC_STACK_OK)
SSM_CLEANUP_ASSERT(SSM_E_FAIL);
-#ifdef CA_INT
ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, "coap://224.0.1.187",
"SoftSensorManager.Sensor", OC_ALL,
std::bind(&CResourceFinder::presenceHandler, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
-#else
- ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, "coap://224.0.1.187",
- "SoftSensorManager.Sensor",
- std::bind(&CResourceFinder::presenceHandler, this, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3));
-#endif
if (ret != OC_STACK_OK)
SSM_CLEANUP_ASSERT(SSM_E_FAIL);
if (m_mapResourcePresenceHandles.find(((ISSMResource *)pMessage[1])->ip) ==
m_mapResourcePresenceHandles.end())
{
-#ifdef CA_INT
ret = OC::OCPlatform::subscribePresence(presenceHandle, ((ISSMResource *)pMessage[1])->ip,
"SoftSensorManager.Sensor", OC_ALL,
std::bind(&CResourceFinder::presenceHandler, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
-#else
- ret = OC::OCPlatform::subscribePresence(presenceHandle, ((ISSMResource *)pMessage[1])->ip,
- "SoftSensorManager.Sensor",
- std::bind(&CResourceFinder::presenceHandler, this, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3));
-#endif
if (ret != OC_STACK_OK)
SSM_CLEANUP_ASSERT(SSM_E_FAIL);
if target_os == 'android':
things_manager_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
-things_manager_env.AppendUnique(CPPDEFINES = ['CA_INT'])
-
######################################################################
# Source files and Targets
######################################################################
if env.get('SECURED') == '1':
linux_sample_env.AppendUnique(LIBS = ['tinydtls'])
-linux_sample_env.AppendUnique(CPPDEFINES = ['CA_INT'])
-
linux_sample_env.ParseConfig('pkg-config --libs glib-2.0')
######################################################################
std::string requestURI = OC_WELL_KNOWN_QUERY;
requestURI += "?rt=a.collection";
- #ifdef CA_INT
OCPlatform::findResource("", requestURI, OC_WIFI, &foundResource);
- #else
- OCPlatform::findResource("", requestURI, &foundResource);
- #endif
}
else if (n == 0)
{
std::string requestURI = OC_WELL_KNOWN_QUERY;
requestURI += "?rt=core.bookmark";
- #ifdef CA_INT
OCPlatform::findResource("", requestURI, OC_WIFI, &foundResource);
- #else
- OCPlatform::findResource("", requestURI, &foundResource);
- #endif
}
else if (n == 1)
{
if env.get('SECURED') == '1':
linux_sample_env.AppendUnique(LIBS = ['tinydtls'])
-linux_sample_env.AppendUnique(CPPDEFINES = ['CA_INT'])
-
linux_sample_env.ParseConfig('pkg-config --libs glib-2.0')
######################################################################
std::string requestURI = OC_WELL_KNOWN_QUERY;
requestURI += "?rt=core.musicplayer";
- #ifdef CA_INT
result = OCPlatform::findResource("", requestURI, OC_WIFI, onFindResource);
- #else
- result = OCPlatform::findResource("", requestURI, onFindResource);
- #endif
if (OC_STACK_OK == result)
{
cout << "Finding music player was successful\n";
std::string requestURI = OC_WELL_KNOWN_QUERY;
requestURI += "?rt=core.speaker";
- #ifdef CA_INT
result = OCPlatform::findResource("", requestURI, OC_WIFI, onFindResource);
- #else
- result = OCPlatform::findResource("", requestURI, onFindResource);
- #endif
if (OC_STACK_OK == result)
{
cout << "Finding speaker was successful\n";
query += "?rt=";
query += resourceTypes.at(i);
- #ifdef CA_INT
OCPlatform::findResource("", query, OC_WIFI,
std::function < void(std::shared_ptr < OCResource > resource)
> (std::bind(&GroupManager::onFoundResource, this,
std::placeholders::_1, waitsec)));
- #else
- OCPlatform::findResource("", query,
- std::function < void(std::shared_ptr < OCResource > resource)
- > (std::bind(&GroupManager::onFoundResource, this,
- std::placeholders::_1, waitsec)));
- #endif
}
if (waitsec >= 0)
std::cout << "\t\thost : " << hostAddress << std::endl;
OCPlatform::OCPresenceHandle presenceHandle;
- #ifdef CA_INT
OCStackResult result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
resourceType, OC_WIFI,
std::function<
std::bind(&GroupManager::collectionPresenceHandler, this,
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3, hostAddress, oit->getUri())));
- #else
- OCStackResult result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
- resourceType,
- std::function<
- void(OCStackResult result, const unsigned int nonce,
- const std::string& hostAddress) >(
- std::bind(&GroupManager::collectionPresenceHandler, this,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, hostAddress, oit->getUri())));
- #endif
if (result == OC_STACK_OK)
{
query += collectionResourceTypes.at(i);
cout << "GroupSynchronization::findGroup - " << query << endl;
-#ifdef CA_INT
OCPlatform::findResource("", query, OC_WIFI,
std::bind(&GroupSynchronization::onFindGroup, this, std::placeholders::_1));
-#else
- OCPlatform::findResource("", query,
- std::bind(&GroupSynchronization::onFindGroup, this, std::placeholders::_1));
-#endif
}
std::vector< std::string > resourceInterface;
resourceInterface.push_back(DEFAULT_INTERFACE);
-#ifdef CA_INT
OCResource::Ptr groupSyncResource = OCPlatform::constructResourceObject(host, uri, OC_WIFI,
1, resourceTypes, resourceInterface);
-#else
- OCResource::Ptr groupSyncResource = OCPlatform::constructResourceObject(host, uri, 1,
- resourceTypes, resourceInterface);
-
-#endif
groupSyncResourceList[type[0]] = groupSyncResource;
cout << "GroupSynchronization::joinGroup : creating groupSyncResource." << endl;
resourceRequest = request;
- #ifdef CA_INT
OCPlatform::findResource("", resourceName, OC_WIFI,
std::bind(&GroupSynchronization::onFindResource, this,
std::placeholders::_1));
- #else
- OCPlatform::findResource("", resourceName,
- std::bind(&GroupSynchronization::onFindResource, this,
- std::placeholders::_1));
- #endif
}
else if (methodType == "leaveGroup")
{
// For this reason, we create the resource objects.
std::string host = getHostFromURI(oit->getUri());
- #ifdef CA_INT
tempResource = OCPlatform::constructResourceObject(host, uri, OC_WIFI, true,
oit->getResourceTypes(), m_if);
- #else
- tempResource = OCPlatform::constructResourceObject(host, uri, true,
- oit->getResourceTypes(), m_if);
- #endif
p_resources.push_back(tempResource);
}