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 "btcore/include/bdaddr.h"
21#include "btcore/include/property.h"
22#include "support/adapter.h"
23#include "support/callbacks.h"
24
25static bt_state_t state;
26static int property_count = 0;
27static bt_property_t *properties = NULL;
28static bt_discovery_state_t discovery_state;
29static bt_acl_state_t acl_state;
30static bt_bond_state_t bond_state;
31
32bt_state_t adapter_get_state() {
33  return state;
34}
35
36int adapter_get_property_count() {
37  return property_count;
38}
39
40bt_property_t *adapter_get_property(bt_property_type_t type) {
41  for (int i = 0; i < property_count; ++i) {
42    if (properties[i].type == type) {
43      return &properties[i];
44    }
45  }
46
47  return NULL;
48}
49
50bt_discovery_state_t adapter_get_discovery_state() {
51  return discovery_state;
52}
53
54bt_acl_state_t adapter_get_acl_state() {
55  return acl_state;
56}
57
58// Returns the device bond state.
59bt_bond_state_t adapter_get_bond_state() {
60  return bond_state;
61}
62
63// callback
64void acl_state_changed(bt_status_t status, bt_bdaddr_t *remote_bd_addr, bt_acl_state_t state) {
65  acl_state = state;
66  CALLBACK_RET();
67}
68
69// callback
70void adapter_state_changed(bt_state_t new_state) {
71  state = new_state;
72  CALLBACK_RET();
73}
74
75// callback
76void adapter_properties(bt_status_t status,
77    int num_properties,
78    bt_property_t *new_properties) {
79  property_free_array(properties, property_count);
80  properties = property_copy_array(new_properties, num_properties);
81  property_count = num_properties;
82
83  CALLBACK_RET();
84}
85
86// callback
87void bond_state_changed(bt_status_t status,
88    bt_bdaddr_t *bdaddr,
89    bt_bond_state_t state) {
90  bond_state = state;
91  CALLBACK_RET();
92}
93
94// callback
95void device_found(int num_properties, bt_property_t *properties) {
96  CALLBACK_RET();
97}
98
99// callback
100void discovery_state_changed(bt_discovery_state_t state) {
101  discovery_state = state;
102  CALLBACK_RET();
103}
104
105// callback
106void remote_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
107    int num_properties, bt_property_t *properties) {
108  CALLBACK_RET();
109}
110
111// callback
112void ssp_request(
113    bt_bdaddr_t *remote_bd_addr,
114    bt_bdname_t *bd_name,
115    uint32_t cod,
116    bt_ssp_variant_t pairing_variant,
117    uint32_t pass_key) {
118
119  CALLBACK_RET();
120}
121
122// callback
123void thread_evt(bt_cb_thread_evt evt) {
124  CALLBACK_RET();
125}
126