handle service without a name

This commit is contained in:
mila@ringwald.ch 2015-03-01 20:55:06 +00:00
parent 2e77e513be
commit 187d66ee88
2 changed files with 35 additions and 16 deletions

View File

@ -145,7 +145,7 @@ void parse(uint8_t eventByte){
case GET_ATTRIBUTE_ID_HEADER_LENGTH: case GET_ATTRIBUTE_ID_HEADER_LENGTH:
if (!de_state_size(eventByte, &de_header_state)) break; if (!de_state_size(eventByte, &de_header_state)) break;
attribute_id = 0; attribute_id = 0;
// log_info("ID data is stored in %d bytes.", de_header_state.de_size); log_info("ID data is stored in %d bytes.", de_header_state.de_size);
state = GET_ATTRIBUTE_ID; state = GET_ATTRIBUTE_ID;
break; break;
@ -153,7 +153,7 @@ void parse(uint8_t eventByte){
attribute_id = (attribute_id << 8) | eventByte; attribute_id = (attribute_id << 8) | eventByte;
de_header_state.de_size--; de_header_state.de_size--;
if (de_header_state.de_size > 0) break; if (de_header_state.de_size > 0) break;
// log_info("parser: Attribute ID: %04x.", attribute_id); log_info("parser: Attribute ID: %04x.", attribute_id);
state = GET_ATTRIBUTE_VALUE_LENGTH; state = GET_ATTRIBUTE_VALUE_LENGTH;
attribute_bytes_received = 0; attribute_bytes_received = 0;
@ -211,14 +211,14 @@ void parse(uint8_t eventByte){
if (list_size > 0 && list_offset != list_size){ if (list_size > 0 && list_offset != list_size){
record_counter++; record_counter++;
state = GET_RECORD_LENGTH; state = GET_RECORD_LENGTH;
// log_info("parser: END_OF_RECORD"); log_info("parser: END_OF_RECORD");
break; break;
} }
list_offset = 0; list_offset = 0;
de_state_init(&de_header_state); de_state_init(&de_header_state);
state = GET_LIST_LENGTH; state = GET_LIST_LENGTH;
record_counter = 0; record_counter = 0;
// log_info("parser: END_OF_RECORD & DONE"); log_info("parser: END_OF_RECORD & DONE");
break; break;
default: default:
break; break;

View File

@ -69,7 +69,7 @@ const uint8_t des_attributeIDList[] = { 0x35, 0x05, 0x0A, 0x00, 0x01, 0x01, 0
static uint8_t des_serviceSearchPattern[5] = {0x35, 0x03, 0x19, 0x00, 0x00}; static uint8_t des_serviceSearchPattern[5] = {0x35, 0x03, 0x19, 0x00, 0x00};
static uint8_t sdp_service_name[SDP_SERVICE_NAME_LEN+1]; static uint8_t sdp_service_name[SDP_SERVICE_NAME_LEN+1];
static uint8_t sdp_rfcom_channel_nr = 0; static uint8_t sdp_rfcomm_channel_nr = 0;
static uint8_t sdp_service_name_header_size; static uint8_t sdp_service_name_header_size;
static pdl_state_t pdl_state = GET_PROTOCOL_LIST_LENGTH; static pdl_state_t pdl_state = GET_PROTOCOL_LIST_LENGTH;
@ -89,6 +89,16 @@ static void (*sdp_app_callback)(sdp_query_event_t * event, void * context) = dum
static void dummy_notify_app(sdp_query_event_t* event, void * context){} static void dummy_notify_app(sdp_query_event_t* event, void * context){}
static void emit_service(){
sdp_query_rfcomm_service_event_t value_event = {
SDP_QUERY_RFCOMM_SERVICE,
sdp_rfcomm_channel_nr,
(uint8_t *) sdp_service_name
};
(*sdp_app_callback)((sdp_query_event_t*)&value_event, sdp_app_context);
sdp_rfcomm_channel_nr = 0;
}
void sdp_query_rfcomm_register_callback(void (*sdp_callback)(sdp_query_event_t* event, void * context), void * context){ void sdp_query_rfcomm_register_callback(void (*sdp_callback)(sdp_query_event_t* event, void * context), void * context){
sdp_app_callback = dummy_notify_app; sdp_app_callback = dummy_notify_app;
if (sdp_callback != NULL){ if (sdp_callback != NULL){
@ -164,7 +174,7 @@ void handleProtocolDescriptorListData(uint32_t attribute_value_length, uint32_t
protocol_value_size = de_header_state.de_size; protocol_value_size = de_header_state.de_size;
pdl_state = GET_PROTOCOL_VALUE; pdl_state = GET_PROTOCOL_VALUE;
sdp_rfcom_channel_nr = 0; sdp_rfcomm_channel_nr = 0;
break; break;
case GET_PROTOCOL_VALUE: case GET_PROTOCOL_VALUE:
@ -177,7 +187,7 @@ void handleProtocolDescriptorListData(uint32_t attribute_value_length, uint32_t
if (protocol_id == 0x0003){ if (protocol_id == 0x0003){
// log_info("\n\n ******* Data ***** %02x\n\n", data); // log_info("\n\n ******* Data ***** %02x\n\n", data);
sdp_rfcom_channel_nr = data; sdp_rfcomm_channel_nr = data;
} }
// log_info(" query: protocol done"); // log_info(" query: protocol done");
@ -231,21 +241,24 @@ void handleServiceNameData(uint32_t attribute_value_length, uint32_t data_offset
} }
// notify on last char // notify on last char
if (data_offset == attribute_value_length - 1 && sdp_rfcom_channel_nr!=0){ if (data_offset == attribute_value_length - 1 && sdp_rfcomm_channel_nr!=0){
sdp_query_rfcomm_service_event_t value_event = { emit_service();
SDP_QUERY_RFCOMM_SERVICE,
sdp_rfcom_channel_nr,
(uint8_t *) sdp_service_name
};
(*sdp_app_callback)((sdp_query_event_t*)&value_event, sdp_app_context);
sdp_rfcom_channel_nr = 0;
} }
} }
static void handle_sdp_parser_event(sdp_query_event_t * event){ static void handle_sdp_parser_event(sdp_query_event_t * event){
sdp_query_attribute_value_event_t * ve; sdp_query_attribute_value_event_t * ve;
switch (event->type){ switch (event->type){
case SDP_QUERY_SERVICE_RECORD_HANDLE:
// handle service without a name
if (sdp_rfcomm_channel_nr){
emit_service();
}
// prepare for new record
sdp_rfcomm_channel_nr = 0;
sdp_service_name[0] = 0;
break;
case SDP_QUERY_ATTRIBUTE_VALUE: case SDP_QUERY_ATTRIBUTE_VALUE:
ve = (sdp_query_attribute_value_event_t*) event; ve = (sdp_query_attribute_value_event_t*) event;
// log_info("handle_sdp_parser_event [ AID, ALen, DOff, Data] : [%x, %u, %u] BYTE %02x", // log_info("handle_sdp_parser_event [ AID, ALen, DOff, Data] : [%x, %u, %u] BYTE %02x",
@ -266,6 +279,10 @@ static void handle_sdp_parser_event(sdp_query_event_t * event){
} }
break; break;
case SDP_QUERY_COMPLETE: case SDP_QUERY_COMPLETE:
// handle service without a name
if (sdp_rfcomm_channel_nr){
emit_service();
}
(*sdp_app_callback)(event, sdp_app_context); (*sdp_app_callback)(event, sdp_app_context);
break; break;
} }
@ -279,6 +296,8 @@ void sdp_query_rfcomm_init(){
pdl_state = GET_PROTOCOL_LIST_LENGTH; pdl_state = GET_PROTOCOL_LIST_LENGTH;
protocol_offset = 0; protocol_offset = 0;
sdp_parser_register_callback(handle_sdp_parser_event); sdp_parser_register_callback(handle_sdp_parser_event);
sdp_rfcomm_channel_nr = 0;
sdp_service_name[0] = 0;
} }