aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/bluetooth
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/bluetooth')
-rw-r--r--include/net/bluetooth/bluetooth.h40
-rw-r--r--include/net/bluetooth/hci.h79
-rw-r--r--include/net/bluetooth/hci_core.h303
-rw-r--r--include/net/bluetooth/hci_mon.h51
-rw-r--r--include/net/bluetooth/l2cap.h87
-rw-r--r--include/net/bluetooth/mgmt.h338
-rw-r--r--include/net/bluetooth/smp.h2
7 files changed, 611 insertions, 289 deletions
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 4a82ca0bb0b2..262ebd1747d4 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -109,12 +109,14 @@ struct bt_power {
109 */ 109 */
110#define BT_CHANNEL_POLICY_AMP_PREFERRED 2 110#define BT_CHANNEL_POLICY_AMP_PREFERRED 2
111 111
112__printf(2, 3) 112__printf(1, 2)
113int bt_printk(const char *level, const char *fmt, ...); 113int bt_info(const char *fmt, ...);
114__printf(1, 2)
115int bt_err(const char *fmt, ...);
114 116
115#define BT_INFO(fmt, arg...) bt_printk(KERN_INFO, pr_fmt(fmt), ##arg) 117#define BT_INFO(fmt, ...) bt_info(fmt "\n", ##__VA_ARGS__)
116#define BT_ERR(fmt, arg...) bt_printk(KERN_ERR, pr_fmt(fmt), ##arg) 118#define BT_ERR(fmt, ...) bt_err(fmt "\n", ##__VA_ARGS__)
117#define BT_DBG(fmt, arg...) pr_debug(fmt "\n", ##arg) 119#define BT_DBG(fmt, ...) pr_debug(fmt "\n", ##__VA_ARGS__)
118 120
119/* Connection and socket states */ 121/* Connection and socket states */
120enum { 122enum {
@@ -129,6 +131,33 @@ enum {
129 BT_CLOSED 131 BT_CLOSED
130}; 132};
131 133
134/* If unused will be removed by compiler */
135static inline const char *state_to_string(int state)
136{
137 switch (state) {
138 case BT_CONNECTED:
139 return "BT_CONNECTED";
140 case BT_OPEN:
141 return "BT_OPEN";
142 case BT_BOUND:
143 return "BT_BOUND";
144 case BT_LISTEN:
145 return "BT_LISTEN";
146 case BT_CONNECT:
147 return "BT_CONNECT";
148 case BT_CONNECT2:
149 return "BT_CONNECT2";
150 case BT_CONFIG:
151 return "BT_CONFIG";
152 case BT_DISCONN:
153 return "BT_DISCONN";
154 case BT_CLOSED:
155 return "BT_CLOSED";
156 }
157
158 return "invalid state";
159}
160
132/* BD Address */ 161/* BD Address */
133typedef struct { 162typedef struct {
134 __u8 b[6]; 163 __u8 b[6];
@@ -193,7 +222,6 @@ struct bt_skb_cb {
193 __u16 tx_seq; 222 __u16 tx_seq;
194 __u8 retries; 223 __u8 retries;
195 __u8 sar; 224 __u8 sar;
196 unsigned short channel;
197 __u8 force_active; 225 __u8 force_active;
198}; 226};
199#define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb)) 227#define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb))
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 00596e816b4d..d47e523c9d83 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -77,14 +77,6 @@ enum {
77 77
78 HCI_RAW, 78 HCI_RAW,
79 79
80 HCI_SETUP,
81 HCI_AUTO_OFF,
82 HCI_MGMT,
83 HCI_PAIRABLE,
84 HCI_SERVICE_CACHE,
85 HCI_LINK_KEYS,
86 HCI_DEBUG_KEYS,
87
88 HCI_RESET, 80 HCI_RESET,
89}; 81};
90 82
@@ -93,7 +85,23 @@ enum {
93 * states from the controller. 85 * states from the controller.
94 */ 86 */
95enum { 87enum {
88 HCI_SETUP,
89 HCI_AUTO_OFF,
90 HCI_MGMT,
91 HCI_PAIRABLE,
92 HCI_SERVICE_CACHE,
93 HCI_LINK_KEYS,
94 HCI_DEBUG_KEYS,
95 HCI_UNREGISTER,
96
96 HCI_LE_SCAN, 97 HCI_LE_SCAN,
98 HCI_SSP_ENABLED,
99 HCI_HS_ENABLED,
100 HCI_LE_ENABLED,
101 HCI_CONNECTABLE,
102 HCI_DISCOVERABLE,
103 HCI_LINK_SECURITY,
104 HCI_PENDING_CLASS,
97}; 105};
98 106
99/* HCI ioctl defines */ 107/* HCI ioctl defines */
@@ -130,6 +138,7 @@ enum {
130#define HCI_IDLE_TIMEOUT (6000) /* 6 seconds */ 138#define HCI_IDLE_TIMEOUT (6000) /* 6 seconds */
131#define HCI_INIT_TIMEOUT (10000) /* 10 seconds */ 139#define HCI_INIT_TIMEOUT (10000) /* 10 seconds */
132#define HCI_CMD_TIMEOUT (1000) /* 1 seconds */ 140#define HCI_CMD_TIMEOUT (1000) /* 1 seconds */
141#define HCI_ACL_TX_TIMEOUT (45000) /* 45 seconds */
133 142
134/* HCI data types */ 143/* HCI data types */
135#define HCI_COMMAND_PKT 0x01 144#define HCI_COMMAND_PKT 0x01
@@ -229,7 +238,9 @@ enum {
229#define LMP_EXTFEATURES 0x80 238#define LMP_EXTFEATURES 0x80
230 239
231/* Extended LMP features */ 240/* Extended LMP features */
232#define LMP_HOST_LE 0x02 241#define LMP_HOST_SSP 0x01
242#define LMP_HOST_LE 0x02
243#define LMP_HOST_LE_BREDR 0x04
233 244
234/* Connection modes */ 245/* Connection modes */
235#define HCI_CM_ACTIVE 0x0000 246#define HCI_CM_ACTIVE 0x0000
@@ -268,10 +279,11 @@ enum {
268#define HCI_LK_UNAUTH_COMBINATION 0x04 279#define HCI_LK_UNAUTH_COMBINATION 0x04
269#define HCI_LK_AUTH_COMBINATION 0x05 280#define HCI_LK_AUTH_COMBINATION 0x05
270#define HCI_LK_CHANGED_COMBINATION 0x06 281#define HCI_LK_CHANGED_COMBINATION 0x06
271/* The spec doesn't define types for SMP keys */ 282/* The spec doesn't define types for SMP keys, the _MASTER suffix is implied */
272#define HCI_LK_SMP_LTK 0x81 283#define HCI_SMP_STK 0x80
273#define HCI_LK_SMP_IRK 0x82 284#define HCI_SMP_STK_SLAVE 0x81
274#define HCI_LK_SMP_CSRK 0x83 285#define HCI_SMP_LTK 0x82
286#define HCI_SMP_LTK_SLAVE 0x83
275 287
276/* ---- HCI Error Codes ---- */ 288/* ---- HCI Error Codes ---- */
277#define HCI_ERROR_AUTH_FAILURE 0x05 289#define HCI_ERROR_AUTH_FAILURE 0x05
@@ -284,6 +296,22 @@ enum {
284#define HCI_FLOW_CTL_MODE_PACKET_BASED 0x00 296#define HCI_FLOW_CTL_MODE_PACKET_BASED 0x00
285#define HCI_FLOW_CTL_MODE_BLOCK_BASED 0x01 297#define HCI_FLOW_CTL_MODE_BLOCK_BASED 0x01
286 298
299/* Extended Inquiry Response field types */
300#define EIR_FLAGS 0x01 /* flags */
301#define EIR_UUID16_SOME 0x02 /* 16-bit UUID, more available */
302#define EIR_UUID16_ALL 0x03 /* 16-bit UUID, all listed */
303#define EIR_UUID32_SOME 0x04 /* 32-bit UUID, more available */
304#define EIR_UUID32_ALL 0x05 /* 32-bit UUID, all listed */
305#define EIR_UUID128_SOME 0x06 /* 128-bit UUID, more available */
306#define EIR_UUID128_ALL 0x07 /* 128-bit UUID, all listed */
307#define EIR_NAME_SHORT 0x08 /* shortened local name */
308#define EIR_NAME_COMPLETE 0x09 /* complete local name */
309#define EIR_TX_POWER 0x0A /* transmit power level */
310#define EIR_CLASS_OF_DEV 0x0D /* Class of Device */
311#define EIR_SSP_HASH_C 0x0E /* Simple Pairing Hash C */
312#define EIR_SSP_RAND_R 0x0F /* Simple Pairing Randomizer R */
313#define EIR_DEVICE_ID 0x10 /* device ID */
314
287/* ----- HCI Commands ---- */ 315/* ----- HCI Commands ---- */
288#define HCI_OP_NOP 0x0000 316#define HCI_OP_NOP 0x0000
289 317
@@ -666,8 +694,8 @@ struct hci_cp_host_buffer_size {
666 694
667#define HCI_OP_WRITE_EIR 0x0c52 695#define HCI_OP_WRITE_EIR 0x0c52
668struct hci_cp_write_eir { 696struct hci_cp_write_eir {
669 uint8_t fec; 697 __u8 fec;
670 uint8_t data[HCI_MAX_EIR_LENGTH]; 698 __u8 data[HCI_MAX_EIR_LENGTH];
671} __packed; 699} __packed;
672 700
673#define HCI_OP_READ_SSP_MODE 0x0c55 701#define HCI_OP_READ_SSP_MODE 0x0c55
@@ -698,8 +726,8 @@ struct hci_rp_read_flow_control_mode {
698 726
699#define HCI_OP_WRITE_LE_HOST_SUPPORTED 0x0c6d 727#define HCI_OP_WRITE_LE_HOST_SUPPORTED 0x0c6d
700struct hci_cp_write_le_host_supported { 728struct hci_cp_write_le_host_supported {
701 __u8 le; 729 __u8 le;
702 __u8 simul; 730 __u8 simul;
703} __packed; 731} __packed;
704 732
705#define HCI_OP_READ_LOCAL_VERSION 0x1001 733#define HCI_OP_READ_LOCAL_VERSION 0x1001
@@ -1155,6 +1183,19 @@ struct hci_ev_le_meta {
1155 __u8 subevent; 1183 __u8 subevent;
1156} __packed; 1184} __packed;
1157 1185
1186#define HCI_EV_NUM_COMP_BLOCKS 0x48
1187struct hci_comp_blocks_info {
1188 __le16 handle;
1189 __le16 pkts;
1190 __le16 blocks;
1191} __packed;
1192
1193struct hci_ev_num_comp_blocks {
1194 __le16 num_blocks;
1195 __u8 num_hndl;
1196 struct hci_comp_blocks_info handles[0];
1197} __packed;
1198
1158/* Low energy meta events */ 1199/* Low energy meta events */
1159#define HCI_EV_LE_CONN_COMPLETE 0x01 1200#define HCI_EV_LE_CONN_COMPLETE 0x01
1160struct hci_ev_le_conn_complete { 1201struct hci_ev_le_conn_complete {
@@ -1287,7 +1328,8 @@ struct sockaddr_hci {
1287#define HCI_DEV_NONE 0xffff 1328#define HCI_DEV_NONE 0xffff
1288 1329
1289#define HCI_CHANNEL_RAW 0 1330#define HCI_CHANNEL_RAW 0
1290#define HCI_CHANNEL_CONTROL 1 1331#define HCI_CHANNEL_MONITOR 2
1332#define HCI_CHANNEL_CONTROL 3
1291 1333
1292struct hci_filter { 1334struct hci_filter {
1293 unsigned long type_mask; 1335 unsigned long type_mask;
@@ -1389,5 +1431,6 @@ struct hci_inquiry_req {
1389#define IREQ_CACHE_FLUSH 0x0001 1431#define IREQ_CACHE_FLUSH 0x0001
1390 1432
1391extern bool enable_hs; 1433extern bool enable_hs;
1434extern bool enable_le;
1392 1435
1393#endif /* __HCI_H */ 1436#endif /* __HCI_H */
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 453893b3120e..6822d2595aff 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -44,14 +44,31 @@ struct inquiry_data {
44}; 44};
45 45
46struct inquiry_entry { 46struct inquiry_entry {
47 struct inquiry_entry *next; 47 struct list_head all; /* inq_cache.all */
48 struct list_head list; /* unknown or resolve */
49 enum {
50 NAME_NOT_KNOWN,
51 NAME_NEEDED,
52 NAME_PENDING,
53 NAME_KNOWN,
54 } name_state;
48 __u32 timestamp; 55 __u32 timestamp;
49 struct inquiry_data data; 56 struct inquiry_data data;
50}; 57};
51 58
52struct inquiry_cache { 59struct discovery_state {
60 int type;
61 enum {
62 DISCOVERY_STOPPED,
63 DISCOVERY_STARTING,
64 DISCOVERY_FINDING,
65 DISCOVERY_RESOLVING,
66 DISCOVERY_STOPPING,
67 } state;
68 struct list_head all; /* All devices found during inquiry */
69 struct list_head unknown; /* Name state not known */
70 struct list_head resolve; /* Name needs to be resolved */
53 __u32 timestamp; 71 __u32 timestamp;
54 struct inquiry_entry *list;
55}; 72};
56 73
57struct hci_conn_hash { 74struct hci_conn_hash {
@@ -72,18 +89,16 @@ struct bt_uuid {
72 u8 svc_hint; 89 u8 svc_hint;
73}; 90};
74 91
75struct key_master_id { 92struct smp_ltk {
76 __le16 ediv; 93 struct list_head list;
77 u8 rand[8];
78} __packed;
79
80struct link_key_data {
81 bdaddr_t bdaddr; 94 bdaddr_t bdaddr;
95 u8 bdaddr_type;
96 u8 authenticated;
82 u8 type; 97 u8 type;
98 u8 enc_size;
99 __le16 ediv;
100 u8 rand[8];
83 u8 val[16]; 101 u8 val[16];
84 u8 pin_len;
85 u8 dlen;
86 u8 data[0];
87} __packed; 102} __packed;
88 103
89struct link_key { 104struct link_key {
@@ -92,8 +107,6 @@ struct link_key {
92 u8 type; 107 u8 type;
93 u8 val[16]; 108 u8 val[16];
94 u8 pin_len; 109 u8 pin_len;
95 u8 dlen;
96 u8 data[0];
97}; 110};
98 111
99struct oob_data { 112struct oob_data {
@@ -109,11 +122,19 @@ struct adv_entry {
109 u8 bdaddr_type; 122 u8 bdaddr_type;
110}; 123};
111 124
125struct le_scan_params {
126 u8 type;
127 u16 interval;
128 u16 window;
129 int timeout;
130};
131
132#define HCI_MAX_SHORT_NAME_LENGTH 10
133
112#define NUM_REASSEMBLY 4 134#define NUM_REASSEMBLY 4
113struct hci_dev { 135struct hci_dev {
114 struct list_head list; 136 struct list_head list;
115 struct mutex lock; 137 struct mutex lock;
116 atomic_t refcnt;
117 138
118 char name[8]; 139 char name[8];
119 unsigned long flags; 140 unsigned long flags;
@@ -122,6 +143,7 @@ struct hci_dev {
122 __u8 dev_type; 143 __u8 dev_type;
123 bdaddr_t bdaddr; 144 bdaddr_t bdaddr;
124 __u8 dev_name[HCI_MAX_NAME_LENGTH]; 145 __u8 dev_name[HCI_MAX_NAME_LENGTH];
146 __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH];
125 __u8 eir[HCI_MAX_EIR_LENGTH]; 147 __u8 eir[HCI_MAX_EIR_LENGTH];
126 __u8 dev_class[3]; 148 __u8 dev_class[3];
127 __u8 major_class; 149 __u8 major_class;
@@ -129,7 +151,6 @@ struct hci_dev {
129 __u8 features[8]; 151 __u8 features[8];
130 __u8 host_features[8]; 152 __u8 host_features[8];
131 __u8 commands[64]; 153 __u8 commands[64];
132 __u8 ssp_mode;
133 __u8 hci_ver; 154 __u8 hci_ver;
134 __u16 hci_rev; 155 __u16 hci_rev;
135 __u8 lmp_ver; 156 __u8 lmp_ver;
@@ -217,7 +238,7 @@ struct hci_dev {
217 238
218 struct list_head mgmt_pending; 239 struct list_head mgmt_pending;
219 240
220 struct inquiry_cache inq_cache; 241 struct discovery_state discovery;
221 struct hci_conn_hash conn_hash; 242 struct hci_conn_hash conn_hash;
222 struct list_head blacklist; 243 struct list_head blacklist;
223 244
@@ -225,6 +246,8 @@ struct hci_dev {
225 246
226 struct list_head link_keys; 247 struct list_head link_keys;
227 248
249 struct list_head long_term_keys;
250
228 struct list_head remote_oob_data; 251 struct list_head remote_oob_data;
229 252
230 struct list_head adv_entries; 253 struct list_head adv_entries;
@@ -234,7 +257,6 @@ struct hci_dev {
234 257
235 struct sk_buff_head driver_init; 258 struct sk_buff_head driver_init;
236 259
237 void *driver_data;
238 void *core_data; 260 void *core_data;
239 261
240 atomic_t promisc; 262 atomic_t promisc;
@@ -246,15 +268,17 @@ struct hci_dev {
246 268
247 struct rfkill *rfkill; 269 struct rfkill *rfkill;
248 270
249 struct module *owner;
250
251 unsigned long dev_flags; 271 unsigned long dev_flags;
252 272
273 struct delayed_work le_scan_disable;
274
275 struct work_struct le_scan;
276 struct le_scan_params le_scan_params;
277
253 int (*open)(struct hci_dev *hdev); 278 int (*open)(struct hci_dev *hdev);
254 int (*close)(struct hci_dev *hdev); 279 int (*close)(struct hci_dev *hdev);
255 int (*flush)(struct hci_dev *hdev); 280 int (*flush)(struct hci_dev *hdev);
256 int (*send)(struct sk_buff *skb); 281 int (*send)(struct sk_buff *skb);
257 void (*destruct)(struct hci_dev *hdev);
258 void (*notify)(struct hci_dev *hdev, unsigned int evt); 282 void (*notify)(struct hci_dev *hdev, unsigned int evt);
259 int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg); 283 int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
260}; 284};
@@ -270,11 +294,10 @@ struct hci_conn {
270 __u16 state; 294 __u16 state;
271 __u8 mode; 295 __u8 mode;
272 __u8 type; 296 __u8 type;
273 __u8 out; 297 bool out;
274 __u8 attempt; 298 __u8 attempt;
275 __u8 dev_class[3]; 299 __u8 dev_class[3];
276 __u8 features[8]; 300 __u8 features[8];
277 __u8 ssp_mode;
278 __u16 interval; 301 __u16 interval;
279 __u16 pkt_type; 302 __u16 pkt_type;
280 __u16 link_policy; 303 __u16 link_policy;
@@ -286,12 +309,10 @@ struct hci_conn {
286 __u8 pin_length; 309 __u8 pin_length;
287 __u8 enc_key_size; 310 __u8 enc_key_size;
288 __u8 io_capability; 311 __u8 io_capability;
289 __u8 power_save;
290 __u16 disc_timeout; 312 __u16 disc_timeout;
291 unsigned long pend; 313 unsigned long flags;
292 314
293 __u8 remote_cap; 315 __u8 remote_cap;
294 __u8 remote_oob;
295 __u8 remote_auth; 316 __u8 remote_auth;
296 317
297 unsigned int sent; 318 unsigned int sent;
@@ -348,21 +369,26 @@ extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
348#define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */ 369#define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */
349#define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */ 370#define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */
350 371
351static inline void inquiry_cache_init(struct hci_dev *hdev) 372static inline void discovery_init(struct hci_dev *hdev)
352{ 373{
353 struct inquiry_cache *c = &hdev->inq_cache; 374 hdev->discovery.state = DISCOVERY_STOPPED;
354 c->list = NULL; 375 INIT_LIST_HEAD(&hdev->discovery.all);
376 INIT_LIST_HEAD(&hdev->discovery.unknown);
377 INIT_LIST_HEAD(&hdev->discovery.resolve);
355} 378}
356 379
380bool hci_discovery_active(struct hci_dev *hdev);
381
382void hci_discovery_set_state(struct hci_dev *hdev, int state);
383
357static inline int inquiry_cache_empty(struct hci_dev *hdev) 384static inline int inquiry_cache_empty(struct hci_dev *hdev)
358{ 385{
359 struct inquiry_cache *c = &hdev->inq_cache; 386 return list_empty(&hdev->discovery.all);
360 return c->list == NULL;
361} 387}
362 388
363static inline long inquiry_cache_age(struct hci_dev *hdev) 389static inline long inquiry_cache_age(struct hci_dev *hdev)
364{ 390{
365 struct inquiry_cache *c = &hdev->inq_cache; 391 struct discovery_state *c = &hdev->discovery;
366 return jiffies - c->timestamp; 392 return jiffies - c->timestamp;
367} 393}
368 394
@@ -372,8 +398,16 @@ static inline long inquiry_entry_age(struct inquiry_entry *e)
372} 398}
373 399
374struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, 400struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
375 bdaddr_t *bdaddr); 401 bdaddr_t *bdaddr);
376void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data); 402struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
403 bdaddr_t *bdaddr);
404struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
405 bdaddr_t *bdaddr,
406 int state);
407void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
408 struct inquiry_entry *ie);
409bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
410 bool name_known, bool *ssp);
377 411
378/* ----- HCI Connections ----- */ 412/* ----- HCI Connections ----- */
379enum { 413enum {
@@ -384,8 +418,19 @@ enum {
384 HCI_CONN_MODE_CHANGE_PEND, 418 HCI_CONN_MODE_CHANGE_PEND,
385 HCI_CONN_SCO_SETUP_PEND, 419 HCI_CONN_SCO_SETUP_PEND,
386 HCI_CONN_LE_SMP_PEND, 420 HCI_CONN_LE_SMP_PEND,
421 HCI_CONN_MGMT_CONNECTED,
422 HCI_CONN_SSP_ENABLED,
423 HCI_CONN_POWER_SAVE,
424 HCI_CONN_REMOTE_OOB,
387}; 425};
388 426
427static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
428{
429 struct hci_dev *hdev = conn->hdev;
430 return (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) &&
431 test_bit(HCI_CONN_SSP_ENABLED, &conn->flags));
432}
433
389static inline void hci_conn_hash_init(struct hci_dev *hdev) 434static inline void hci_conn_hash_init(struct hci_dev *hdev)
390{ 435{
391 struct hci_conn_hash *h = &hdev->conn_hash; 436 struct hci_conn_hash *h = &hdev->conn_hash;
@@ -566,36 +611,33 @@ static inline void hci_conn_put(struct hci_conn *conn)
566} 611}
567 612
568/* ----- HCI Devices ----- */ 613/* ----- HCI Devices ----- */
569static inline void __hci_dev_put(struct hci_dev *d) 614static inline void hci_dev_put(struct hci_dev *d)
570{ 615{
571 if (atomic_dec_and_test(&d->refcnt)) 616 put_device(&d->dev);
572 d->destruct(d);
573} 617}
574 618
575/* 619static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
576 * hci_dev_put and hci_dev_hold are macros to avoid dragging all the
577 * overhead of all the modular infrastructure into this header.
578 */
579#define hci_dev_put(d) \
580do { \
581 __hci_dev_put(d); \
582 module_put(d->owner); \
583} while (0)
584
585static inline struct hci_dev *__hci_dev_hold(struct hci_dev *d)
586{ 620{
587 atomic_inc(&d->refcnt); 621 get_device(&d->dev);
588 return d; 622 return d;
589} 623}
590 624
591#define hci_dev_hold(d) \
592({ \
593 try_module_get(d->owner) ? __hci_dev_hold(d) : NULL; \
594})
595
596#define hci_dev_lock(d) mutex_lock(&d->lock) 625#define hci_dev_lock(d) mutex_lock(&d->lock)
597#define hci_dev_unlock(d) mutex_unlock(&d->lock) 626#define hci_dev_unlock(d) mutex_unlock(&d->lock)
598 627
628#define to_hci_dev(d) container_of(d, struct hci_dev, dev)
629#define to_hci_conn(c) container_of(c, struct hci_conn, dev)
630
631static inline void *hci_get_drvdata(struct hci_dev *hdev)
632{
633 return dev_get_drvdata(&hdev->dev);
634}
635
636static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
637{
638 dev_set_drvdata(&hdev->dev, data);
639}
640
599struct hci_dev *hci_dev_get(int index); 641struct hci_dev *hci_dev_get(int index);
600struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst); 642struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst);
601 643
@@ -619,20 +661,23 @@ int hci_inquiry(void __user *arg);
619 661
620struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr); 662struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr);
621int hci_blacklist_clear(struct hci_dev *hdev); 663int hci_blacklist_clear(struct hci_dev *hdev);
622int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr); 664int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
623int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr); 665int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
624 666
625int hci_uuids_clear(struct hci_dev *hdev); 667int hci_uuids_clear(struct hci_dev *hdev);
626 668
627int hci_link_keys_clear(struct hci_dev *hdev); 669int hci_link_keys_clear(struct hci_dev *hdev);
628struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 670struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
629int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, 671int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
630 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len); 672 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len);
631struct link_key *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]); 673struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]);
632struct link_key *hci_find_link_key_type(struct hci_dev *hdev, 674int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
633 bdaddr_t *bdaddr, u8 type); 675 int new_key, u8 authenticated, u8 tk[16], u8 enc_size, u16 ediv,
634int hci_add_ltk(struct hci_dev *hdev, int new_key, bdaddr_t *bdaddr, 676 u8 rand[8]);
635 u8 key_size, __le16 ediv, u8 rand[8], u8 ltk[16]); 677struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
678 u8 addr_type);
679int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr);
680int hci_smp_ltks_clear(struct hci_dev *hdev);
636int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 681int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
637 682
638int hci_remote_oob_data_clear(struct hci_dev *hdev); 683int hci_remote_oob_data_clear(struct hci_dev *hdev);
@@ -674,6 +719,7 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
674#define lmp_ssp_capable(dev) ((dev)->features[6] & LMP_SIMPLE_PAIR) 719#define lmp_ssp_capable(dev) ((dev)->features[6] & LMP_SIMPLE_PAIR)
675#define lmp_no_flush_capable(dev) ((dev)->features[6] & LMP_NO_FLUSH) 720#define lmp_no_flush_capable(dev) ((dev)->features[6] & LMP_NO_FLUSH)
676#define lmp_le_capable(dev) ((dev)->features[4] & LMP_LE) 721#define lmp_le_capable(dev) ((dev)->features[4] & LMP_LE)
722#define lmp_bredr_capable(dev) (!((dev)->features[4] & LMP_NO_BREDR))
677 723
678/* ----- Extended LMP capabilities ----- */ 724/* ----- Extended LMP capabilities ----- */
679#define lmp_host_le_capable(dev) ((dev)->host_features[0] & LMP_HOST_LE) 725#define lmp_host_le_capable(dev) ((dev)->host_features[0] & LMP_HOST_LE)
@@ -755,7 +801,7 @@ static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
755 if (conn->type != ACL_LINK && conn->type != LE_LINK) 801 if (conn->type != ACL_LINK && conn->type != LE_LINK)
756 return; 802 return;
757 803
758 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) 804 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
759 return; 805 return;
760 806
761 encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00; 807 encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
@@ -796,7 +842,7 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
796 842
797 hci_proto_auth_cfm(conn, status); 843 hci_proto_auth_cfm(conn, status);
798 844
799 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) 845 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
800 return; 846 return;
801 847
802 encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00; 848 encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
@@ -859,25 +905,73 @@ static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
859 read_unlock(&hci_cb_list_lock); 905 read_unlock(&hci_cb_list_lock);
860} 906}
861 907
908static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
909{
910 size_t parsed = 0;
911
912 if (data_len < 2)
913 return false;
914
915 while (parsed < data_len - 1) {
916 u8 field_len = data[0];
917
918 if (field_len == 0)
919 break;
920
921 parsed += field_len + 1;
922
923 if (parsed > data_len)
924 break;
925
926 if (data[1] == type)
927 return true;
928
929 data += field_len + 1;
930 }
931
932 return false;
933}
934
935static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
936 u8 data_len)
937{
938 eir[eir_len++] = sizeof(type) + data_len;
939 eir[eir_len++] = type;
940 memcpy(&eir[eir_len], data, data_len);
941 eir_len += data_len;
942
943 return eir_len;
944}
945
862int hci_register_cb(struct hci_cb *hcb); 946int hci_register_cb(struct hci_cb *hcb);
863int hci_unregister_cb(struct hci_cb *hcb); 947int hci_unregister_cb(struct hci_cb *hcb);
864 948
865int hci_register_notifier(struct notifier_block *nb);
866int hci_unregister_notifier(struct notifier_block *nb);
867
868int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param); 949int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param);
869void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags); 950void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
870void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); 951void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
871 952
872void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); 953void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
873 954
874void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data);
875
876/* ----- HCI Sockets ----- */ 955/* ----- HCI Sockets ----- */
877void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb, 956void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
878 struct sock *skip_sk); 957void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk);
958void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
959
960void hci_sock_dev_event(struct hci_dev *hdev, int event);
879 961
880/* Management interface */ 962/* Management interface */
963#define MGMT_ADDR_BREDR 0x00
964#define MGMT_ADDR_LE_PUBLIC 0x01
965#define MGMT_ADDR_LE_RANDOM 0x02
966#define MGMT_ADDR_INVALID 0xff
967
968#define DISCOV_TYPE_BREDR (BIT(MGMT_ADDR_BREDR))
969#define DISCOV_TYPE_LE (BIT(MGMT_ADDR_LE_PUBLIC) | \
970 BIT(MGMT_ADDR_LE_RANDOM))
971#define DISCOV_TYPE_INTERLEAVED (BIT(MGMT_ADDR_BREDR) | \
972 BIT(MGMT_ADDR_LE_PUBLIC) | \
973 BIT(MGMT_ADDR_LE_RANDOM))
974
881int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len); 975int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
882int mgmt_index_added(struct hci_dev *hdev); 976int mgmt_index_added(struct hci_dev *hdev);
883int mgmt_index_removed(struct hci_dev *hdev); 977int mgmt_index_removed(struct hci_dev *hdev);
@@ -886,56 +980,67 @@ int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable);
886int mgmt_connectable(struct hci_dev *hdev, u8 connectable); 980int mgmt_connectable(struct hci_dev *hdev, u8 connectable);
887int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status); 981int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);
888int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, 982int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
889 u8 persistent); 983 u8 persistent);
890int mgmt_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 984int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
891 u8 addr_type); 985 u8 addr_type, u32 flags, u8 *name, u8 name_len,
892int mgmt_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 986 u8 *dev_class);
893 u8 addr_type); 987int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
894int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status); 988 u8 link_type, u8 addr_type);
989int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
990 u8 link_type, u8 addr_type, u8 status);
895int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 991int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
896 u8 addr_type, u8 status); 992 u8 addr_type, u8 status);
897int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure); 993int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
898int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 994int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
899 u8 status); 995 u8 status);
900int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 996int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
901 u8 status); 997 u8 status);
902int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 998int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
903 __le32 value, u8 confirm_hint); 999 u8 link_type, u8 addr_type, __le32 value,
1000 u8 confirm_hint);
904int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1001int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
905 u8 status); 1002 u8 link_type, u8 addr_type, u8 status);
906int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, 1003int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
907 bdaddr_t *bdaddr, u8 status); 1004 u8 link_type, u8 addr_type, u8 status);
908int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr); 1005int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
1006 u8 link_type, u8 addr_type);
909int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1007int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
910 u8 status); 1008 u8 link_type, u8 addr_type, u8 status);
911int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, 1009int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
912 bdaddr_t *bdaddr, u8 status); 1010 u8 link_type, u8 addr_type, u8 status);
913int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status); 1011int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1012 u8 addr_type, u8 status);
1013int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
1014int mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
1015int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
1016 u8 status);
914int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); 1017int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
915int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash, 1018int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
916 u8 *randomizer, u8 status); 1019 u8 *randomizer, u8 status);
1020int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
917int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1021int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
918 u8 addr_type, u8 *dev_class, s8 rssi, u8 *eir); 1022 u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name,
919int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *name); 1023 u8 ssp, u8 *eir, u16 eir_len);
1024int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1025 u8 addr_type, s8 rssi, u8 *name, u8 name_len);
920int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status); 1026int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status);
921int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status); 1027int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status);
922int mgmt_discovering(struct hci_dev *hdev, u8 discovering); 1028int mgmt_discovering(struct hci_dev *hdev, u8 discovering);
923int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr); 1029int mgmt_interleaved_discovery(struct hci_dev *hdev);
924int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr); 1030int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
1031int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
1032
1033int mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, u8 persistent);
925 1034
926/* HCI info for socket */ 1035/* HCI info for socket */
927#define hci_pi(sk) ((struct hci_pinfo *) sk) 1036#define hci_pi(sk) ((struct hci_pinfo *) sk)
928 1037
929/* HCI socket flags */
930#define HCI_PI_MGMT_INIT 0
931
932struct hci_pinfo { 1038struct hci_pinfo {
933 struct bt_sock bt; 1039 struct bt_sock bt;
934 struct hci_dev *hdev; 1040 struct hci_dev *hdev;
935 struct hci_filter filter; 1041 struct hci_filter filter;
936 __u32 cmsg_mask; 1042 __u32 cmsg_mask;
937 unsigned short channel; 1043 unsigned short channel;
938 unsigned long flags;
939}; 1044};
940 1045
941/* HCI security filter */ 1046/* HCI security filter */
@@ -966,5 +1071,7 @@ void hci_le_ltk_neg_reply(struct hci_conn *conn);
966 1071
967int hci_do_inquiry(struct hci_dev *hdev, u8 length); 1072int hci_do_inquiry(struct hci_dev *hdev, u8 length);
968int hci_cancel_inquiry(struct hci_dev *hdev); 1073int hci_cancel_inquiry(struct hci_dev *hdev);
1074int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
1075 int timeout);
969 1076
970#endif /* __HCI_CORE_H */ 1077#endif /* __HCI_CORE_H */
diff --git a/include/net/bluetooth/hci_mon.h b/include/net/bluetooth/hci_mon.h
new file mode 100644
index 000000000000..77d1e5764185
--- /dev/null
+++ b/include/net/bluetooth/hci_mon.h
@@ -0,0 +1,51 @@
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3
4 Copyright (C) 2011-2012 Intel Corporation
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation;
9
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
11 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
13 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
14 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
19 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
20 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
21 SOFTWARE IS DISCLAIMED.
22*/
23
24#ifndef __HCI_MON_H
25#define __HCI_MON_H
26
27struct hci_mon_hdr {
28 __le16 opcode;
29 __le16 index;
30 __le16 len;
31} __packed;
32#define HCI_MON_HDR_SIZE 6
33
34#define HCI_MON_NEW_INDEX 0
35#define HCI_MON_DEL_INDEX 1
36#define HCI_MON_COMMAND_PKT 2
37#define HCI_MON_EVENT_PKT 3
38#define HCI_MON_ACL_TX_PKT 4
39#define HCI_MON_ACL_RX_PKT 5
40#define HCI_MON_SCO_TX_PKT 6
41#define HCI_MON_SCO_RX_PKT 7
42
43struct hci_mon_new_index {
44 __u8 type;
45 __u8 bus;
46 bdaddr_t bdaddr;
47 char name[8];
48} __packed;
49#define HCI_MON_NEW_INDEX_SIZE 16
50
51#endif /* __HCI_MON_H */
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index b1664ed884e6..9b242c6bf55b 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -45,11 +45,11 @@
45#define L2CAP_DEFAULT_SDU_ITIME 0xFFFFFFFF 45#define L2CAP_DEFAULT_SDU_ITIME 0xFFFFFFFF
46#define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF 46#define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF
47 47
48#define L2CAP_DISC_TIMEOUT (100) 48#define L2CAP_DISC_TIMEOUT msecs_to_jiffies(100)
49#define L2CAP_DISC_REJ_TIMEOUT (5000) /* 5 seconds */ 49#define L2CAP_DISC_REJ_TIMEOUT msecs_to_jiffies(5000)
50#define L2CAP_ENC_TIMEOUT (5000) /* 5 seconds */ 50#define L2CAP_ENC_TIMEOUT msecs_to_jiffies(5000)
51#define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */ 51#define L2CAP_CONN_TIMEOUT msecs_to_jiffies(40000)
52#define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */ 52#define L2CAP_INFO_TIMEOUT msecs_to_jiffies(4000)
53 53
54/* L2CAP socket address */ 54/* L2CAP socket address */
55struct sockaddr_l2 { 55struct sockaddr_l2 {
@@ -492,51 +492,56 @@ struct l2cap_chan {
492 struct sk_buff_head srej_q; 492 struct sk_buff_head srej_q;
493 struct list_head srej_l; 493 struct list_head srej_l;
494 494
495 struct list_head list; 495 struct list_head list;
496 struct list_head global_l; 496 struct list_head global_l;
497 497
498 void *data; 498 void *data;
499 struct l2cap_ops *ops; 499 struct l2cap_ops *ops;
500 struct mutex lock;
500}; 501};
501 502
502struct l2cap_ops { 503struct l2cap_ops {
503 char *name; 504 char *name;
504 505
505 struct l2cap_chan *(*new_connection) (void *data); 506 struct l2cap_chan *(*new_connection) (void *data);
506 int (*recv) (void *data, struct sk_buff *skb); 507 int (*recv) (void *data, struct sk_buff *skb);
507 void (*close) (void *data); 508 void (*close) (void *data);
508 void (*state_change) (void *data, int state); 509 void (*state_change) (void *data, int state);
510 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
511 unsigned long len, int nb, int *err);
512
509}; 513};
510 514
511struct l2cap_conn { 515struct l2cap_conn {
512 struct hci_conn *hcon; 516 struct hci_conn *hcon;
513 struct hci_chan *hchan; 517 struct hci_chan *hchan;
514 518
515 bdaddr_t *dst; 519 bdaddr_t *dst;
516 bdaddr_t *src; 520 bdaddr_t *src;
517 521
518 unsigned int mtu; 522 unsigned int mtu;
519 523
520 __u32 feat_mask; 524 __u32 feat_mask;
525 __u8 fixed_chan_mask;
521 526
522 __u8 info_state; 527 __u8 info_state;
523 __u8 info_ident; 528 __u8 info_ident;
524 529
525 struct delayed_work info_timer; 530 struct delayed_work info_timer;
526 531
527 spinlock_t lock; 532 spinlock_t lock;
528 533
529 struct sk_buff *rx_skb; 534 struct sk_buff *rx_skb;
530 __u32 rx_len; 535 __u32 rx_len;
531 __u8 tx_ident; 536 __u8 tx_ident;
532 537
533 __u8 disc_reason; 538 __u8 disc_reason;
534 539
535 struct delayed_work security_timer; 540 struct delayed_work security_timer;
536 struct smp_chan *smp_chan; 541 struct smp_chan *smp_chan;
537 542
538 struct list_head chan_l; 543 struct list_head chan_l;
539 struct mutex chan_lock; 544 struct mutex chan_lock;
540}; 545};
541 546
542#define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 547#define L2CAP_INFO_CL_MTU_REQ_SENT 0x01
@@ -551,9 +556,9 @@ struct l2cap_conn {
551#define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 556#define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
552 557
553struct l2cap_pinfo { 558struct l2cap_pinfo {
554 struct bt_sock bt; 559 struct bt_sock bt;
555 struct l2cap_chan *chan; 560 struct l2cap_chan *chan;
556 struct sk_buff *rx_busy_skb; 561 struct sk_buff *rx_busy_skb;
557}; 562};
558 563
559enum { 564enum {
@@ -606,21 +611,37 @@ static inline void l2cap_chan_put(struct l2cap_chan *c)
606 kfree(c); 611 kfree(c);
607} 612}
608 613
614static inline void l2cap_chan_lock(struct l2cap_chan *chan)
615{
616 mutex_lock(&chan->lock);
617}
618
619static inline void l2cap_chan_unlock(struct l2cap_chan *chan)
620{
621 mutex_unlock(&chan->lock);
622}
623
609static inline void l2cap_set_timer(struct l2cap_chan *chan, 624static inline void l2cap_set_timer(struct l2cap_chan *chan,
610 struct delayed_work *work, long timeout) 625 struct delayed_work *work, long timeout)
611{ 626{
612 BT_DBG("chan %p state %d timeout %ld", chan, chan->state, timeout); 627 BT_DBG("chan %p state %s timeout %ld", chan,
628 state_to_string(chan->state), timeout);
613 629
614 if (!cancel_delayed_work(work)) 630 if (!cancel_delayed_work(work))
615 l2cap_chan_hold(chan); 631 l2cap_chan_hold(chan);
616 schedule_delayed_work(work, timeout); 632 schedule_delayed_work(work, timeout);
617} 633}
618 634
619static inline void l2cap_clear_timer(struct l2cap_chan *chan, 635static inline bool l2cap_clear_timer(struct l2cap_chan *chan,
620 struct delayed_work *work) 636 struct delayed_work *work)
621{ 637{
622 if (cancel_delayed_work(work)) 638 bool ret;
639
640 ret = cancel_delayed_work(work);
641 if (ret)
623 l2cap_chan_put(chan); 642 l2cap_chan_put(chan);
643
644 return ret;
624} 645}
625 646
626#define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 647#define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t))
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index be65d3417883..ebfd91fc20f8 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -2,6 +2,7 @@
2 BlueZ - Bluetooth protocol stack for Linux 2 BlueZ - Bluetooth protocol stack for Linux
3 3
4 Copyright (C) 2010 Nokia Corporation 4 Copyright (C) 2010 Nokia Corporation
5 Copyright (C) 2011-2012 Intel Corporation
5 6
6 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as 8 it under the terms of the GNU General Public License version 2 as
@@ -39,29 +40,47 @@
39#define MGMT_STATUS_INVALID_PARAMS 0x0d 40#define MGMT_STATUS_INVALID_PARAMS 0x0d
40#define MGMT_STATUS_DISCONNECTED 0x0e 41#define MGMT_STATUS_DISCONNECTED 0x0e
41#define MGMT_STATUS_NOT_POWERED 0x0f 42#define MGMT_STATUS_NOT_POWERED 0x0f
43#define MGMT_STATUS_CANCELLED 0x10
44#define MGMT_STATUS_INVALID_INDEX 0x11
42 45
43struct mgmt_hdr { 46struct mgmt_hdr {
44 __le16 opcode; 47 __le16 opcode;
45 __le16 index; 48 __le16 index;
46 __le16 len; 49 __le16 len;
47} __packed; 50} __packed;
48 51
52struct mgmt_addr_info {
53 bdaddr_t bdaddr;
54 __u8 type;
55} __packed;
56#define MGMT_ADDR_INFO_SIZE 7
57
49#define MGMT_OP_READ_VERSION 0x0001 58#define MGMT_OP_READ_VERSION 0x0001
59#define MGMT_READ_VERSION_SIZE 0
50struct mgmt_rp_read_version { 60struct mgmt_rp_read_version {
51 __u8 version; 61 __u8 version;
52 __le16 revision; 62 __le16 revision;
63} __packed;
64
65#define MGMT_OP_READ_COMMANDS 0x0002
66#define MGMT_READ_COMMANDS_SIZE 0
67struct mgmt_rp_read_commands {
68 __le16 num_commands;
69 __le16 num_events;
70 __le16 opcodes[0];
53} __packed; 71} __packed;
54 72
55#define MGMT_OP_READ_INDEX_LIST 0x0003 73#define MGMT_OP_READ_INDEX_LIST 0x0003
74#define MGMT_READ_INDEX_LIST_SIZE 0
56struct mgmt_rp_read_index_list { 75struct mgmt_rp_read_index_list {
57 __le16 num_controllers; 76 __le16 num_controllers;
58 __le16 index[0]; 77 __le16 index[0];
59} __packed; 78} __packed;
60 79
61/* Reserve one extra byte for names in management messages so that they 80/* Reserve one extra byte for names in management messages so that they
62 * are always guaranteed to be nul-terminated */ 81 * are always guaranteed to be nul-terminated */
63#define MGMT_MAX_NAME_LENGTH (HCI_MAX_NAME_LENGTH + 1) 82#define MGMT_MAX_NAME_LENGTH (HCI_MAX_NAME_LENGTH + 1)
64#define MGMT_MAX_SHORT_NAME_LENGTH (10 + 1) 83#define MGMT_MAX_SHORT_NAME_LENGTH (HCI_MAX_SHORT_NAME_LENGTH + 1)
65 84
66#define MGMT_SETTING_POWERED 0x00000001 85#define MGMT_SETTING_POWERED 0x00000001
67#define MGMT_SETTING_CONNECTABLE 0x00000002 86#define MGMT_SETTING_CONNECTABLE 0x00000002
@@ -75,28 +94,32 @@ struct mgmt_rp_read_index_list {
75#define MGMT_SETTING_LE 0x00000200 94#define MGMT_SETTING_LE 0x00000200
76 95
77#define MGMT_OP_READ_INFO 0x0004 96#define MGMT_OP_READ_INFO 0x0004
97#define MGMT_READ_INFO_SIZE 0
78struct mgmt_rp_read_info { 98struct mgmt_rp_read_info {
79 bdaddr_t bdaddr; 99 bdaddr_t bdaddr;
80 __u8 version; 100 __u8 version;
81 __le16 manufacturer; 101 __le16 manufacturer;
82 __le32 supported_settings; 102 __le32 supported_settings;
83 __le32 current_settings; 103 __le32 current_settings;
84 __u8 dev_class[3]; 104 __u8 dev_class[3];
85 __u8 name[MGMT_MAX_NAME_LENGTH]; 105 __u8 name[MGMT_MAX_NAME_LENGTH];
86 __u8 short_name[MGMT_MAX_SHORT_NAME_LENGTH]; 106 __u8 short_name[MGMT_MAX_SHORT_NAME_LENGTH];
87} __packed; 107} __packed;
88 108
89struct mgmt_mode { 109struct mgmt_mode {
90 __u8 val; 110 __u8 val;
91} __packed; 111} __packed;
92 112
113#define MGMT_SETTING_SIZE 1
114
93#define MGMT_OP_SET_POWERED 0x0005 115#define MGMT_OP_SET_POWERED 0x0005
94 116
95#define MGMT_OP_SET_DISCOVERABLE 0x0006 117#define MGMT_OP_SET_DISCOVERABLE 0x0006
96struct mgmt_cp_set_discoverable { 118struct mgmt_cp_set_discoverable {
97 __u8 val; 119 __u8 val;
98 __u16 timeout; 120 __le16 timeout;
99} __packed; 121} __packed;
122#define MGMT_SET_DISCOVERABLE_SIZE 3
100 123
101#define MGMT_OP_SET_CONNECTABLE 0x0007 124#define MGMT_OP_SET_CONNECTABLE 0x0007
102 125
@@ -111,73 +134,76 @@ struct mgmt_cp_set_discoverable {
111#define MGMT_OP_SET_HS 0x000C 134#define MGMT_OP_SET_HS 0x000C
112 135
113#define MGMT_OP_SET_LE 0x000D 136#define MGMT_OP_SET_LE 0x000D
114
115#define MGMT_OP_SET_DEV_CLASS 0x000E 137#define MGMT_OP_SET_DEV_CLASS 0x000E
116struct mgmt_cp_set_dev_class { 138struct mgmt_cp_set_dev_class {
117 __u8 major; 139 __u8 major;
118 __u8 minor; 140 __u8 minor;
119} __packed; 141} __packed;
142#define MGMT_SET_DEV_CLASS_SIZE 2
120 143
121#define MGMT_OP_SET_LOCAL_NAME 0x000F 144#define MGMT_OP_SET_LOCAL_NAME 0x000F
122struct mgmt_cp_set_local_name { 145struct mgmt_cp_set_local_name {
123 __u8 name[MGMT_MAX_NAME_LENGTH]; 146 __u8 name[MGMT_MAX_NAME_LENGTH];
147 __u8 short_name[MGMT_MAX_SHORT_NAME_LENGTH];
124} __packed; 148} __packed;
149#define MGMT_SET_LOCAL_NAME_SIZE 260
125 150
126#define MGMT_OP_ADD_UUID 0x0010 151#define MGMT_OP_ADD_UUID 0x0010
127struct mgmt_cp_add_uuid { 152struct mgmt_cp_add_uuid {
128 __u8 uuid[16]; 153 __u8 uuid[16];
129 __u8 svc_hint; 154 __u8 svc_hint;
130} __packed; 155} __packed;
156#define MGMT_ADD_UUID_SIZE 17
131 157
132#define MGMT_OP_REMOVE_UUID 0x0011 158#define MGMT_OP_REMOVE_UUID 0x0011
133struct mgmt_cp_remove_uuid { 159struct mgmt_cp_remove_uuid {
134 __u8 uuid[16]; 160 __u8 uuid[16];
135} __packed; 161} __packed;
162#define MGMT_REMOVE_UUID_SIZE 16
136 163
137struct mgmt_link_key_info { 164struct mgmt_link_key_info {
138 bdaddr_t bdaddr; 165 struct mgmt_addr_info addr;
139 u8 type; 166 __u8 type;
140 u8 val[16]; 167 __u8 val[16];
141 u8 pin_len; 168 __u8 pin_len;
142} __packed; 169} __packed;
143 170
144#define MGMT_OP_LOAD_LINK_KEYS 0x0012 171#define MGMT_OP_LOAD_LINK_KEYS 0x0012
145struct mgmt_cp_load_link_keys { 172struct mgmt_cp_load_link_keys {
146 __u8 debug_keys; 173 __u8 debug_keys;
147 __le16 key_count; 174 __le16 key_count;
148 struct mgmt_link_key_info keys[0]; 175 struct mgmt_link_key_info keys[0];
149} __packed; 176} __packed;
177#define MGMT_LOAD_LINK_KEYS_SIZE 3
150 178
151#define MGMT_OP_REMOVE_KEYS 0x0013 179struct mgmt_ltk_info {
152struct mgmt_cp_remove_keys { 180 struct mgmt_addr_info addr;
153 bdaddr_t bdaddr; 181 __u8 authenticated;
154 __u8 disconnect; 182 __u8 master;
183 __u8 enc_size;
184 __le16 ediv;
185 __u8 rand[8];
186 __u8 val[16];
155} __packed; 187} __packed;
156struct mgmt_rp_remove_keys { 188
157 bdaddr_t bdaddr; 189#define MGMT_OP_LOAD_LONG_TERM_KEYS 0x0013
158 __u8 status; 190struct mgmt_cp_load_long_term_keys {
159}; 191 __le16 key_count;
192 struct mgmt_ltk_info keys[0];
193} __packed;
194#define MGMT_LOAD_LONG_TERM_KEYS_SIZE 2
160 195
161#define MGMT_OP_DISCONNECT 0x0014 196#define MGMT_OP_DISCONNECT 0x0014
162struct mgmt_cp_disconnect { 197struct mgmt_cp_disconnect {
163 bdaddr_t bdaddr; 198 struct mgmt_addr_info addr;
164} __packed; 199} __packed;
200#define MGMT_DISCONNECT_SIZE MGMT_ADDR_INFO_SIZE
165struct mgmt_rp_disconnect { 201struct mgmt_rp_disconnect {
166 bdaddr_t bdaddr; 202 struct mgmt_addr_info addr;
167 __u8 status;
168} __packed;
169
170#define MGMT_ADDR_BREDR 0x00
171#define MGMT_ADDR_LE_PUBLIC 0x01
172#define MGMT_ADDR_LE_RANDOM 0x02
173#define MGMT_ADDR_INVALID 0xff
174
175struct mgmt_addr_info {
176 bdaddr_t bdaddr;
177 __u8 type;
178} __packed; 203} __packed;
179 204
180#define MGMT_OP_GET_CONNECTIONS 0x0015 205#define MGMT_OP_GET_CONNECTIONS 0x0015
206#define MGMT_GET_CONNECTIONS_SIZE 0
181struct mgmt_rp_get_connections { 207struct mgmt_rp_get_connections {
182 __le16 conn_count; 208 __le16 conn_count;
183 struct mgmt_addr_info addr[0]; 209 struct mgmt_addr_info addr[0];
@@ -185,124 +211,152 @@ struct mgmt_rp_get_connections {
185 211
186#define MGMT_OP_PIN_CODE_REPLY 0x0016 212#define MGMT_OP_PIN_CODE_REPLY 0x0016
187struct mgmt_cp_pin_code_reply { 213struct mgmt_cp_pin_code_reply {
188 bdaddr_t bdaddr; 214 struct mgmt_addr_info addr;
189 __u8 pin_len; 215 __u8 pin_len;
190 __u8 pin_code[16]; 216 __u8 pin_code[16];
191} __packed; 217} __packed;
218#define MGMT_PIN_CODE_REPLY_SIZE (MGMT_ADDR_INFO_SIZE + 17)
192struct mgmt_rp_pin_code_reply { 219struct mgmt_rp_pin_code_reply {
193 bdaddr_t bdaddr; 220 struct mgmt_addr_info addr;
194 uint8_t status;
195} __packed; 221} __packed;
196 222
197#define MGMT_OP_PIN_CODE_NEG_REPLY 0x0017 223#define MGMT_OP_PIN_CODE_NEG_REPLY 0x0017
198struct mgmt_cp_pin_code_neg_reply { 224struct mgmt_cp_pin_code_neg_reply {
199 bdaddr_t bdaddr; 225 struct mgmt_addr_info addr;
200} __packed; 226} __packed;
227#define MGMT_PIN_CODE_NEG_REPLY_SIZE MGMT_ADDR_INFO_SIZE
201 228
202#define MGMT_OP_SET_IO_CAPABILITY 0x0018 229#define MGMT_OP_SET_IO_CAPABILITY 0x0018
203struct mgmt_cp_set_io_capability { 230struct mgmt_cp_set_io_capability {
204 __u8 io_capability; 231 __u8 io_capability;
205} __packed; 232} __packed;
233#define MGMT_SET_IO_CAPABILITY_SIZE 1
206 234
207#define MGMT_OP_PAIR_DEVICE 0x0019 235#define MGMT_OP_PAIR_DEVICE 0x0019
208struct mgmt_cp_pair_device { 236struct mgmt_cp_pair_device {
209 struct mgmt_addr_info addr; 237 struct mgmt_addr_info addr;
210 __u8 io_cap; 238 __u8 io_cap;
211} __packed; 239} __packed;
240#define MGMT_PAIR_DEVICE_SIZE (MGMT_ADDR_INFO_SIZE + 1)
212struct mgmt_rp_pair_device { 241struct mgmt_rp_pair_device {
213 struct mgmt_addr_info addr; 242 struct mgmt_addr_info addr;
214 __u8 status;
215} __packed; 243} __packed;
216 244
217#define MGMT_OP_USER_CONFIRM_REPLY 0x001A 245#define MGMT_OP_CANCEL_PAIR_DEVICE 0x001A
246#define MGMT_CANCEL_PAIR_DEVICE_SIZE MGMT_ADDR_INFO_SIZE
247
248#define MGMT_OP_UNPAIR_DEVICE 0x001B
249struct mgmt_cp_unpair_device {
250 struct mgmt_addr_info addr;
251 __u8 disconnect;
252} __packed;
253#define MGMT_UNPAIR_DEVICE_SIZE (MGMT_ADDR_INFO_SIZE + 1)
254struct mgmt_rp_unpair_device {
255 struct mgmt_addr_info addr;
256};
257
258#define MGMT_OP_USER_CONFIRM_REPLY 0x001C
218struct mgmt_cp_user_confirm_reply { 259struct mgmt_cp_user_confirm_reply {
219 bdaddr_t bdaddr; 260 struct mgmt_addr_info addr;
220} __packed; 261} __packed;
262#define MGMT_USER_CONFIRM_REPLY_SIZE MGMT_ADDR_INFO_SIZE
221struct mgmt_rp_user_confirm_reply { 263struct mgmt_rp_user_confirm_reply {
222 bdaddr_t bdaddr; 264 struct mgmt_addr_info addr;
223 __u8 status;
224} __packed; 265} __packed;
225 266
226#define MGMT_OP_USER_CONFIRM_NEG_REPLY 0x001B 267#define MGMT_OP_USER_CONFIRM_NEG_REPLY 0x001D
227struct mgmt_cp_user_confirm_neg_reply { 268struct mgmt_cp_user_confirm_neg_reply {
228 bdaddr_t bdaddr; 269 struct mgmt_addr_info addr;
229} __packed; 270} __packed;
271#define MGMT_USER_CONFIRM_NEG_REPLY_SIZE MGMT_ADDR_INFO_SIZE
230 272
231#define MGMT_OP_USER_PASSKEY_REPLY 0x001C 273#define MGMT_OP_USER_PASSKEY_REPLY 0x001E
232struct mgmt_cp_user_passkey_reply { 274struct mgmt_cp_user_passkey_reply {
233 bdaddr_t bdaddr; 275 struct mgmt_addr_info addr;
234 __le32 passkey; 276 __le32 passkey;
235} __packed; 277} __packed;
278#define MGMT_USER_PASSKEY_REPLY_SIZE (MGMT_ADDR_INFO_SIZE + 4)
236struct mgmt_rp_user_passkey_reply { 279struct mgmt_rp_user_passkey_reply {
237 bdaddr_t bdaddr; 280 struct mgmt_addr_info addr;
238 __u8 status;
239} __packed; 281} __packed;
240 282
241#define MGMT_OP_USER_PASSKEY_NEG_REPLY 0x001D 283#define MGMT_OP_USER_PASSKEY_NEG_REPLY 0x001F
242struct mgmt_cp_user_passkey_neg_reply { 284struct mgmt_cp_user_passkey_neg_reply {
243 bdaddr_t bdaddr; 285 struct mgmt_addr_info addr;
244} __packed; 286} __packed;
287#define MGMT_USER_PASSKEY_NEG_REPLY_SIZE MGMT_ADDR_INFO_SIZE
245 288
246#define MGMT_OP_READ_LOCAL_OOB_DATA 0x001E 289#define MGMT_OP_READ_LOCAL_OOB_DATA 0x0020
290#define MGMT_READ_LOCAL_OOB_DATA_SIZE 0
247struct mgmt_rp_read_local_oob_data { 291struct mgmt_rp_read_local_oob_data {
248 __u8 hash[16]; 292 __u8 hash[16];
249 __u8 randomizer[16]; 293 __u8 randomizer[16];
250} __packed; 294} __packed;
251 295
252#define MGMT_OP_ADD_REMOTE_OOB_DATA 0x001F 296#define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0021
253struct mgmt_cp_add_remote_oob_data { 297struct mgmt_cp_add_remote_oob_data {
254 bdaddr_t bdaddr; 298 struct mgmt_addr_info addr;
255 __u8 hash[16]; 299 __u8 hash[16];
256 __u8 randomizer[16]; 300 __u8 randomizer[16];
257} __packed; 301} __packed;
302#define MGMT_ADD_REMOTE_OOB_DATA_SIZE (MGMT_ADDR_INFO_SIZE + 32)
258 303
259#define MGMT_OP_REMOVE_REMOTE_OOB_DATA 0x0020 304#define MGMT_OP_REMOVE_REMOTE_OOB_DATA 0x0022
260struct mgmt_cp_remove_remote_oob_data { 305struct mgmt_cp_remove_remote_oob_data {
261 bdaddr_t bdaddr; 306 struct mgmt_addr_info addr;
262} __packed; 307} __packed;
308#define MGMT_REMOVE_REMOTE_OOB_DATA_SIZE MGMT_ADDR_INFO_SIZE
263 309
264#define MGMT_OP_START_DISCOVERY 0x0021 310#define MGMT_OP_START_DISCOVERY 0x0023
265struct mgmt_cp_start_discovery { 311struct mgmt_cp_start_discovery {
266 __u8 type; 312 __u8 type;
267} __packed; 313} __packed;
314#define MGMT_START_DISCOVERY_SIZE 1
268 315
269#define MGMT_OP_STOP_DISCOVERY 0x0022 316#define MGMT_OP_STOP_DISCOVERY 0x0024
317struct mgmt_cp_stop_discovery {
318 __u8 type;
319} __packed;
320#define MGMT_STOP_DISCOVERY_SIZE 1
270 321
271#define MGMT_OP_CONFIRM_NAME 0x0023 322#define MGMT_OP_CONFIRM_NAME 0x0025
272struct mgmt_cp_confirm_name { 323struct mgmt_cp_confirm_name {
273 bdaddr_t bdaddr; 324 struct mgmt_addr_info addr;
274 __u8 name_known; 325 __u8 name_known;
275} __packed; 326} __packed;
327#define MGMT_CONFIRM_NAME_SIZE (MGMT_ADDR_INFO_SIZE + 1)
276struct mgmt_rp_confirm_name { 328struct mgmt_rp_confirm_name {
277 bdaddr_t bdaddr; 329 struct mgmt_addr_info addr;
278 __u8 status;
279} __packed; 330} __packed;
280 331
281#define MGMT_OP_BLOCK_DEVICE 0x0024 332#define MGMT_OP_BLOCK_DEVICE 0x0026
282struct mgmt_cp_block_device { 333struct mgmt_cp_block_device {
283 bdaddr_t bdaddr; 334 struct mgmt_addr_info addr;
284} __packed; 335} __packed;
336#define MGMT_BLOCK_DEVICE_SIZE MGMT_ADDR_INFO_SIZE
285 337
286#define MGMT_OP_UNBLOCK_DEVICE 0x0025 338#define MGMT_OP_UNBLOCK_DEVICE 0x0027
287struct mgmt_cp_unblock_device { 339struct mgmt_cp_unblock_device {
288 bdaddr_t bdaddr; 340 struct mgmt_addr_info addr;
289} __packed; 341} __packed;
342#define MGMT_UNBLOCK_DEVICE_SIZE MGMT_ADDR_INFO_SIZE
290 343
291#define MGMT_EV_CMD_COMPLETE 0x0001 344#define MGMT_EV_CMD_COMPLETE 0x0001
292struct mgmt_ev_cmd_complete { 345struct mgmt_ev_cmd_complete {
293 __le16 opcode; 346 __le16 opcode;
294 __u8 data[0]; 347 __u8 status;
348 __u8 data[0];
295} __packed; 349} __packed;
296 350
297#define MGMT_EV_CMD_STATUS 0x0002 351#define MGMT_EV_CMD_STATUS 0x0002
298struct mgmt_ev_cmd_status { 352struct mgmt_ev_cmd_status {
299 __u8 status; 353 __le16 opcode;
300 __le16 opcode; 354 __u8 status;
301} __packed; 355} __packed;
302 356
303#define MGMT_EV_CONTROLLER_ERROR 0x0003 357#define MGMT_EV_CONTROLLER_ERROR 0x0003
304struct mgmt_ev_controller_error { 358struct mgmt_ev_controller_error {
305 __u8 error_code; 359 __u8 error_code;
306} __packed; 360} __packed;
307 361
308#define MGMT_EV_INDEX_ADDED 0x0004 362#define MGMT_EV_INDEX_ADDED 0x0004
@@ -313,78 +367,96 @@ struct mgmt_ev_controller_error {
313 367
314#define MGMT_EV_CLASS_OF_DEV_CHANGED 0x0007 368#define MGMT_EV_CLASS_OF_DEV_CHANGED 0x0007
315struct mgmt_ev_class_of_dev_changed { 369struct mgmt_ev_class_of_dev_changed {
316 __u8 dev_class[3]; 370 __u8 dev_class[3];
317}; 371};
318 372
319#define MGMT_EV_LOCAL_NAME_CHANGED 0x0008 373#define MGMT_EV_LOCAL_NAME_CHANGED 0x0008
320struct mgmt_ev_local_name_changed { 374struct mgmt_ev_local_name_changed {
321 __u8 name[MGMT_MAX_NAME_LENGTH]; 375 __u8 name[MGMT_MAX_NAME_LENGTH];
322 __u8 short_name[MGMT_MAX_SHORT_NAME_LENGTH]; 376 __u8 short_name[MGMT_MAX_SHORT_NAME_LENGTH];
323} __packed; 377} __packed;
324 378
325#define MGMT_EV_NEW_LINK_KEY 0x0009 379#define MGMT_EV_NEW_LINK_KEY 0x0009
326struct mgmt_ev_new_link_key { 380struct mgmt_ev_new_link_key {
327 __u8 store_hint; 381 __u8 store_hint;
328 struct mgmt_link_key_info key; 382 struct mgmt_link_key_info key;
329} __packed; 383} __packed;
330 384
331#define MGMT_EV_CONNECTED 0x000A 385#define MGMT_EV_NEW_LONG_TERM_KEY 0x000A
386struct mgmt_ev_new_long_term_key {
387 __u8 store_hint;
388 struct mgmt_ltk_info key;
389} __packed;
332 390
333#define MGMT_EV_DISCONNECTED 0x000B 391#define MGMT_EV_DEVICE_CONNECTED 0x000B
392struct mgmt_ev_device_connected {
393 struct mgmt_addr_info addr;
394 __le32 flags;
395 __le16 eir_len;
396 __u8 eir[0];
397} __packed;
398
399#define MGMT_EV_DEVICE_DISCONNECTED 0x000C
334 400
335#define MGMT_EV_CONNECT_FAILED 0x000C 401#define MGMT_EV_CONNECT_FAILED 0x000D
336struct mgmt_ev_connect_failed { 402struct mgmt_ev_connect_failed {
337 struct mgmt_addr_info addr; 403 struct mgmt_addr_info addr;
338 __u8 status; 404 __u8 status;
339} __packed; 405} __packed;
340 406
341#define MGMT_EV_PIN_CODE_REQUEST 0x000D 407#define MGMT_EV_PIN_CODE_REQUEST 0x000E
342struct mgmt_ev_pin_code_request { 408struct mgmt_ev_pin_code_request {
343 bdaddr_t bdaddr; 409 struct mgmt_addr_info addr;
344 __u8 secure; 410 __u8 secure;
345} __packed; 411} __packed;
346 412
347#define MGMT_EV_USER_CONFIRM_REQUEST 0x000E 413#define MGMT_EV_USER_CONFIRM_REQUEST 0x000F
348struct mgmt_ev_user_confirm_request { 414struct mgmt_ev_user_confirm_request {
349 bdaddr_t bdaddr; 415 struct mgmt_addr_info addr;
350 __u8 confirm_hint; 416 __u8 confirm_hint;
351 __le32 value; 417 __le32 value;
352} __packed; 418} __packed;
353 419
354#define MGMT_EV_USER_PASSKEY_REQUEST 0x000F 420#define MGMT_EV_USER_PASSKEY_REQUEST 0x0010
355struct mgmt_ev_user_passkey_request { 421struct mgmt_ev_user_passkey_request {
356 bdaddr_t bdaddr; 422 struct mgmt_addr_info addr;
357} __packed; 423} __packed;
358 424
359#define MGMT_EV_AUTH_FAILED 0x0010 425#define MGMT_EV_AUTH_FAILED 0x0011
360struct mgmt_ev_auth_failed { 426struct mgmt_ev_auth_failed {
361 bdaddr_t bdaddr; 427 struct mgmt_addr_info addr;
362 __u8 status; 428 __u8 status;
363} __packed; 429} __packed;
364 430
365#define MGMT_EV_DEVICE_FOUND 0x0011 431#define MGMT_DEV_FOUND_CONFIRM_NAME 0x01
432#define MGMT_DEV_FOUND_LEGACY_PAIRING 0x02
433
434#define MGMT_EV_DEVICE_FOUND 0x0012
366struct mgmt_ev_device_found { 435struct mgmt_ev_device_found {
367 struct mgmt_addr_info addr; 436 struct mgmt_addr_info addr;
368 __u8 dev_class[3]; 437 __s8 rssi;
369 __s8 rssi; 438 __u8 flags[4];
370 __u8 confirm_name; 439 __le16 eir_len;
371 __u8 eir[HCI_MAX_EIR_LENGTH]; 440 __u8 eir[0];
372} __packed;
373
374#define MGMT_EV_REMOTE_NAME 0x0012
375struct mgmt_ev_remote_name {
376 bdaddr_t bdaddr;
377 __u8 name[MGMT_MAX_NAME_LENGTH];
378} __packed; 441} __packed;
379 442
380#define MGMT_EV_DISCOVERING 0x0013 443#define MGMT_EV_DISCOVERING 0x0013
444struct mgmt_ev_discovering {
445 __u8 type;
446 __u8 discovering;
447} __packed;
381 448
382#define MGMT_EV_DEVICE_BLOCKED 0x0014 449#define MGMT_EV_DEVICE_BLOCKED 0x0014
383struct mgmt_ev_device_blocked { 450struct mgmt_ev_device_blocked {
384 bdaddr_t bdaddr; 451 struct mgmt_addr_info addr;
385} __packed; 452} __packed;
386 453
387#define MGMT_EV_DEVICE_UNBLOCKED 0x0015 454#define MGMT_EV_DEVICE_UNBLOCKED 0x0015
388struct mgmt_ev_device_unblocked { 455struct mgmt_ev_device_unblocked {
389 bdaddr_t bdaddr; 456 struct mgmt_addr_info addr;
457} __packed;
458
459#define MGMT_EV_DEVICE_UNPAIRED 0x0016
460struct mgmt_ev_device_unpaired {
461 struct mgmt_addr_info addr;
390} __packed; 462} __packed;
diff --git a/include/net/bluetooth/smp.h b/include/net/bluetooth/smp.h
index aeaf5fa2b9f1..7b3acdd29134 100644
--- a/include/net/bluetooth/smp.h
+++ b/include/net/bluetooth/smp.h
@@ -127,7 +127,7 @@ struct smp_chan {
127 u8 rrnd[16]; /* SMP Pairing Random (remote) */ 127 u8 rrnd[16]; /* SMP Pairing Random (remote) */
128 u8 pcnf[16]; /* SMP Pairing Confirm */ 128 u8 pcnf[16]; /* SMP Pairing Confirm */
129 u8 tk[16]; /* SMP Temporary Key */ 129 u8 tk[16]; /* SMP Temporary Key */
130 u8 smp_key_size; 130 u8 enc_key_size;
131 unsigned long smp_flags; 131 unsigned long smp_flags;
132 struct crypto_blkcipher *tfm; 132 struct crypto_blkcipher *tfm;
133 struct work_struct confirm; 133 struct work_struct confirm;