1 /*
2  * Copyright (C) 2012 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 #pragma once
18 
19 #include <bluetooth/log.h>
20 
21 #include "hardware/bluetooth.h"
22 #include "types/raw_address.h"
23 
24 #define BTPAN_ROLE_NONE 0
25 #define BTPAN_ROLE_PANNAP 1
26 #define BTPAN_ROLE_PANU 2
27 
28 typedef enum {
29   BTPAN_STATE_CONNECTED = 0,
30   BTPAN_STATE_CONNECTING = 1,
31   BTPAN_STATE_DISCONNECTED = 2,
32   BTPAN_STATE_DISCONNECTING = 3
33 } btpan_connection_state_t;
34 
35 typedef enum { BTPAN_STATE_ENABLED = 0, BTPAN_STATE_DISABLED = 1 } btpan_control_state_t;
36 
37 /**
38  * Callback for pan connection state
39  */
40 typedef void (*btpan_connection_state_callback)(btpan_connection_state_t state, bt_status_t error,
41                                                 const RawAddress* bd_addr, int local_role,
42                                                 int remote_role);
43 typedef void (*btpan_control_state_callback)(btpan_control_state_t state, int local_role,
44                                              bt_status_t error, const char* ifname);
45 
46 typedef struct {
47   size_t size;
48   btpan_control_state_callback control_state_cb;
49   btpan_connection_state_callback connection_state_cb;
50 } btpan_callbacks_t;
51 typedef struct {
52   /** set to size of this struct*/
53   size_t size;
54   /**
55    * Initialize the pan interface and register the btpan callbacks
56    */
57   bt_status_t (*init)(const btpan_callbacks_t* callbacks);
58   /*
59    * enable the pan service by specified role. The result state of
60    * enabl will be returned by btpan_control_state_callback. when pan-nap is
61    * enabled, the state of connecting panu device will be notified by
62    * btpan_connection_state_callback
63    */
64   bt_status_t (*enable)(int local_role);
65   /*
66    * get current pan local role
67    */
68   int (*get_local_role)(void);
69   /**
70    * start bluetooth pan connection to the remote device by specified pan role.
71    * The result state will be returned by btpan_connection_state_callback
72    */
73   bt_status_t (*connect)(const RawAddress* bd_addr, int local_role, int remote_role);
74   /**
75    * stop bluetooth pan connection. The result state will be returned by
76    * btpan_connection_state_callback
77    */
78   bt_status_t (*disconnect)(const RawAddress* bd_addr);
79 
80   /**
81    * Cleanup the pan interface
82    */
83   void (*cleanup)(void);
84 } btpan_interface_t;
85 
86 namespace std {
87 template <>
88 struct formatter<btpan_connection_state_t> : enum_formatter<btpan_connection_state_t> {};
89 
90 template <>
91 struct formatter<btpan_control_state_t> : enum_formatter<btpan_control_state_t> {};
92 }  // namespace std
93