diff --git a/src/daemon.c b/src/daemon.c index 8d27be40c..edee51471 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -102,7 +102,7 @@ typedef struct { } client_state_t; // MARK: prototypes -static void handle_sdp_rfcomm_service_result(sdp_query_rfcomm_event_t * event, void * context); +static void handle_sdp_rfcomm_service_result(sdp_query_event_t * event, void * context); static void dummy_bluetooth_status_handler(BLUETOOTH_STATE state); static client_state_t * client_for_connection(connection_t *connection); static int clients_require_power_on(void); @@ -524,7 +524,7 @@ static void daemon_packet_handler(void * connection, uint8_t packet_type, uint16 } } -static void handle_sdp_rfcomm_service_result(sdp_query_rfcomm_event_t * rfcomm_event, void * context){ +static void handle_sdp_rfcomm_service_result(sdp_query_event_t * rfcomm_event, void * context){ switch (rfcomm_event->type){ case SDP_QUERY_RFCOMM_SERVICE: { sdp_query_rfcomm_service_event_t * service_event = (sdp_query_rfcomm_service_event_t*) rfcomm_event; @@ -540,7 +540,7 @@ static void handle_sdp_rfcomm_service_result(sdp_query_rfcomm_event_t * rfcomm_e break; } case SDP_QUERY_COMPLETE: { - sdp_query_rfcomm_complete_event_t * complete_event = (sdp_query_rfcomm_complete_event_t*) rfcomm_event; + sdp_query_complete_event_t * complete_event = (sdp_query_complete_event_t*) rfcomm_event; uint8_t event[] = { rfcomm_event->type, 1, complete_event->status}; hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event)); socket_connection_send_packet(context, HCI_EVENT_PACKET, 0, event, sizeof(event)); diff --git a/src/sdp_client.c b/src/sdp_client.c index 3e29ecdf0..c619e4066 100644 --- a/src/sdp_client.c +++ b/src/sdp_client.c @@ -1,10 +1,42 @@ +/* + * Copyright (C) 2009-2013 by Matthias Ringwald + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at btstack@ringwald.ch + * + */ -//***************************************************************************** -// -// minimal setup for SDP client over USB or UART -// -//***************************************************************************** - +/* + * sdp_client.c + */ #include "config.h" #include "sdp_client.h" @@ -57,6 +89,10 @@ void hexdump2(void *data, int size){ printf("\n"); } +/* Queries the SDP service of the remote device given a service search pattern +and a list of attribute IDs. The remote data is handled by the SDP parser. The +SDP parser delivers attribute values and done event via a registered callback. */ + void sdp_client_query(bd_addr_t remote, uint8_t * des_serviceSearchPattern, uint8_t * des_attributeIDList){ serviceSearchPattern = des_serviceSearchPattern; diff --git a/src/sdp_client.h b/src/sdp_client.h index dad5a444f..1c90b63a1 100644 --- a/src/sdp_client.h +++ b/src/sdp_client.h @@ -1,10 +1,47 @@ +/* + * Copyright (C) 2009-2013 by Matthias Ringwald + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at btstack@ringwald.ch + * + */ -//***************************************************************************** -// -// minimal setup for SDP client over USB or UART -// -//***************************************************************************** +/* + * sdp_client.h + */ #include +/* Queries the SDP service of the remote device given a service search pattern +and a list of attribute IDs. The remote data is handled by the SDP parser. The +SDP parser delivers attribute values and done event via a registered callback. */ + void sdp_client_query(bd_addr_t remote, uint8_t * des_serviceSearchPattern, uint8_t * des_attributeIDList); diff --git a/src/sdp_parser.c b/src/sdp_parser.c index 367cdaeb3..164883fae 100644 --- a/src/sdp_parser.c +++ b/src/sdp_parser.c @@ -1,3 +1,43 @@ +/* + * Copyright (C) 2009-2013 by Matthias Ringwald + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at btstack@ringwald.ch + * + */ + +/* + * sdp_parser.c + */ + #include "sdp_parser.h" #include "debug.h" diff --git a/src/sdp_parser.h b/src/sdp_parser.h index 50c211fe8..b0081b82c 100644 --- a/src/sdp_parser.h +++ b/src/sdp_parser.h @@ -1,9 +1,43 @@ +/* + * Copyright (C) 2009-2013 by Matthias Ringwald + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at btstack@ringwald.ch + * + */ + +/* + * sdp_parser.h + */ -//***************************************************************************** -// -// minimal setup for SDP client over USB or UART -// -//***************************************************************************** #include #include #include @@ -11,13 +45,20 @@ #include + +// Data Element stream parser helper typedef struct de_state { uint8_t in_state_GET_DE_HEADER_LENGTH ; uint32_t addon_header_bytes; uint32_t de_size; uint32_t de_offset; } de_state_t; +void de_state_init(de_state_t * state); +int de_state_size(uint8_t eventByte, de_state_t *de_state); +// SDP Parser + +// Basic SDP Parser event type typedef enum sdp_parser_event_type { SDP_PARSER_ATTRIBUTE_VALUE = 1, SDP_PARSER_COMPLETE, @@ -27,6 +68,7 @@ typedef struct sdp_parser_event { uint8_t type; } sdp_parser_event_t; +// SDP Parser event to deliver an attribute value byte by byte typedef struct sdp_parser_attribute_value_event { uint8_t type; int record_id; @@ -36,15 +78,16 @@ typedef struct sdp_parser_attribute_value_event { uint8_t data; } sdp_parser_attribute_value_event_t; +// SDP Parser event to indicate that processing is complete typedef struct sdp_parser_complete_event { uint8_t type; uint8_t status; // 0 == OK } sdp_parser_complete_event_t; -void de_state_init(de_state_t * state); -int de_state_size(uint8_t eventByte, de_state_t *de_state); void sdp_parser_init(); void sdp_parser_handle_chunk(uint8_t * data, uint16_t size); void sdp_parser_handle_done(uint8_t status); + +// Registers a callback to receive attribute value data and done event. void sdp_parser_register_callback(void (*sdp_callback)(sdp_parser_event_t* event)); diff --git a/src/sdp_query_rfcomm.c b/src/sdp_query_rfcomm.c index 7d9c41356..b023d2894 100644 --- a/src/sdp_query_rfcomm.c +++ b/src/sdp_query_rfcomm.c @@ -1,9 +1,42 @@ +/* + * Copyright (C) 2009-2013 by Matthias Ringwald + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at btstack@ringwald.ch + * + */ -//***************************************************************************** -// -// minimal setup for SDP client over USB or UART -// -//***************************************************************************** +/* + * sdp_rfcomm_query.c + */ #include "sdp_query_rfcomm.h" @@ -17,7 +50,7 @@ #include "sdp_client.h" -static void dummy_notify_app(sdp_query_rfcomm_event_t* event, void * context); +static void dummy_notify_app(sdp_query_event_t* event, void * context); typedef enum { GET_PROTOCOL_LIST_LENGTH = 1, @@ -52,13 +85,13 @@ static de_state_t de_header_state; static de_state_t sn_de_header_state; static void *sdp_app_context; -static void (*sdp_app_callback)(sdp_query_rfcomm_event_t * event, void * context) = dummy_notify_app; +static void (*sdp_app_callback)(sdp_query_event_t * event, void * context) = dummy_notify_app; // -static void dummy_notify_app(sdp_query_rfcomm_event_t* event, void * context){} +static void dummy_notify_app(sdp_query_event_t* event, void * context){} -void sdp_query_rfcomm_register_callback(void (*sdp_callback)(sdp_query_rfcomm_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; if (sdp_callback != NULL){ sdp_app_callback = sdp_callback; @@ -201,7 +234,7 @@ void handleServiceNameData(uint32_t attribute_value_length, uint32_t data_offset .channel_nr = sdp_rfcom_channel_nr }; printf("Service found %s\n", sdp_service_name); - (*sdp_app_callback)((sdp_query_rfcomm_event_t*)&value_event, sdp_app_context); + (*sdp_app_callback)((sdp_query_event_t*)&value_event, sdp_app_context); sdp_rfcom_channel_nr = 0; } } @@ -233,11 +266,11 @@ static void handle_sdp_parser_event(sdp_parser_event_t * event){ break; case SDP_PARSER_COMPLETE: ce = (sdp_parser_complete_event_t*) event; - sdp_query_rfcomm_complete_event_t c_event = { + sdp_query_complete_event_t c_event = { .type = SDP_QUERY_COMPLETE, .status = ce->status }; - (*sdp_app_callback)((sdp_query_rfcomm_event_t*)&c_event, sdp_app_context); + (*sdp_app_callback)((sdp_query_event_t*)&c_event, sdp_app_context); break; } // insert higher level code HERE diff --git a/src/sdp_query_rfcomm.h b/src/sdp_query_rfcomm.h index 2610710f2..ff6aef290 100644 --- a/src/sdp_query_rfcomm.h +++ b/src/sdp_query_rfcomm.h @@ -1,31 +1,72 @@ +/* + * Copyright (C) 2009-2013 by Matthias Ringwald + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at btstack@ringwald.ch + * + */ -//***************************************************************************** -// -// minimal setup for SDP client over USB or UART -// -//***************************************************************************** +/* + * sdp_rfcomm_query.h + */ #include #include "sdp_parser.h" - -typedef struct sdp_query_rfcomm_event { +// Basic SDP Query event type +typedef struct sdp_query_event { uint8_t type; -} sdp_query_rfcomm_event_t; +} sdp_query_event_t; +// SDP Query event to indicate that query is complete. +typedef struct sdp_query_complete_event { + uint8_t type; + uint8_t status; // 0 == OK +} sdp_query_complete_event_t; + +// SDP Query RFCOMM event to deliver channel number and service name byte by byte. typedef struct sdp_query_rfcomm_service_event { uint8_t type; uint8_t channel_nr; uint8_t * service_name; } sdp_query_rfcomm_service_event_t; -typedef struct sdp_query_rfcomm_complete_event { - uint8_t type; - uint8_t status; // 0 == OK -} sdp_query_rfcomm_complete_event_t; - void sdp_query_rfcomm_init(void); + +// Searches SDP records on a remote device for RFCOMM services with the given UUID. void sdp_query_rfcomm_channel_and_name_for_service_with_uuid(bd_addr_t remote, uint16_t uuid); + +// Searches SDP records on a remote device for RFCOMM services with a given service search pattern. void sdp_query_rfcomm_channel_and_name_for_service_with_service_search_pattern(bd_addr_t remote, uint8_t * des_serviceSearchPattern); -void sdp_query_rfcomm_register_callback(void(*sdp_app_callback)(sdp_query_rfcomm_event_t * event, void * context), void * context); + +// Registers a callback to receive RFCOMM service and done event. +void sdp_query_rfcomm_register_callback(void(*sdp_app_callback)(sdp_query_event_t * event, void * context), void * context);