1 /******************************************************************************
2  *
3  *  Copyright 1999-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This file contains main functions to support PAN profile
22  *  commands and events.
23  *
24  ******************************************************************************/
25 
26 #include <string.h>
27 #include "bnep_api.h"
28 #include "bt_common.h"
29 #include "bt_types.h"
30 #include "bt_utils.h"
31 #include "hcidefs.h"
32 #include "l2c_api.h"
33 #include "osi/include/osi.h"
34 #include "pan_api.h"
35 #include "pan_int.h"
36 #include "sdp_api.h"
37 #include "sdpdefs.h"
38 
39 using bluetooth::Uuid;
40 
41 tPAN_CB pan_cb;
42 
43 /*******************************************************************************
44  *
45  * Function         pan_register_with_bnep
46  *
47  * Description      This function registers PAN profile with BNEP
48  *
49  * Parameters:      none
50  *
51  * Returns          none
52  *
53  ******************************************************************************/
pan_register_with_bnep(void)54 void pan_register_with_bnep(void) {
55   tBNEP_REGISTER reg_info;
56 
57   memset(&reg_info, 0, sizeof(tBNEP_REGISTER));
58 
59   reg_info.p_conn_ind_cb = pan_conn_ind_cb;
60   reg_info.p_conn_state_cb = pan_connect_state_cb;
61   reg_info.p_data_buf_cb = pan_data_buf_ind_cb;
62   reg_info.p_data_ind_cb = NULL;
63   reg_info.p_tx_data_flow_cb = pan_tx_data_flow_cb;
64   reg_info.p_filter_ind_cb = pan_proto_filt_ind_cb;
65   reg_info.p_mfilter_ind_cb = pan_mcast_filt_ind_cb;
66 
67   BNEP_Register(&reg_info);
68 }
69 
70 /*******************************************************************************
71  *
72  * Function         pan_conn_ind_cb
73  *
74  * Description      This function is registered with BNEP as connection
75  *                  indication callback. BNEP will call this when there is
76  *                  connection request from the peer. PAN should call
77  *                  BNEP_ConnectResp to indicate whether to accept the
78  *                  connection or reject
79  *
80  * Parameters:      handle      - handle for the connection
81  *                  p_bda       - BD Addr of the peer requesting the connection
82  *                  remote_uuid     - UUID of the source role (peer device role)
83  *                  local_uuid      - UUID of the destination role (local device
84  *                                                                  role)
85  *                  is_role_change  - Flag to indicate that it is a role change
86  *
87  * Returns          none
88  *
89  ******************************************************************************/
pan_conn_ind_cb(uint16_t handle,const RawAddress & p_bda,const Uuid & remote_uuid,const Uuid & local_uuid,bool is_role_change)90 void pan_conn_ind_cb(uint16_t handle, const RawAddress& p_bda,
91                      const Uuid& remote_uuid, const Uuid& local_uuid,
92                      bool is_role_change) {
93   /* If we are in GN or NAP role and have one or more active connections and the
94    * received connection is for user role reject it. If we are in user role with
95    * one connection active reject the connection. Allocate PCB and store the
96    * parameters. Make bridge request to the host system if connection is for NAP
97    */
98 
99   if (!remote_uuid.Is16Bit()) {
100     PAN_TRACE_ERROR("PAN Connection failed because of wrong remote UUID ");
101     BNEP_ConnectResp(handle, BNEP_CONN_FAILED_SRC_UUID);
102     return;
103   }
104 
105   if (!local_uuid.Is16Bit()) {
106     PAN_TRACE_ERROR("PAN Connection failed because of wrong local UUID ");
107     BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID);
108     return;
109   }
110 
111   uint16_t remote_uuid16 = remote_uuid.As16Bit();
112   uint16_t local_uuid16 = local_uuid.As16Bit();
113 
114   PAN_TRACE_EVENT(
115       "%s - handle %d, current role %d, dst uuid 0x%x, src uuid 0x%x, role "
116       "change %s",
117       __func__, handle, pan_cb.role, local_uuid16, remote_uuid16,
118       is_role_change ? "YES" : "NO");
119 
120   /* Check if the source UUID is a valid one */
121   if (remote_uuid16 != UUID_SERVCLASS_PANU &&
122       remote_uuid16 != UUID_SERVCLASS_NAP &&
123       remote_uuid16 != UUID_SERVCLASS_GN) {
124     PAN_TRACE_ERROR("Src UUID 0x%x is not valid", remote_uuid16);
125     BNEP_ConnectResp(handle, BNEP_CONN_FAILED_SRC_UUID);
126     return;
127   }
128 
129   /* Check if the destination UUID is a valid one */
130   if (local_uuid16 != UUID_SERVCLASS_PANU &&
131       local_uuid16 != UUID_SERVCLASS_NAP && local_uuid16 != UUID_SERVCLASS_GN) {
132     PAN_TRACE_ERROR("Dst UUID 0x%x is not valid", local_uuid16);
133     BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID);
134     return;
135   }
136 
137   /* Check if currently we support the destination role requested */
138   if (((!(pan_cb.role & UUID_SERVCLASS_PANU)) &&
139        local_uuid16 == UUID_SERVCLASS_PANU) ||
140       ((!(pan_cb.role & UUID_SERVCLASS_GN)) &&
141        local_uuid16 == UUID_SERVCLASS_GN) ||
142       ((!(pan_cb.role & UUID_SERVCLASS_NAP)) &&
143        local_uuid16 == UUID_SERVCLASS_NAP)) {
144     PAN_TRACE_ERROR(
145         "PAN Connection failed because of unsupported destination UUID 0x%x",
146         local_uuid16);
147     BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID);
148     return;
149   }
150 
151   /* Check for valid interactions between the three PAN profile roles */
152   /*
153    * For reference, see Table 1 in PAN Profile v1.0 spec.
154    * Note: the remote is the initiator.
155    */
156   bool is_valid_interaction = false;
157   switch (remote_uuid16) {
158     case UUID_SERVCLASS_NAP:
159     case UUID_SERVCLASS_GN:
160       if (local_uuid16 == UUID_SERVCLASS_PANU) is_valid_interaction = true;
161       break;
162     case UUID_SERVCLASS_PANU:
163       is_valid_interaction = true;
164       break;
165   }
166   /*
167    * Explicitly disable connections to the local PANU if the remote is
168    * not PANU.
169    */
170   if ((local_uuid16 == UUID_SERVCLASS_PANU) &&
171       (remote_uuid16 != UUID_SERVCLASS_PANU)) {
172     is_valid_interaction = false;
173   }
174   if (!is_valid_interaction) {
175     PAN_TRACE_ERROR(
176         "PAN Connection failed because of invalid PAN profile roles "
177         "interaction: Remote UUID 0x%x Local UUID 0x%x",
178         remote_uuid16, local_uuid16);
179     BNEP_ConnectResp(handle, BNEP_CONN_FAILED_SRC_UUID);
180     return;
181   }
182 
183   uint8_t req_role;
184   /* Requested destination role is */
185   if (local_uuid16 == UUID_SERVCLASS_PANU)
186     req_role = PAN_ROLE_CLIENT;
187   else if (local_uuid16 == UUID_SERVCLASS_GN)
188     req_role = PAN_ROLE_GN_SERVER;
189   else
190     req_role = PAN_ROLE_NAP_SERVER;
191 
192   /* If the connection indication is for the existing connection
193   ** Check if the new destination role is acceptable
194   */
195   tPAN_CONN* pcb = pan_get_pcb_by_handle(handle);
196   if (pcb) {
197     if (pan_cb.num_conns > 1 && local_uuid16 == UUID_SERVCLASS_PANU) {
198       /* There are connections other than this one
199       ** so we cann't accept PANU role. Reject
200       */
201       PAN_TRACE_ERROR(
202           "Dst UUID should be either GN or NAP only because there are other "
203           "connections");
204       BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID);
205       return;
206     }
207 
208     /* If it is already in connected state check for bridging status */
209     if (pcb->con_state == PAN_STATE_CONNECTED) {
210       PAN_TRACE_EVENT("PAN Role changing New Src 0x%x Dst 0x%x", remote_uuid16,
211                       local_uuid16);
212 
213       pcb->prv_src_uuid = pcb->src_uuid;
214       pcb->prv_dst_uuid = pcb->dst_uuid;
215 
216       if (pcb->src_uuid == UUID_SERVCLASS_NAP &&
217           local_uuid16 != UUID_SERVCLASS_NAP) {
218         /* Remove bridging */
219         if (pan_cb.pan_bridge_req_cb)
220           (*pan_cb.pan_bridge_req_cb)(pcb->rem_bda, false);
221       }
222     }
223     /* Set the latest active PAN role */
224     pan_cb.active_role = req_role;
225     pcb->src_uuid = local_uuid16;
226     pcb->dst_uuid = remote_uuid16;
227     BNEP_ConnectResp(handle, BNEP_SUCCESS);
228     return;
229   } else {
230     /* If this a new connection and destination is PANU role and
231     ** we already have a connection then reject the request.
232     ** If we have a connection in PANU role then reject it
233     */
234     if (pan_cb.num_conns && (local_uuid16 == UUID_SERVCLASS_PANU ||
235                              pan_cb.active_role == PAN_ROLE_CLIENT)) {
236       PAN_TRACE_ERROR("PAN already have a connection and can't be user");
237       BNEP_ConnectResp(handle, BNEP_CONN_FAILED_DST_UUID);
238       return;
239     }
240   }
241 
242   /* This is a new connection */
243   PAN_TRACE_DEBUG("New connection indication for handle %d", handle);
244   pcb = pan_allocate_pcb(p_bda, handle);
245   if (!pcb) {
246     PAN_TRACE_ERROR("PAN no control block for new connection");
247     BNEP_ConnectResp(handle, BNEP_CONN_FAILED);
248     return;
249   }
250 
251   PAN_TRACE_EVENT("PAN connection destination UUID is 0x%x", local_uuid16);
252   /* Set the latest active PAN role */
253   pan_cb.active_role = req_role;
254   pcb->src_uuid = local_uuid16;
255   pcb->dst_uuid = remote_uuid16;
256   pcb->con_state = PAN_STATE_CONN_START;
257   pan_cb.num_conns++;
258 
259   BNEP_ConnectResp(handle, BNEP_SUCCESS);
260   return;
261 }
262 
263 /*******************************************************************************
264  *
265  * Function         pan_connect_state_cb
266  *
267  * Description      This function is registered with BNEP as connection state
268  *                  change callback. BNEP will call this when the connection
269  *                  is established successfully or terminated
270  *
271  * Parameters:      handle  - handle for the connection given in the connection
272  *                            indication callback
273  *                  rem_bda - remote device bd addr
274  *                  result  - indicates whether the connection is up or down
275  *                            BNEP_SUCCESS if the connection is up all other
276  *                            values indicate appropriate errors.
277  *                  is_role_change - flag to indicate that it is a role change
278  *
279  * Returns          none
280  *
281  ******************************************************************************/
pan_connect_state_cb(uint16_t handle,UNUSED_ATTR const RawAddress & rem_bda,tBNEP_RESULT result,bool is_role_change)282 void pan_connect_state_cb(uint16_t handle,
283                           UNUSED_ATTR const RawAddress& rem_bda,
284                           tBNEP_RESULT result, bool is_role_change) {
285   tPAN_CONN* pcb;
286   uint8_t peer_role;
287 
288   PAN_TRACE_EVENT("pan_connect_state_cb - for handle %d, result %d", handle,
289                   result);
290   pcb = pan_get_pcb_by_handle(handle);
291   if (!pcb) {
292     PAN_TRACE_ERROR("PAN State change indication for wrong handle %d", handle);
293     return;
294   }
295 
296   /* If the connection is getting terminated remove bridging */
297   if (result != BNEP_SUCCESS) {
298     /* Inform the application that connection is down */
299     if (pan_cb.pan_conn_state_cb)
300       (*pan_cb.pan_conn_state_cb)(pcb->handle, pcb->rem_bda, result,
301                                   is_role_change, PAN_ROLE_INACTIVE,
302                                   PAN_ROLE_INACTIVE);
303 
304     /* Check if this failure is for role change only */
305     if (pcb->con_state != PAN_STATE_CONNECTED &&
306         (pcb->con_flags & PAN_FLAGS_CONN_COMPLETED)) {
307       /* restore the original values */
308       PAN_TRACE_EVENT("restoring the connection state to active");
309       pcb->con_state = PAN_STATE_CONNECTED;
310       pcb->con_flags &= (~PAN_FLAGS_CONN_COMPLETED);
311 
312       pcb->src_uuid = pcb->prv_src_uuid;
313       pcb->dst_uuid = pcb->prv_dst_uuid;
314       pan_cb.active_role = pan_cb.prv_active_role;
315 
316       if ((pcb->src_uuid == UUID_SERVCLASS_NAP) && pan_cb.pan_bridge_req_cb)
317         (*pan_cb.pan_bridge_req_cb)(pcb->rem_bda, true);
318 
319       return;
320     }
321 
322     if (pcb->con_state == PAN_STATE_CONNECTED) {
323       /* If the connections destination role is NAP remove bridging */
324       if ((pcb->src_uuid == UUID_SERVCLASS_NAP) && pan_cb.pan_bridge_req_cb)
325         (*pan_cb.pan_bridge_req_cb)(pcb->rem_bda, false);
326     }
327 
328     pan_cb.num_conns--;
329     pan_release_pcb(pcb);
330     return;
331   }
332 
333   /* Requested destination role is */
334   if (pcb->src_uuid == UUID_SERVCLASS_PANU)
335     pan_cb.active_role = PAN_ROLE_CLIENT;
336   else if (pcb->src_uuid == UUID_SERVCLASS_GN)
337     pan_cb.active_role = PAN_ROLE_GN_SERVER;
338   else
339     pan_cb.active_role = PAN_ROLE_NAP_SERVER;
340 
341   if (pcb->dst_uuid == UUID_SERVCLASS_PANU)
342     peer_role = PAN_ROLE_CLIENT;
343   else if (pcb->dst_uuid == UUID_SERVCLASS_GN)
344     peer_role = PAN_ROLE_GN_SERVER;
345   else
346     peer_role = PAN_ROLE_NAP_SERVER;
347 
348   pcb->con_state = PAN_STATE_CONNECTED;
349 
350   /* Inform the application that connection is down */
351   if (pan_cb.pan_conn_state_cb)
352     (*pan_cb.pan_conn_state_cb)(pcb->handle, pcb->rem_bda, PAN_SUCCESS,
353                                 is_role_change, pan_cb.active_role, peer_role);
354 
355   /* Create bridge if the destination role is NAP */
356   if (pan_cb.pan_bridge_req_cb && pcb->src_uuid == UUID_SERVCLASS_NAP) {
357     PAN_TRACE_EVENT("PAN requesting for bridge");
358     (*pan_cb.pan_bridge_req_cb)(pcb->rem_bda, true);
359   }
360 }
361 
362 /*******************************************************************************
363  *
364  * Function         pan_data_ind_cb
365  *
366  * Description      This function is registered with BNEP as data indication
367  *                  callback. BNEP will call this when the peer sends any data
368  *                  on this connection
369  *
370  * Parameters:      handle      - handle for the connection
371  *                  src         - source BD Addr
372  *                  dst         - destination BD Addr
373  *                  protocol    - Network protocol of the Eth packet
374  *                  p_data      - pointer to the data
375  *                  len         - length of the data
376  *                  fw_ext_present - to indicate whether the data contains any
377  *                                         extension headers before the payload
378  *
379  * Returns          none
380  *
381  ******************************************************************************/
pan_data_ind_cb(uint16_t handle,const RawAddress & src,const RawAddress & dst,uint16_t protocol,uint8_t * p_data,uint16_t len,bool ext)382 void pan_data_ind_cb(uint16_t handle, const RawAddress& src,
383                      const RawAddress& dst, uint16_t protocol, uint8_t* p_data,
384                      uint16_t len, bool ext) {
385   tPAN_CONN* pcb;
386   uint16_t i;
387   bool forward;
388 
389   /*
390   ** Check the connection status
391   ** If the destination address is MAC broadcast send on all links
392   ** except on the one received
393   ** If the destination uuid is for NAP send to host system also
394   ** If the destination address is one of the devices connected
395   ** send the packet to over that link
396   ** If the destination address is unknown and destination uuid is NAP
397   ** send it to the host system
398   */
399 
400   PAN_TRACE_EVENT("pan_data_ind_cb - for handle %d", handle);
401   pcb = pan_get_pcb_by_handle(handle);
402   if (!pcb) {
403     PAN_TRACE_ERROR("PAN Data indication for wrong handle %d", handle);
404     return;
405   }
406 
407   if (pcb->con_state != PAN_STATE_CONNECTED) {
408     PAN_TRACE_ERROR("PAN Data indication in wrong state %d for handle %d",
409                     pcb->con_state, handle);
410     return;
411   }
412 
413   /* Check if it is broadcast packet */
414   if (dst.address[0] & 0x01) {
415     PAN_TRACE_DEBUG("PAN received broadcast packet on handle %d, src uuid 0x%x",
416                     handle, pcb->src_uuid);
417     for (i = 0; i < MAX_PAN_CONNS; i++) {
418       if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED &&
419           pan_cb.pcb[i].handle != handle &&
420           pcb->src_uuid == pan_cb.pcb[i].src_uuid) {
421         BNEP_Write(pan_cb.pcb[i].handle, dst, p_data, len, protocol, &src, ext);
422       }
423     }
424 
425     if (pan_cb.pan_data_ind_cb)
426       (*pan_cb.pan_data_ind_cb)(pcb->handle, src, dst, protocol, p_data, len,
427                                 ext, true);
428 
429     return;
430   }
431 
432   /* Check if it is for any other PAN connection */
433   for (i = 0; i < MAX_PAN_CONNS; i++) {
434     if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED &&
435         pcb->src_uuid == pan_cb.pcb[i].src_uuid) {
436       if (pan_cb.pcb[i].rem_bda == dst) {
437         BNEP_Write(pan_cb.pcb[i].handle, dst, p_data, len, protocol, &src, ext);
438         return;
439       }
440     }
441   }
442 
443   if (pcb->src_uuid == UUID_SERVCLASS_NAP)
444     forward = true;
445   else
446     forward = false;
447 
448   /* Send it over the LAN or give it to host software */
449   if (pan_cb.pan_data_ind_cb)
450     (*pan_cb.pan_data_ind_cb)(pcb->handle, src, dst, protocol, p_data, len, ext,
451                               forward);
452 
453   return;
454 }
455 
456 /*******************************************************************************
457  *
458  * Function         pan_data_buf_ind_cb
459  *
460  * Description      This function is registered with BNEP as data buffer
461  *                  indication callback. BNEP will call this when the peer sends
462  *                  any data on this connection. PAN is responsible to release
463  *                  the buffer
464  *
465  * Parameters:      handle      - handle for the connection
466  *                  src         - source BD Addr
467  *                  dst         - destination BD Addr
468  *                  protocol    - Network protocol of the Eth packet
469  *                  p_buf       - pointer to the data buffer
470  *                  ext         - to indicate whether the data contains any
471  *                                         extension headers before the payload
472  *
473  * Returns          none
474  *
475  ******************************************************************************/
pan_data_buf_ind_cb(uint16_t handle,const RawAddress & src,const RawAddress & dst,uint16_t protocol,BT_HDR * p_buf,bool ext)476 void pan_data_buf_ind_cb(uint16_t handle, const RawAddress& src,
477                          const RawAddress& dst, uint16_t protocol,
478                          BT_HDR* p_buf, bool ext) {
479   tPAN_CONN *pcb, *dst_pcb;
480   tBNEP_RESULT result;
481   uint16_t i, len;
482   uint8_t* p_data;
483   bool forward = false;
484 
485   /* Check if the connection is in right state */
486   pcb = pan_get_pcb_by_handle(handle);
487   if (!pcb) {
488     PAN_TRACE_ERROR("PAN Data buffer indication for wrong handle %d", handle);
489     osi_free(p_buf);
490     return;
491   }
492 
493   if (pcb->con_state != PAN_STATE_CONNECTED) {
494     PAN_TRACE_ERROR("PAN Data indication in wrong state %d for handle %d",
495                     pcb->con_state, handle);
496     osi_free(p_buf);
497     return;
498   }
499 
500   p_data = (uint8_t*)(p_buf + 1) + p_buf->offset;
501   len = p_buf->len;
502 
503   PAN_TRACE_EVENT(
504       "pan_data_buf_ind_cb - for handle %d, protocol 0x%x, length %d, ext %d",
505       handle, protocol, len, ext);
506 
507   if (pcb->src_uuid == UUID_SERVCLASS_NAP)
508     forward = true;
509   else
510     forward = false;
511 
512   /* Check if it is broadcast or multicast packet */
513   if (pcb->src_uuid != UUID_SERVCLASS_PANU) {
514     if (dst.address[0] & 0x01) {
515       PAN_TRACE_DEBUG(
516           "PAN received broadcast packet on handle %d, src uuid 0x%x", handle,
517           pcb->src_uuid);
518       for (i = 0; i < MAX_PAN_CONNS; i++) {
519         if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED &&
520             pan_cb.pcb[i].handle != handle &&
521             pcb->src_uuid == pan_cb.pcb[i].src_uuid) {
522           BNEP_Write(pan_cb.pcb[i].handle, dst, p_data, len, protocol, &src,
523                      ext);
524         }
525       }
526 
527       if (pan_cb.pan_data_buf_ind_cb)
528         (*pan_cb.pan_data_buf_ind_cb)(pcb->handle, src, dst, protocol, p_buf,
529                                       ext, forward);
530       else if (pan_cb.pan_data_ind_cb)
531         (*pan_cb.pan_data_ind_cb)(pcb->handle, src, dst, protocol, p_data, len,
532                                   ext, forward);
533 
534       osi_free(p_buf);
535       return;
536     }
537 
538     /* Check if it is for any other PAN connection */
539     dst_pcb = pan_get_pcb_by_addr(dst);
540     if (dst_pcb) {
541       PAN_TRACE_EVENT(
542           "%s - destination PANU found on handle %d and sending data, len: %d",
543           __func__, dst_pcb->handle, len);
544 
545       result =
546           BNEP_Write(dst_pcb->handle, dst, p_data, len, protocol, &src, ext);
547       if (result != BNEP_SUCCESS && result != BNEP_IGNORE_CMD)
548         PAN_TRACE_ERROR("Failed to write data for PAN connection handle %d",
549                         dst_pcb->handle);
550       osi_free(p_buf);
551       return;
552     }
553   }
554 
555   /* Send it over the LAN or give it to host software */
556   if (pan_cb.pan_data_buf_ind_cb)
557     (*pan_cb.pan_data_buf_ind_cb)(pcb->handle, src, dst, protocol, p_buf, ext,
558                                   forward);
559   else if (pan_cb.pan_data_ind_cb)
560     (*pan_cb.pan_data_ind_cb)(pcb->handle, src, dst, protocol, p_data, len, ext,
561                               forward);
562   osi_free(p_buf);
563   return;
564 }
565 
566 /*******************************************************************************
567  *
568  * Function         pan_proto_filt_ind_cb
569  *
570  * Description      This function is registered with BNEP to receive tx data
571  *          flow status
572  *
573  * Parameters:      handle      - handle for the connection
574  *          event       - flow status
575  *
576  * Returns          none
577  *
578  ******************************************************************************/
pan_tx_data_flow_cb(uint16_t handle,tBNEP_RESULT event)579 void pan_tx_data_flow_cb(uint16_t handle, tBNEP_RESULT event) {
580   if (pan_cb.pan_tx_data_flow_cb) (*pan_cb.pan_tx_data_flow_cb)(handle, event);
581 
582   return;
583 }
584 
585 /*******************************************************************************
586  *
587  * Function         pan_proto_filt_ind_cb
588  *
589  * Description      This function is registered with BNEP as proto filter
590  *                  indication callback. BNEP will call this when the peer sends
591  *                  any protocol filter set for the connection or to indicate
592  *                  the result of the protocol filter set by the local device
593  *
594  * Parameters:      handle      - handle for the connection
595  *                  indication  - true if this is indication
596  *                                false if it is called to give the result of
597  *                                      local device protocol filter set
598  *                  result      - This gives the result of the filter set
599  *                                      operation
600  *                  num_filters - number of filters set by the peer device
601  *                  p_filters   - pointer to the filters set by the peer device
602  *
603  * Returns          none
604  *
605  ******************************************************************************/
pan_proto_filt_ind_cb(uint16_t handle,bool indication,tBNEP_RESULT result,uint16_t num_filters,uint8_t * p_filters)606 void pan_proto_filt_ind_cb(uint16_t handle, bool indication,
607                            tBNEP_RESULT result, uint16_t num_filters,
608                            uint8_t* p_filters) {
609   PAN_TRACE_EVENT(
610       "pan_proto_filt_ind_cb - called for handle %d with ind %d, result %d, "
611       "num %d",
612       handle, indication, result, num_filters);
613 
614   if (pan_cb.pan_pfilt_ind_cb)
615     (*pan_cb.pan_pfilt_ind_cb)(handle, indication, result, num_filters,
616                                p_filters);
617 }
618 
619 /*******************************************************************************
620  *
621  * Function         pan_mcast_filt_ind_cb
622  *
623  * Description      This function is registered with BNEP as mcast filter
624  *                  indication callback. BNEP will call this when the peer sends
625  *                  any multicast filter set for the connection or to indicate
626  *                  the result of the multicast filter set by the local device
627  *
628  * Parameters:      handle      - handle for the connection
629  *                  indication  - true if this is indication
630  *                                false if it is called to give the result of
631  *                                      local device multicast filter set
632  *                  result      - This gives the result of the filter set
633  *                                operation
634  *                  num_filters - number of filters set by the peer device
635  *                  p_filters   - pointer to the filters set by the peer device
636  *
637  * Returns          none
638  *
639  ******************************************************************************/
pan_mcast_filt_ind_cb(uint16_t handle,bool indication,tBNEP_RESULT result,uint16_t num_filters,uint8_t * p_filters)640 void pan_mcast_filt_ind_cb(uint16_t handle, bool indication,
641                            tBNEP_RESULT result, uint16_t num_filters,
642                            uint8_t* p_filters) {
643   PAN_TRACE_EVENT(
644       "pan_mcast_filt_ind_cb - called for handle %d with ind %d, result %d, "
645       "num %d",
646       handle, indication, result, num_filters);
647 
648   if (pan_cb.pan_mfilt_ind_cb)
649     (*pan_cb.pan_mfilt_ind_cb)(handle, indication, result, num_filters,
650                                p_filters);
651 }
652