1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __BT_SDP_H__
18 #define __BT_SDP_H__
19 
20 #include <stdint.h>
21 // #include "bluetooth.h"
22 #include "common/bt_defs.h"
23 #include "esp_bt_defs.h"
24 
25 #define SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH 15
26 
27 /**
28  * These events are handled by the state machine
29  */
30 typedef enum {
31     SDP_TYPE_RAW,        // Used to carry raw SDP search data for unknown UUIDs
32     SDP_TYPE_MAP_MAS,    // Message Access Profile - Server
33     SDP_TYPE_MAP_MNS,    // Message Access Profile - Client (Notification Server)
34     SDP_TYPE_PBAP_PSE,   // Phone Book Profile - Server
35     SDP_TYPE_PBAP_PCE,   // Phone Book Profile - Client
36     SDP_TYPE_OPP_SERVER, // Object Push Profile
37     SDP_TYPE_SAP_SERVER  // SIM Access Profile
38 } bluetooth_sdp_types;
39 
40 typedef struct _bluetooth_sdp_hdr {
41     bluetooth_sdp_types type;
42     esp_bt_uuid_t       uuid;
43     uint32_t    service_name_length;
44     char       *service_name;
45     int32_t     rfcomm_channel_number;
46     int32_t     l2cap_psm;
47     int32_t     profile_version;
48 } bluetooth_sdp_hdr;
49 
50 /**
51  * Some signals need additional pointers, hence we introduce a
52  * generic way to handle these pointers.
53  */
54 typedef struct _bluetooth_sdp_hdr_overlay {
55     bluetooth_sdp_types type;
56     esp_bt_uuid_t       bt_uuid;
57     uint32_t    service_name_length;
58     char       *service_name;
59     int32_t     rfcomm_channel_number;
60     int32_t     l2cap_psm;
61     int32_t     profile_version;
62 
63     // User pointers, only used for some signals - see bluetooth_sdp_ops_record
64     int         user1_ptr_len;
65     uint8_t    *user1_ptr;
66     int         user2_ptr_len;
67     uint8_t    *user2_ptr;
68 } bluetooth_sdp_hdr_overlay;
69 
70 typedef struct _bluetooth_sdp_mas_record {
71     bluetooth_sdp_hdr_overlay hdr;
72     uint32_t    mas_instance_id;
73     uint32_t    supported_features;
74     uint32_t    supported_message_types;
75 } bluetooth_sdp_mas_record;
76 
77 typedef struct _bluetooth_sdp_mns_record {
78     bluetooth_sdp_hdr_overlay hdr;
79     uint32_t    supported_features;
80 } bluetooth_sdp_mns_record;
81 
82 typedef struct _bluetooth_sdp_pse_record {
83     bluetooth_sdp_hdr_overlay hdr;
84     uint32_t    supported_features;
85     uint32_t    supported_repositories;
86 } bluetooth_sdp_pse_record;
87 
88 typedef struct _bluetooth_sdp_pce_record {
89     bluetooth_sdp_hdr_overlay hdr;
90 } bluetooth_sdp_pce_record;
91 
92 typedef struct _bluetooth_sdp_ops_record {
93     bluetooth_sdp_hdr_overlay hdr;
94     int         supported_formats_list_len;
95     uint8_t     supported_formats_list[SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH];
96 } bluetooth_sdp_ops_record;
97 
98 typedef struct _bluetooth_sdp_sap_record {
99     bluetooth_sdp_hdr_overlay hdr;
100 } bluetooth_sdp_sap_record;
101 
102 typedef union {
103     bluetooth_sdp_hdr_overlay   hdr;
104     bluetooth_sdp_mas_record    mas;
105     bluetooth_sdp_mns_record    mns;
106     bluetooth_sdp_pse_record    pse;
107     bluetooth_sdp_pce_record    pce;
108     bluetooth_sdp_ops_record    ops;
109     bluetooth_sdp_sap_record    sap;
110 } bluetooth_sdp_record;
111 
112 #endif /* __BT_SDP_H__ */
113