]>
Commit | Line | Data |
---|---|---|
1ae26a18 AZ |
1 | /* |
2 | * QEMU Bluetooth HCI helpers. | |
3 | * | |
4 | * Copyright (C) 2007 OpenMoko, Inc. | |
5 | * Written by Andrzej Zaborowski <andrew@openedhand.com> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU General Public License as | |
9 | * published by the Free Software Foundation; either version 2 of | |
10 | * the License, or (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, | |
20 | * MA 02110-1301 USA | |
21 | */ | |
22 | ||
23 | /* BD Address */ | |
24 | typedef struct { | |
25 | uint8_t b[6]; | |
26 | } __attribute__((packed)) bdaddr_t; | |
27 | ||
28 | #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) | |
29 | #define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) | |
30 | #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) | |
31 | ||
32 | /* Copy, swap, convert BD Address */ | |
33 | static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2) | |
34 | { | |
35 | return memcmp(ba1, ba2, sizeof(bdaddr_t)); | |
36 | } | |
37 | static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src) | |
38 | { | |
39 | memcpy(dst, src, sizeof(bdaddr_t)); | |
40 | } | |
41 | ||
42 | #define BAINIT(orig) { .b = { \ | |
43 | (orig)->b[0], (orig)->b[1], (orig)->b[2], \ | |
44 | (orig)->b[3], (orig)->b[4], (orig)->b[5], \ | |
45 | }, } | |
46 | ||
47 | /* The twisted structures of a bluetooth environment */ | |
48 | struct bt_device_s; | |
49 | struct bt_scatternet_s; | |
50 | struct bt_piconet_s; | |
51 | struct bt_link_s; | |
52 | ||
53 | struct bt_scatternet_s { | |
54 | struct bt_device_s *slave; | |
55 | }; | |
56 | ||
57 | struct bt_link_s { | |
58 | struct bt_device_s *slave, *host; | |
59 | uint16_t handle; /* Master (host) side handle */ | |
60 | uint16_t acl_interval; | |
61 | enum { | |
62 | acl_active, | |
63 | acl_hold, | |
64 | acl_sniff, | |
65 | acl_parked, | |
66 | } acl_mode; | |
67 | }; | |
68 | ||
69 | struct bt_device_s { | |
70 | int lt_addr; | |
71 | bdaddr_t bd_addr; | |
72 | int mtu; | |
73 | int setup; | |
74 | struct bt_scatternet_s *net; | |
75 | ||
76 | uint8_t key[16]; | |
77 | int key_present; | |
78 | uint8_t class[3]; | |
79 | ||
80 | uint8_t reject_reason; | |
81 | ||
82 | uint64_t lmp_caps; | |
83 | const char *lmp_name; | |
84 | void (*lmp_connection_request)(struct bt_link_s *link); | |
85 | void (*lmp_connection_complete)(struct bt_link_s *link); | |
86 | void (*lmp_disconnect_master)(struct bt_link_s *link); | |
87 | void (*lmp_disconnect_slave)(struct bt_link_s *link); | |
88 | void (*lmp_acl_data)(struct bt_link_s *link, const uint8_t *data, | |
89 | int start, int len); | |
90 | void (*lmp_acl_resp)(struct bt_link_s *link, const uint8_t *data, | |
91 | int start, int len); | |
92 | void (*lmp_mode_change)(struct bt_link_s *link); | |
93 | ||
94 | void (*handle_destroy)(struct bt_device_s *device); | |
95 | struct bt_device_s *next; /* Next in the piconet/scatternet */ | |
96 | ||
97 | int inquiry_scan; | |
98 | int page_scan; | |
99 | ||
100 | uint16_t clkoff; /* Note: Always little-endian */ | |
101 | }; | |
102 | ||
103 | /* bt.c */ | |
104 | void bt_device_init(struct bt_device_s *dev, struct bt_scatternet_s *net); | |
105 | void bt_device_done(struct bt_device_s *dev); |