static void prv_handleRegistrationReply(lwm2m_transaction_t * transacP, void * message) { coap_packet_t * packet = (coap_packet_t *)message; lwm2m_server_t * targetP = (lwm2m_server_t *)(transacP->peerP); if (targetP->status == STATE_REG_PENDING) { time_t tv_sec = lwm2m_gettime(); if (tv_sec >= 0) { targetP->registration = tv_sec; } if (packet != NULL && packet->code == COAP_201_CREATED) { targetP->status = STATE_REGISTERED; if (NULL != targetP->location) { lwm2m_free(targetP->location); } targetP->location = coap_get_multi_option_as_string(packet->location_path); LOG(" => REGISTERED\r\n"); } else { targetP->status = STATE_REG_FAILED; LOG(" => Registration FAILED\r\n"); } } }
static void prv_resultCallback(lwm2m_transaction_t * transacP, void * message) { dm_data_t * dataP = (dm_data_t *)transacP->userData; if (message == NULL) { dataP->callback(dataP->clientID, &dataP->uri, COAP_503_SERVICE_UNAVAILABLE, LWM2M_CONTENT_TEXT, NULL, 0, dataP->userData); } else { coap_packet_t * packet = (coap_packet_t *)message; //if packet is a CREATE response and the instanceId was assigned by the client if (packet->code == COAP_201_CREATED && packet->location_path != NULL) { char * locationString = NULL; int result = 0; lwm2m_uri_t locationUri; locationString = coap_get_multi_option_as_string(packet->location_path); if (locationString == NULL) { LOG("Error: coap_get_multi_option_as_string() failed for Location_path option in prv_resultCallback()"); return; } result = lwm2m_stringToUri(locationString, strlen(locationString), &locationUri); if (result == 0) { LOG("Error: lwm2m_stringToUri() failed for Location_path option in prv_resultCallback()"); lwm2m_free(locationString); return; } ((dm_data_t*)transacP->userData)->uri.instanceId = locationUri.instanceId; ((dm_data_t*)transacP->userData)->uri.flag = locationUri.flag; lwm2m_free(locationString); } dataP->callback(dataP->clientID, &dataP->uri, packet->code, utils_convertMediaType(packet->content_type), packet->payload, packet->payload_len, dataP->userData); } lwm2m_free(dataP); }
static void prv_handleRegistrationReply(lwm2m_transaction_t * transacP, void * message) { lwm2m_server_t * targetP; coap_packet_t * packet = (coap_packet_t *)message; targetP = (lwm2m_server_t *)(transacP->peerP); struct timeval tv; switch(targetP->status) { case STATE_REG_PENDING: { if (packet == NULL) { targetP->status = STATE_UNKNOWN; targetP->mid = 0; } else if (packet->mid == targetP->mid && packet->type == COAP_TYPE_ACK && packet->location_path != NULL) { if (packet->code == CREATED_2_01) { targetP->status = STATE_REGISTERED; targetP->location = coap_get_multi_option_as_string(packet->location_path); if (0 == lwm2m_gettimeofday(&tv, NULL)) { targetP->registration = tv.tv_sec; } } else if (packet->code == BAD_REQUEST_4_00) { targetP->status = STATE_UNKNOWN; targetP->mid = 0; } } } break; default: break; } }
static void prv_resultCallback(lwm2m_context_t * contextP, lwm2m_transaction_t * transacP, void * message) { dm_data_t * dataP = (dm_data_t *)transacP->userData; (void)contextP; /* unused */ if (message == NULL) { dataP->callback(dataP->clientID, &dataP->uri, COAP_503_SERVICE_UNAVAILABLE, LWM2M_CONTENT_TEXT, NULL, 0, dataP->userData); } else { coap_packet_t * packet = (coap_packet_t *)message; //if packet is a CREATE response and the instanceId was assigned by the client if (packet->code == COAP_201_CREATED && packet->location_path != NULL) { char * locationString = NULL; int result = 0; lwm2m_uri_t locationUri; locationString = coap_get_multi_option_as_string(packet->location_path); if (locationString == NULL) { LOG("Error: coap_get_multi_option_as_string() failed for Location_path option in prv_resultCallback()"); return; } result = lwm2m_stringToUri(locationString, strlen(locationString), &locationUri); if (result == 0) { LOG("Error: lwm2m_stringToUri() failed for Location_path option in prv_resultCallback()"); lwm2m_free(locationString); return; } if (!LWM2M_URI_IS_SET_OBJECT(&locationUri) || !LWM2M_URI_IS_SET_INSTANCE(&locationUri) || LWM2M_URI_IS_SET_RESOURCE(&locationUri) || locationUri.objectId != ((dm_data_t*)transacP->userData)->uri.objectId) { LOG("Error: invalid Location_path option in prv_resultCallback()"); lwm2m_free(locationString); return; } memcpy(&((dm_data_t*)transacP->userData)->uri, &locationUri, sizeof(locationUri)); lwm2m_free(locationString); } dataP->callback(dataP->clientID, &dataP->uri, packet->code, utils_convertMediaType(packet->content_type), packet->payload, packet->payload_len, dataP->userData); } lwm2m_free(dataP); }