1 /* 2 * 3 * BlueZ - Bluetooth protocol stack for Linux 4 * 5 * Copyright (C) 2001-2002 Nokia Corporation 6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk (at) qualcomm.com> 7 * Copyright (C) 2002-2009 Marcel Holtmann <marcel (at) holtmann.org> 8 * Copyright (C) 2002-2003 Stephen Crane <steve.crane (at) rococosoft.com> 9 * 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 * 25 */ 26 27 #include <bluetooth/bluetooth.h> 28 #include <bluetooth/sdp.h> 29 30 #ifdef SDP_DEBUG 31 #include <syslog.h> 32 #define SDPDBG(fmt, arg...) syslog(LOG_DEBUG, "%s: " fmt "\n", __func__ , ## arg) 33 #else 34 #define SDPDBG(fmt...) 35 #endif 36 37 typedef struct request { 38 bdaddr_t device; 39 bdaddr_t bdaddr; 40 int local; 41 int sock; 42 int mtu; 43 int flags; 44 uint8_t *buf; 45 int len; 46 } sdp_req_t; 47 48 void handle_request(int sk, uint8_t *data, int len); 49 50 int service_register_req(sdp_req_t *req, sdp_buf_t *rsp); 51 int service_update_req(sdp_req_t *req, sdp_buf_t *rsp); 52 int service_remove_req(sdp_req_t *req, sdp_buf_t *rsp); 53 54 void register_public_browse_group(void); 55 void register_server_service(void); 56 void register_device_id(const uint16_t vendor, const uint16_t product, 57 const uint16_t version); 58 59 typedef struct { 60 uint32_t timestamp; 61 union { 62 uint16_t maxBytesSent; 63 uint16_t lastIndexSent; 64 } cStateValue; 65 } sdp_cont_state_t; 66 67 #define SDP_CONT_STATE_SIZE (sizeof(uint8_t) + sizeof(sdp_cont_state_t)) 68 69 sdp_buf_t *sdp_get_cached_rsp(sdp_cont_state_t *cstate); 70 void sdp_cstate_cache_init(void); 71 void sdp_cstate_clean_buf(void); 72 73 void sdp_svcdb_reset(void); 74 void sdp_svcdb_collect_all(int sock); 75 void sdp_svcdb_set_collectable(sdp_record_t *rec, int sock); 76 void sdp_svcdb_collect(sdp_record_t *rec); 77 sdp_record_t *sdp_record_find(uint32_t handle); 78 void sdp_record_add(const bdaddr_t *device, sdp_record_t *rec); 79 int sdp_record_remove(uint32_t handle); 80 sdp_list_t *sdp_get_record_list(void); 81 sdp_list_t *sdp_get_access_list(void); 82 int sdp_check_access(uint32_t handle, bdaddr_t *device); 83 uint32_t sdp_next_handle(void); 84 85 uint32_t sdp_get_time(); 86 87 #define SDP_SERVER_COMPAT (1 << 0) 88 #define SDP_SERVER_MASTER (1 << 1) 89 90 int start_sdp_server(uint16_t mtu, const char *did, uint32_t flags); 91 void stop_sdp_server(void); 92 93 int add_record_to_server(const bdaddr_t *src, sdp_record_t *rec); 94 int remove_record_from_server(uint32_t handle); 95 96 uint8_t get_service_classes(const bdaddr_t *bdaddr); 97 void create_ext_inquiry_response(const char *name, uint8_t *data); 98 static inline int android_get_control_socket(const char *name); 99