1 /******************************************************************************
2 *
3 * Copyright (C) 2014 Google, Inc.
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 #include "base.h"
20 #include "support/callbacks.h"
21 #include "support/pan.h"
22
23 const btpan_interface_t *pan_interface;
24
25 static btpan_control_state_t pan_control_state;
26 static btpan_connection_state_t pan_connection_state;
27 static int pan_local_role;
28 static int pan_remote_role;
29 static bt_status_t pan_error;
30 static char *pan_ifname;
31
pan_init()32 bool pan_init() {
33 pan_interface = bt_interface->get_profile_interface(BT_PROFILE_PAN_ID);
34 return pan_interface->init(callbacks_get_pan_struct()) == BT_STATUS_SUCCESS;
35 }
36
pan_get_control_state()37 btpan_control_state_t pan_get_control_state() {
38 return pan_control_state;
39 }
40
pan_get_connection_state()41 btpan_connection_state_t pan_get_connection_state() {
42 return pan_connection_state;
43 }
44
pan_get_local_role()45 int pan_get_local_role() {
46 return pan_local_role;
47 }
48
pan_get_remote_role()49 int pan_get_remote_role() {
50 return pan_remote_role;
51 }
52
pan_get_error()53 bt_status_t pan_get_error() {
54 return pan_error;
55 }
56
57 // callback
pan_control_state_changed(btpan_control_state_t state,bt_status_t error,int local_role,const char * ifname)58 void pan_control_state_changed(btpan_control_state_t state, bt_status_t error, int local_role, const char *ifname) {
59 free(pan_ifname);
60
61 pan_control_state = state;
62 pan_local_role = local_role;
63 pan_error = error;
64 pan_ifname = strdup(ifname);
65
66 CALLBACK_RET();
67 }
68
69 // callback
pan_connection_state_changed(btpan_connection_state_t state,bt_status_t error,const bt_bdaddr_t * bd_addr,int local_role,int remote_role)70 void pan_connection_state_changed(btpan_connection_state_t state, bt_status_t error, const bt_bdaddr_t *bd_addr, int local_role, int remote_role) {
71 pan_connection_state = state;
72 pan_error = error;
73 pan_local_role = local_role;
74 pan_remote_role = remote_role;
75 CALLBACK_RET();
76 }
77