summaryrefslogtreecommitdiffstats
path: root/bta/ar/bta_ar.c
blob: 89b732ab8feb6c74ce6d684670d1a266e4d3a6d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/******************************************************************************
 *
 *  Copyright (C) 2008-2012 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

/******************************************************************************
 *
 *  This is the implementation for the audio/video registration module.
 *
 ******************************************************************************/

#include <string.h>
#include "bta_ar_api.h"
#include "bta_ar_int.h"


/* AV control block */
#if BTA_DYNAMIC_MEMORY == FALSE
tBTA_AR_CB  bta_ar_cb;
#endif

/*******************************************************************************
**
** Function         bta_ar_id
**
** Description      This function maps sys_id to ar id mask.
**
** Returns          void
**
*******************************************************************************/
static UINT8 bta_ar_id(tBTA_SYS_ID sys_id)
{
    UINT8   mask = 0;
    if (sys_id == BTA_ID_AV)
    {
        mask = BTA_AR_AV_MASK;
    }
    else if (sys_id == BTA_ID_AVK)
    {
        mask = BTA_AR_AVK_MASK;
    }

    return mask;
}

/*******************************************************************************
**
** Function         bta_ar_init
**
** Description      This function is called to register to AVDTP.
**
** Returns          void
**
*******************************************************************************/
void bta_ar_init(void)
{
    /* initialize control block */
    memset(&bta_ar_cb, 0, sizeof(tBTA_AR_CB));
}

/*******************************************************************************
**
** Function         bta_ar_reg_avdt
**
** Description      This function is called to register to AVDTP.
**
** Returns          void
**
*******************************************************************************/
static void bta_ar_avdt_cback(UINT8 handle, BD_ADDR bd_addr, UINT8 event, tAVDT_CTRL *p_data)
{
    /* route the AVDT registration callback to av or avk */
    if (bta_ar_cb.p_av_conn_cback)
        (*bta_ar_cb.p_av_conn_cback)(handle, bd_addr, event, p_data);
    if (bta_ar_cb.p_avk_conn_cback)
        (*bta_ar_cb.p_avk_conn_cback)(handle, bd_addr, event, p_data);
}

/*******************************************************************************
**
** Function         bta_ar_reg_avdt
**
** Description      AR module registration to AVDT.
**
** Returns          void
**
*******************************************************************************/
void bta_ar_reg_avdt(tAVDT_REG *p_reg, tAVDT_CTRL_CBACK *p_cback, tBTA_SYS_ID sys_id)
{
    UINT8   mask = 0;

    if (sys_id == BTA_ID_AV)
    {
        bta_ar_cb.p_av_conn_cback = p_cback;
        mask = BTA_AR_AV_MASK;
    }
    else if (sys_id == BTA_ID_AVK)
    {
        bta_ar_cb.p_avk_conn_cback = p_cback;
        mask = BTA_AR_AVK_MASK;
    }
#if (BTA_AR_DEBUG == TRUE)
    else
    {
        APPL_TRACE_ERROR1("bta_ar_reg_avdt: the registration is from wrong sys_id:%d", sys_id);
    }
#endif

    if (mask)
    {
        if (bta_ar_cb.avdt_registered == 0)
        {
            AVDT_Register(p_reg, bta_ar_avdt_cback);
        }
        bta_ar_cb.avdt_registered |= mask;
    }
}

/*******************************************************************************
**
** Function         bta_ar_dereg_avdt
**
** Description      This function is called to de-register from AVDTP.
**
** Returns          void
**
*******************************************************************************/
void bta_ar_dereg_avdt(tBTA_SYS_ID sys_id)
{
    UINT8   mask = 0;

    if (sys_id == BTA_ID_AV)
    {
        bta_ar_cb.p_av_conn_cback = NULL;
        mask = BTA_AR_AV_MASK;
    }
    else if (sys_id == BTA_ID_AVK)
    {
        bta_ar_cb.p_avk_conn_cback = NULL;
        mask = BTA_AR_AVK_MASK;
    }
    bta_ar_cb.avdt_registered &= ~mask;

    if (bta_ar_cb.avdt_registered == 0)
        AVDT_Deregister();
}

/*******************************************************************************
**
** Function         bta_ar_avdt_conn
**
** Description      This function is called to let ar know that some AVDTP profile
**                  is connected for this sys_id.
**                  If the other sys modules started a timer for PENDING_EVT,
**                  the timer can be stopped now.
**
** Returns          void
**
*******************************************************************************/
void bta_ar_avdt_conn(tBTA_SYS_ID sys_id, BD_ADDR bd_addr)
{
    UINT8       event = BTA_AR_AVDT_CONN_EVT;
    tAVDT_CTRL  data;

    if (sys_id == BTA_ID_AV)
    {
        if (bta_ar_cb.p_avk_conn_cback)
        {
            (*bta_ar_cb.p_avk_conn_cback)(0, bd_addr, event, &data);
        }
    }
    else if (sys_id == BTA_ID_AVK)
    {
        if (bta_ar_cb.p_av_conn_cback)
        {
            (*bta_ar_cb.p_av_conn_cback)(0, bd_addr, event, &data);
        }
    }
}

/*******************************************************************************
**
** Function         bta_ar_reg_avct
**
** Description      This function is called to register to AVCTP.
**
** Returns          void
**
*******************************************************************************/
void bta_ar_reg_avct(UINT16 mtu, UINT16 mtu_br, UINT8 sec_mask, tBTA_SYS_ID sys_id)
{
    UINT8   mask = bta_ar_id (sys_id);

    if (mask)
    {
        if (bta_ar_cb.avct_registered == 0)
        {
            AVCT_Register(mtu, mtu_br, sec_mask);
        }
        bta_ar_cb.avct_registered |= mask;
    }
}

/*******************************************************************************
**
** Function         bta_ar_dereg_avct
**
** Description      This function is called to deregister from AVCTP.
**
** Returns          void
**
*******************************************************************************/
void bta_ar_dereg_avct(tBTA_SYS_ID sys_id)
{
    UINT8   mask = bta_ar_id (sys_id);

    bta_ar_cb.avct_registered &= ~mask;

    if (bta_ar_cb.avct_registered == 0)
        AVCT_Deregister();
}

/******************************************************************************
**
** Function         bta_ar_reg_avrc
**
** Description      This function is called to register an SDP record for AVRCP.
**
** Returns          void
**
******************************************************************************/
void bta_ar_reg_avrc(UINT16 service_uuid, char *service_name, char *provider_name,
					 UINT16 categories, tBTA_SYS_ID sys_id)
{
    UINT8   mask = bta_ar_id (sys_id);
    UINT8   temp[8], *p;

    if (!mask || !categories)
        return;

    if (service_uuid == UUID_SERVCLASS_AV_REM_CTRL_TARGET)
    {
        if (bta_ar_cb.sdp_tg_handle == 0)
        {
            bta_ar_cb.tg_registered = mask;
            bta_ar_cb.sdp_tg_handle = SDP_CreateRecord();
            AVRC_AddRecord(service_uuid, service_name, provider_name, categories, bta_ar_cb.sdp_tg_handle);
#if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&(BTA_EIR_CANNED_UUID_LIST != TRUE)
            bta_sys_add_uuid(service_uuid);
#endif
        }
        /* only one TG is allowed (first-come, first-served).
         * If sdp_tg_handle is non-0, ignore this request */
    }
    else if ((service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL) || (service_uuid == UUID_SERVCLASS_AV_REM_CTRL_CONTROL))
    {
        bta_ar_cb.ct_categories [mask - 1] = categories;
        categories = bta_ar_cb.ct_categories[0]|bta_ar_cb.ct_categories[1];
        if (bta_ar_cb.sdp_ct_handle == 0)
        {
            bta_ar_cb.sdp_ct_handle = SDP_CreateRecord();
            AVRC_AddRecord(service_uuid, service_name, provider_name, categories, bta_ar_cb.sdp_ct_handle);
#if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&(BTA_EIR_CANNED_UUID_LIST != TRUE)
            bta_sys_add_uuid(service_uuid);
#endif
        }
        else
        {
            /* multiple CTs are allowed.
             * Change supported categories on the second one */
            p = temp;
            UINT16_TO_BE_STREAM(p, categories);
            SDP_AddAttribute(bta_ar_cb.sdp_ct_handle, ATTR_ID_SUPPORTED_FEATURES, UINT_DESC_TYPE,
                      (UINT32)2, (UINT8*)temp);
        }
    }
}

/******************************************************************************
**
** Function         bta_ar_dereg_avrc
**
** Description      This function is called to de-register/delete an SDP record for AVRCP.
**
** Returns          void
**
******************************************************************************/
void bta_ar_dereg_avrc(UINT16 service_uuid, tBTA_SYS_ID sys_id)
{
    UINT8   mask = bta_ar_id (sys_id);
    UINT16  categories = 0;
    UINT8   temp[8], *p;

    if (!mask)
        return;

    if (service_uuid == UUID_SERVCLASS_AV_REM_CTRL_TARGET)
    {
        if (bta_ar_cb.sdp_tg_handle && mask == bta_ar_cb.tg_registered)
        {
            bta_ar_cb.tg_registered = 0;
            SDP_DeleteRecord(bta_ar_cb.sdp_tg_handle);
            bta_ar_cb.sdp_tg_handle = 0;
#if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&(BTA_EIR_CANNED_UUID_LIST != TRUE)
            bta_sys_remove_uuid(service_uuid);
#endif
        }
    }
    else if (service_uuid == UUID_SERVCLASS_AV_REMOTE_CONTROL)
    {
        if (bta_ar_cb.sdp_ct_handle)
        {
            bta_ar_cb.ct_categories [mask - 1] = 0;
            categories = bta_ar_cb.ct_categories[0]|bta_ar_cb.ct_categories[1];
            if (!categories)
            {
                /* no CT is still registered - cleaup */
                SDP_DeleteRecord(bta_ar_cb.sdp_ct_handle);
                bta_ar_cb.sdp_ct_handle = 0;
#if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&(BTA_EIR_CANNED_UUID_LIST != TRUE)
                bta_sys_remove_uuid(service_uuid);
#endif
            }
            else
            {
                /* change supported categories to the remaning one */
                p = temp;
                UINT16_TO_BE_STREAM(p, categories);
                SDP_AddAttribute(bta_ar_cb.sdp_ct_handle, ATTR_ID_SUPPORTED_FEATURES, UINT_DESC_TYPE,
                          (UINT32)2, (UINT8*)temp);
            }
        }
    }

}