📄 sdp_lib.h
字号:
/* * * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2001-2002 Nokia Corporation * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> * Copyright (C) 2002-2008 Marcel Holtmann <marcel@holtmann.org> * Copyright (C) 2002-2003 Stephen Crane <steve.crane@rococosoft.com> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */#ifndef __SDP_LIB_H#define __SDP_LIB_H#include <sys/socket.h>#include <bluetooth/bluetooth.h>#include <bluetooth/hci.h>#ifdef __cplusplusextern "C" {#endif/* * SDP lists */typedef void(*sdp_list_func_t)(void *, void *);typedef void(*sdp_free_func_t)(void *);typedef int (*sdp_comp_func_t)(const void *, const void *);sdp_list_t *sdp_list_append(sdp_list_t *list, void *d);sdp_list_t *sdp_list_remove(sdp_list_t *list, void *d);sdp_list_t *sdp_list_insert_sorted(sdp_list_t *list, void *data, sdp_comp_func_t f);void sdp_list_free(sdp_list_t *list, sdp_free_func_t f);static inline int sdp_list_len(const sdp_list_t *list) { int n = 0; for (; list; list = list->next) n++; return n;}static inline sdp_list_t *sdp_list_find(sdp_list_t *list, void *u, sdp_comp_func_t f){ for (; list; list = list->next) if (f(list->data, u) == 0) return list; return NULL;}static inline void sdp_list_foreach(sdp_list_t *list, sdp_list_func_t f, void *u){ for (; list; list = list->next) f(list->data, u);}/* * Values of the flags parameter to sdp_record_register */#define SDP_RECORD_PERSIST 0x01#define SDP_DEVICE_RECORD 0x02/* * Values of the flags parameter to sdp_connect */#define SDP_RETRY_IF_BUSY 0x01#define SDP_WAIT_ON_CLOSE 0x02#define SDP_NON_BLOCKING 0x04/* * a session with an SDP server */typedef struct { int sock; int state; int local; int flags; uint16_t tid; // Current transaction ID void *priv;} sdp_session_t;typedef enum { /* * Attributes are specified as individual elements */ SDP_ATTR_REQ_INDIVIDUAL = 1, /* * Attributes are specified as a range */ SDP_ATTR_REQ_RANGE} sdp_attrreq_type_t;/* * When the pdu_id(type) is a sdp error response, check the status value * to figure out the error reason. For status values 0x0001-0x0006 check * Bluetooth SPEC. If the status is 0xffff, call sdp_get_error function * to get the real reason: * - wrong transaction ID(EPROTO) * - wrong PDU id or(EPROTO) * - I/O error */typedef void sdp_callback_t(uint8_t type, uint16_t status, uint8_t *rsp, size_t size, void *udata);/* * create an L2CAP connection to a Bluetooth device * * INPUT: * * bdaddr_t *src: * Address of the local device to use to make the connection * (or BDADDR_ANY) * * bdaddr_t *dst: * Address of the SDP server device */sdp_session_t *sdp_connect(const bdaddr_t *src, const bdaddr_t *dst, uint32_t flags);int sdp_close(sdp_session_t *session);int sdp_get_socket(const sdp_session_t *session);/* * SDP transaction: functions for asynchronous search. */sdp_session_t *sdp_create(int sk, uint32_t flags);int sdp_get_error(sdp_session_t *session);int sdp_process(sdp_session_t *session);int sdp_set_notify(sdp_session_t *session, sdp_callback_t *func, void *udata);int sdp_service_search_async(sdp_session_t *session, const sdp_list_t *search, uint16_t max_rec_num);int sdp_service_attr_async(sdp_session_t *session, uint32_t handle, sdp_attrreq_type_t reqtype, const sdp_list_t *attrid_list);int sdp_service_search_attr_async(sdp_session_t *session, const sdp_list_t *search, sdp_attrreq_type_t reqtype, const sdp_list_t *attrid_list);uint16_t sdp_gen_tid(sdp_session_t *session);/* * find all devices in the piconet */int sdp_general_inquiry(inquiry_info *ii, int dev_num, int duration, uint8_t *found);/* flexible extraction of basic attributes - Jean II */int sdp_get_int_attr(const sdp_record_t *rec, uint16_t attr, int *value);int sdp_get_string_attr(const sdp_record_t *rec, uint16_t attr, char *value, int valuelen);/* * Basic sdp data functions */sdp_data_t *sdp_data_alloc(uint8_t dtd, const void *value);sdp_data_t *sdp_data_alloc_with_length(uint8_t dtd, const void *value, uint32_t length);void sdp_data_free(sdp_data_t *data);sdp_data_t *sdp_data_get(const sdp_record_t *rec, uint16_t attr_id);sdp_data_t *sdp_seq_alloc(void **dtds, void **values, int len);sdp_data_t *sdp_seq_alloc_with_length(void **dtds, void **values, int *length, int len);sdp_data_t *sdp_seq_append(sdp_data_t *seq, sdp_data_t *data);int sdp_attr_add(sdp_record_t *rec, uint16_t attr, sdp_data_t *data);void sdp_attr_remove(sdp_record_t *rec, uint16_t attr);void sdp_attr_replace(sdp_record_t *rec, uint16_t attr, sdp_data_t *data);int sdp_set_uuidseq_attr(sdp_record_t *rec, uint16_t attr, sdp_list_t *seq);int sdp_get_uuidseq_attr(const sdp_record_t *rec, uint16_t attr, sdp_list_t **seqp);/* * NOTE that none of the functions below will update the SDP server, * unless the {register, update}sdp_record_t() function is invoked. * All functions which return an integer value, return 0 on success * or -1 on failure. *//* * Create an attribute and add it to the service record's attribute list. * This consists of the data type descriptor of the attribute, * the value of the attribute and the attribute identifier. */int sdp_attr_add_new(sdp_record_t *rec, uint16_t attr, uint8_t dtd, const void *p);/* * Set the information attributes of the service record. * The set of attributes comprises service name, description * and provider name */void sdp_set_info_attr(sdp_record_t *rec, const char *name, const char *prov, const char *desc);/* * Set the ServiceClassID attribute to the sequence specified by seq. * Note that the identifiers need to be in sorted order from the most * specific to the most generic service class that this service * conforms to. */static inline int sdp_set_service_classes(sdp_record_t *rec, sdp_list_t *seq){ return sdp_set_uuidseq_attr(rec, SDP_ATTR_SVCLASS_ID_LIST, seq);}/* * Get the service classes to which the service conforms. * * When set, the list contains elements of ServiceClassIdentifer(uint16_t) * ordered from most specific to most generic */static inline int sdp_get_service_classes(const sdp_record_t *rec, sdp_list_t **seqp){ return sdp_get_uuidseq_attr(rec, SDP_ATTR_SVCLASS_ID_LIST, seqp);}/* * Set the BrowseGroupList attribute to the list specified by seq. * * A service can belong to one or more service groups * and the list comprises such group identifiers (UUIDs) */static inline int sdp_set_browse_groups(sdp_record_t *rec, sdp_list_t *seq){ return sdp_set_uuidseq_attr(rec, SDP_ATTR_BROWSE_GRP_LIST, seq);}/* * Set the access protocols of the record to those specified in proto */int sdp_set_access_protos(sdp_record_t *rec, const sdp_list_t *proto);/* * Set the additional access protocols of the record to those specified in proto */int sdp_set_add_access_protos(sdp_record_t *rec, const sdp_list_t *proto);/* * Get protocol port (i.e. PSM for L2CAP, Channel for RFCOMM) */int sdp_get_proto_port(const sdp_list_t *list, int proto);/* * Get protocol descriptor. */sdp_data_t *sdp_get_proto_desc(sdp_list_t *list, int proto);/* * Set the LanguageBase attributes to the values specified in list * (a linked list of sdp_lang_attr_t objects, one for each language in * which user-visible attributes are present). */int sdp_set_lang_attr(sdp_record_t *rec, const sdp_list_t *list);/* * Set the ServiceInfoTimeToLive attribute of the service. * This is the number of seconds that this record is guaranteed * not to change after being obtained by a client. */static inline int sdp_set_service_ttl(sdp_record_t *rec, uint32_t ttl){ return sdp_attr_add_new(rec, SDP_ATTR_SVCINFO_TTL, SDP_UINT32, &ttl);}/* * Set the ServiceRecordState attribute of a service. This is * guaranteed to change if there is any kind of modification to * the record. */static inline int sdp_set_record_state(sdp_record_t *rec, uint32_t state){ return sdp_attr_add_new(rec, SDP_ATTR_RECORD_STATE, SDP_UINT32, &state);}/* * Set the ServiceID attribute of a service. */void sdp_set_service_id(sdp_record_t *rec, uuid_t uuid);/* * Set the GroupID attribute of a service */void sdp_set_group_id(sdp_record_t *rec, uuid_t grouuuid);/* * Set the ServiceAvailability attribute of a service. * * Note that this represents the relative availability * of the service: 0x00 means completely unavailable; * 0xFF means maximum availability. */static inline int sdp_set_service_avail(sdp_record_t *rec, uint8_t avail){ return sdp_attr_add_new(rec, SDP_ATTR_SERVICE_AVAILABILITY, SDP_UINT8, &avail);}/* * Set the profile descriptor list attribute of a record. * * Each element in the list is an object of type * sdp_profile_desc_t which is a definition of the * Bluetooth profile that this service conforms to. */int sdp_set_profile_descs(sdp_record_t *rec, const sdp_list_t *desc);/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -