+exit:
+ OC_LOG_V(INFO, TAG, "Leave TelJpanHandler() with ret=%d", ret);
+ return ret;
+}
+
+TWResultCode TelEndDeviceJoinHandler(int count, char* tokens[])
+{
+ //Ask: AT+PJOIN
+ //
+ //Prompt: RFD:<IEEE Address>,<NodeID>
+ //Prompt: FFD:<IEEE Address>,<NodeID>
+ //Prompt: SED:<IEEE Address>,<NodeID>
+ //Prompt: ZED:<IEEE Address>,<NodeID>
+
+ OC_LOG_V(INFO, TAG, "Enter TelEndDeviceJoinHandler()");
+ TWResultCode ret = TW_RESULT_UNKNOWN;
+
+ if(!tokens || count != RESPONSE_PARAMS_COUNT_DEVICE_JOINED)
+ {
+ ret = TW_RESULT_ERROR_INVALID_PARAMS;
+ goto exit;
+ }
+
+ //TODO: Might need to add into the list if needed - log it for now.
+ OC_LOG_V(INFO, TAG, "Just Joined - EUI:%s; NodeID:%s.\n", tokens[0], tokens[1]);
+ ret = TW_RESULT_OK;
+
+exit:
+ OC_LOG_V(INFO, TAG, "Leave TelEndDeviceJoinHandler() with ret=%d", ret);
+ return ret;
+}
+
+TWResultCode TelMatchDescHandler(int count, char* tokens[])
+{
+ //Prompt: MatchDesc:0B4A,00,01
+
+ OC_LOG_V(INFO, TAG, "Enter TelMatchDescHandler()");
+ TWResultCode ret = TW_RESULT_ERROR;
+
+ if(!tokens || count != RESPONSE_PARAMS_COUNT_MATCH_DESC)
+ {
+ ret = TW_RESULT_ERROR_INVALID_PARAMS;
+ goto exit;
+ }
+
+ if (strcmp(tokens[1], AT_STR_ERROR_OK) != 0)
+ {
+ OC_LOG_V(INFO, TAG, "MatchDesc prompt contained error status.");
+ ret = TW_RESULT_ERROR;
+ goto exit;
+ }
+ else
+ {
+ char remoteEUI[SIZE_EUI];
+ ret = GetRemoteEUI(tokens[0], remoteEUI);
+ if (ret != TW_RESULT_OK)
+ {
+ OC_LOG_V(ERROR, TAG, "GetRemoteEUI()");
+ goto exit;
+ }
+ else
+ {
+ //Step 1: Create TWDevice
+ TWDevice* device = (TWDevice*)OICCalloc(1, sizeof(TWDevice));
+ if (device == NULL)
+ {
+ ret = TW_RESULT_ERROR_NO_MEMORY;
+ goto exit;
+ }
+ else
+ {
+ device->endpointOfInterest = (TWEndpoint*)OICCalloc(1, sizeof(TWEndpoint));
+ if (device->endpointOfInterest == NULL)
+ {
+ OICFree(device);
+ ret = TW_RESULT_ERROR_NO_MEMORY;
+ }
+ else
+ {
+ OICStrcpy(device->eui, SIZE_EUI, remoteEUI);
+ OICStrcpy(device->nodeId, SIZE_NODEID, tokens[0]);
+ OICStrcpy(device->endpointOfInterest->endpointId, SIZE_ENDPOINTID, tokens[2]);
+ g_WIPDevice = device;
+
+ //Step 2: Add to list
+ if (g_FoundMatchedDeviceList == NULL)
+ {
+ //Create a list of promptCount entries
+ g_FoundMatchedDeviceList = (TWDeviceList*)OICMalloc(sizeof(TWDeviceList));
+ if (g_FoundMatchedDeviceList == NULL)
+ {
+ OICFree(device->endpointOfInterest);
+ OICFree(device);
+ ret = TW_RESULT_ERROR_NO_MEMORY;
+ }
+ else
+ {
+ g_FoundMatchedDeviceList->count = 1;
+ g_FoundMatchedDeviceList->deviceList =
+ (TWDevice*)OICMalloc(sizeof(TWDevice));
+ if (g_FoundMatchedDeviceList->deviceList == NULL)
+ {
+ OICFree(device->endpointOfInterest);
+ OICFree(device);
+ ret = TW_RESULT_ERROR_NO_MEMORY;
+ }
+ else
+ {
+ memcpy(g_FoundMatchedDeviceList->deviceList,
+ device,
+ sizeof(TWDevice));
+ ret = TW_RESULT_OK;
+ }
+ }
+ }
+ else
+ {
+ //Expand the list
+ int newSize = sizeof(TWDevice) * (g_FoundMatchedDeviceList->count + 1);
+ TWDevice* temp = (TWDevice*)realloc(g_FoundMatchedDeviceList->deviceList,
+ newSize);
+ if (temp == NULL)
+ {
+ OICFree(device->endpointOfInterest);
+ OICFree(device);
+ ret =TW_RESULT_ERROR_NO_MEMORY;
+ }
+ else
+ {
+ g_FoundMatchedDeviceList->deviceList = temp;
+
+ //Add to the end of list
+ int count = g_FoundMatchedDeviceList->count;
+ memcpy(&g_FoundMatchedDeviceList->deviceList[count],
+ device,
+ sizeof(TWDevice));