blob: bec4142f271ea2c819e7b5c66344c5ea16fccce3 [file] [log] [blame]
Sharvil Nanavati3cf59ef2014-04-09 22:20:40 -07001/******************************************************************************
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
23const btpan_interface_t *pan_interface;
24
25static btpan_control_state_t pan_control_state;
26static btpan_connection_state_t pan_connection_state;
27static int pan_local_role;
28static int pan_remote_role;
29static bt_status_t pan_error;
30static char *pan_ifname;
31
32bool 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
37btpan_control_state_t pan_get_control_state() {
38 return pan_control_state;
39}
40
41btpan_connection_state_t pan_get_connection_state() {
42 return pan_connection_state;
43}
44
45int pan_get_local_role() {
46 return pan_local_role;
47}
48
49int pan_get_remote_role() {
50 return pan_remote_role;
51}
52
53bt_status_t pan_get_error() {
54 return pan_error;
55}
56
57// callback
58void pan_control_state_changed(btpan_control_state_t state, int local_role, bt_status_t error, 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
70void 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}