aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2013-04-26 08:36:00 -0400
committerJohn W. Linville <linville@tuxdriver.com>2013-04-26 08:36:00 -0400
commit375e875c696ae65e7ce748721ec2dc93ca0a16df (patch)
tree31a1e54475c3c9da63326efd7f63871004a1a249
parentb006ed545cbadf1ebd4683719554742d20dbcede (diff)
parent69676b1c2af451bfe5cd36ff4973a484b5d5a86c (diff)
Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next
-rw-r--r--drivers/bluetooth/btmrvl_debugfs.c266
-rw-r--r--drivers/bluetooth/btmrvl_sdio.c41
-rw-r--r--drivers/bluetooth/btusb.c377
-rw-r--r--include/net/bluetooth/hci_core.h14
-rw-r--r--net/bluetooth/hci_core.c29
-rw-r--r--net/bluetooth/l2cap_core.c7
-rw-r--r--net/bluetooth/mgmt.c8
7 files changed, 462 insertions, 280 deletions
diff --git a/drivers/bluetooth/btmrvl_debugfs.c b/drivers/bluetooth/btmrvl_debugfs.c
index 428dbb7574bd..db2c3c305df8 100644
--- a/drivers/bluetooth/btmrvl_debugfs.c
+++ b/drivers/bluetooth/btmrvl_debugfs.c
@@ -29,20 +29,6 @@
29struct btmrvl_debugfs_data { 29struct btmrvl_debugfs_data {
30 struct dentry *config_dir; 30 struct dentry *config_dir;
31 struct dentry *status_dir; 31 struct dentry *status_dir;
32
33 /* config */
34 struct dentry *psmode;
35 struct dentry *pscmd;
36 struct dentry *hsmode;
37 struct dentry *hscmd;
38 struct dentry *gpiogap;
39 struct dentry *hscfgcmd;
40
41 /* status */
42 struct dentry *curpsmode;
43 struct dentry *hsstate;
44 struct dentry *psstate;
45 struct dentry *txdnldready;
46}; 32};
47 33
48static ssize_t btmrvl_hscfgcmd_write(struct file *file, 34static ssize_t btmrvl_hscfgcmd_write(struct file *file,
@@ -91,47 +77,6 @@ static const struct file_operations btmrvl_hscfgcmd_fops = {
91 .llseek = default_llseek, 77 .llseek = default_llseek,
92}; 78};
93 79
94static ssize_t btmrvl_psmode_write(struct file *file, const char __user *ubuf,
95 size_t count, loff_t *ppos)
96{
97 struct btmrvl_private *priv = file->private_data;
98 char buf[16];
99 long result, ret;
100
101 memset(buf, 0, sizeof(buf));
102
103 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
104 return -EFAULT;
105
106 ret = strict_strtol(buf, 10, &result);
107 if (ret)
108 return ret;
109
110 priv->btmrvl_dev.psmode = result;
111
112 return count;
113}
114
115static ssize_t btmrvl_psmode_read(struct file *file, char __user *userbuf,
116 size_t count, loff_t *ppos)
117{
118 struct btmrvl_private *priv = file->private_data;
119 char buf[16];
120 int ret;
121
122 ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
123 priv->btmrvl_dev.psmode);
124
125 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
126}
127
128static const struct file_operations btmrvl_psmode_fops = {
129 .read = btmrvl_psmode_read,
130 .write = btmrvl_psmode_write,
131 .open = simple_open,
132 .llseek = default_llseek,
133};
134
135static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf, 80static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
136 size_t count, loff_t *ppos) 81 size_t count, loff_t *ppos)
137{ 82{
@@ -178,47 +123,6 @@ static const struct file_operations btmrvl_pscmd_fops = {
178 .llseek = default_llseek, 123 .llseek = default_llseek,
179}; 124};
180 125
181static ssize_t btmrvl_gpiogap_write(struct file *file, const char __user *ubuf,
182 size_t count, loff_t *ppos)
183{
184 struct btmrvl_private *priv = file->private_data;
185 char buf[16];
186 long result, ret;
187
188 memset(buf, 0, sizeof(buf));
189
190 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
191 return -EFAULT;
192
193 ret = strict_strtol(buf, 16, &result);
194 if (ret)
195 return ret;
196
197 priv->btmrvl_dev.gpio_gap = result;
198
199 return count;
200}
201
202static ssize_t btmrvl_gpiogap_read(struct file *file, char __user *userbuf,
203 size_t count, loff_t *ppos)
204{
205 struct btmrvl_private *priv = file->private_data;
206 char buf[16];
207 int ret;
208
209 ret = snprintf(buf, sizeof(buf) - 1, "0x%x\n",
210 priv->btmrvl_dev.gpio_gap);
211
212 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
213}
214
215static const struct file_operations btmrvl_gpiogap_fops = {
216 .read = btmrvl_gpiogap_read,
217 .write = btmrvl_gpiogap_write,
218 .open = simple_open,
219 .llseek = default_llseek,
220};
221
222static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf, 126static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
223 size_t count, loff_t *ppos) 127 size_t count, loff_t *ppos)
224{ 128{
@@ -263,119 +167,6 @@ static const struct file_operations btmrvl_hscmd_fops = {
263 .llseek = default_llseek, 167 .llseek = default_llseek,
264}; 168};
265 169
266static ssize_t btmrvl_hsmode_write(struct file *file, const char __user *ubuf,
267 size_t count, loff_t *ppos)
268{
269 struct btmrvl_private *priv = file->private_data;
270 char buf[16];
271 long result, ret;
272
273 memset(buf, 0, sizeof(buf));
274
275 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
276 return -EFAULT;
277
278 ret = strict_strtol(buf, 10, &result);
279 if (ret)
280 return ret;
281
282 priv->btmrvl_dev.hsmode = result;
283
284 return count;
285}
286
287static ssize_t btmrvl_hsmode_read(struct file *file, char __user * userbuf,
288 size_t count, loff_t *ppos)
289{
290 struct btmrvl_private *priv = file->private_data;
291 char buf[16];
292 int ret;
293
294 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hsmode);
295
296 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
297}
298
299static const struct file_operations btmrvl_hsmode_fops = {
300 .read = btmrvl_hsmode_read,
301 .write = btmrvl_hsmode_write,
302 .open = simple_open,
303 .llseek = default_llseek,
304};
305
306static ssize_t btmrvl_curpsmode_read(struct file *file, char __user *userbuf,
307 size_t count, loff_t *ppos)
308{
309 struct btmrvl_private *priv = file->private_data;
310 char buf[16];
311 int ret;
312
313 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->psmode);
314
315 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
316}
317
318static const struct file_operations btmrvl_curpsmode_fops = {
319 .read = btmrvl_curpsmode_read,
320 .open = simple_open,
321 .llseek = default_llseek,
322};
323
324static ssize_t btmrvl_psstate_read(struct file *file, char __user * userbuf,
325 size_t count, loff_t *ppos)
326{
327 struct btmrvl_private *priv = file->private_data;
328 char buf[16];
329 int ret;
330
331 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->ps_state);
332
333 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
334}
335
336static const struct file_operations btmrvl_psstate_fops = {
337 .read = btmrvl_psstate_read,
338 .open = simple_open,
339 .llseek = default_llseek,
340};
341
342static ssize_t btmrvl_hsstate_read(struct file *file, char __user *userbuf,
343 size_t count, loff_t *ppos)
344{
345 struct btmrvl_private *priv = file->private_data;
346 char buf[16];
347 int ret;
348
349 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->hs_state);
350
351 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
352}
353
354static const struct file_operations btmrvl_hsstate_fops = {
355 .read = btmrvl_hsstate_read,
356 .open = simple_open,
357 .llseek = default_llseek,
358};
359
360static ssize_t btmrvl_txdnldready_read(struct file *file, char __user *userbuf,
361 size_t count, loff_t *ppos)
362{
363 struct btmrvl_private *priv = file->private_data;
364 char buf[16];
365 int ret;
366
367 ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
368 priv->btmrvl_dev.tx_dnld_rdy);
369
370 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
371}
372
373static const struct file_operations btmrvl_txdnldready_fops = {
374 .read = btmrvl_txdnldready_read,
375 .open = simple_open,
376 .llseek = default_llseek,
377};
378
379void btmrvl_debugfs_init(struct hci_dev *hdev) 170void btmrvl_debugfs_init(struct hci_dev *hdev)
380{ 171{
381 struct btmrvl_private *priv = hci_get_drvdata(hdev); 172 struct btmrvl_private *priv = hci_get_drvdata(hdev);
@@ -394,30 +185,28 @@ void btmrvl_debugfs_init(struct hci_dev *hdev)
394 185
395 dbg->config_dir = debugfs_create_dir("config", hdev->debugfs); 186 dbg->config_dir = debugfs_create_dir("config", hdev->debugfs);
396 187
397 dbg->psmode = debugfs_create_file("psmode", 0644, dbg->config_dir, 188 debugfs_create_u8("psmode", 0644, dbg->config_dir,
398 priv, &btmrvl_psmode_fops); 189 &priv->btmrvl_dev.psmode);
399 dbg->pscmd = debugfs_create_file("pscmd", 0644, dbg->config_dir, 190 debugfs_create_file("pscmd", 0644, dbg->config_dir,
400 priv, &btmrvl_pscmd_fops); 191 priv, &btmrvl_pscmd_fops);
401 dbg->gpiogap = debugfs_create_file("gpiogap", 0644, dbg->config_dir, 192 debugfs_create_x16("gpiogap", 0644, dbg->config_dir,
402 priv, &btmrvl_gpiogap_fops); 193 &priv->btmrvl_dev.gpio_gap);
403 dbg->hsmode = debugfs_create_file("hsmode", 0644, dbg->config_dir, 194 debugfs_create_u8("hsmode", 0644, dbg->config_dir,
404 priv, &btmrvl_hsmode_fops); 195 &priv->btmrvl_dev.hsmode);
405 dbg->hscmd = debugfs_create_file("hscmd", 0644, dbg->config_dir, 196 debugfs_create_file("hscmd", 0644, dbg->config_dir,
406 priv, &btmrvl_hscmd_fops); 197 priv, &btmrvl_hscmd_fops);
407 dbg->hscfgcmd = debugfs_create_file("hscfgcmd", 0644, dbg->config_dir, 198 debugfs_create_file("hscfgcmd", 0644, dbg->config_dir,
408 priv, &btmrvl_hscfgcmd_fops); 199 priv, &btmrvl_hscfgcmd_fops);
409 200
410 dbg->status_dir = debugfs_create_dir("status", hdev->debugfs); 201 dbg->status_dir = debugfs_create_dir("status", hdev->debugfs);
411 dbg->curpsmode = debugfs_create_file("curpsmode", 0444, 202 debugfs_create_u8("curpsmode", 0444, dbg->status_dir,
412 dbg->status_dir, priv, 203 &priv->adapter->psmode);
413 &btmrvl_curpsmode_fops); 204 debugfs_create_u8("psstate", 0444, dbg->status_dir,
414 dbg->psstate = debugfs_create_file("psstate", 0444, dbg->status_dir, 205 &priv->adapter->ps_state);
415 priv, &btmrvl_psstate_fops); 206 debugfs_create_u8("hsstate", 0444, dbg->status_dir,
416 dbg->hsstate = debugfs_create_file("hsstate", 0444, dbg->status_dir, 207 &priv->adapter->hs_state);
417 priv, &btmrvl_hsstate_fops); 208 debugfs_create_u8("txdnldready", 0444, dbg->status_dir,
418 dbg->txdnldready = debugfs_create_file("txdnldready", 0444, 209 &priv->btmrvl_dev.tx_dnld_rdy);
419 dbg->status_dir, priv,
420 &btmrvl_txdnldready_fops);
421} 210}
422 211
423void btmrvl_debugfs_remove(struct hci_dev *hdev) 212void btmrvl_debugfs_remove(struct hci_dev *hdev)
@@ -428,19 +217,8 @@ void btmrvl_debugfs_remove(struct hci_dev *hdev)
428 if (!dbg) 217 if (!dbg)
429 return; 218 return;
430 219
431 debugfs_remove(dbg->psmode); 220 debugfs_remove_recursive(dbg->config_dir);
432 debugfs_remove(dbg->pscmd); 221 debugfs_remove_recursive(dbg->status_dir);
433 debugfs_remove(dbg->gpiogap);
434 debugfs_remove(dbg->hsmode);
435 debugfs_remove(dbg->hscmd);
436 debugfs_remove(dbg->hscfgcmd);
437 debugfs_remove(dbg->config_dir);
438
439 debugfs_remove(dbg->curpsmode);
440 debugfs_remove(dbg->psstate);
441 debugfs_remove(dbg->hsstate);
442 debugfs_remove(dbg->txdnldready);
443 debugfs_remove(dbg->status_dir);
444 222
445 kfree(dbg); 223 kfree(dbg);
446} 224}
diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index 1cb51839912d..c63488c54f4a 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -228,24 +228,24 @@ failed:
228static int btmrvl_sdio_verify_fw_download(struct btmrvl_sdio_card *card, 228static int btmrvl_sdio_verify_fw_download(struct btmrvl_sdio_card *card,
229 int pollnum) 229 int pollnum)
230{ 230{
231 int ret = -ETIMEDOUT;
232 u16 firmwarestat; 231 u16 firmwarestat;
233 unsigned int tries; 232 int tries, ret;
234 233
235 /* Wait for firmware to become ready */ 234 /* Wait for firmware to become ready */
236 for (tries = 0; tries < pollnum; tries++) { 235 for (tries = 0; tries < pollnum; tries++) {
237 if (btmrvl_sdio_read_fw_status(card, &firmwarestat) < 0) 236 sdio_claim_host(card->func);
237 ret = btmrvl_sdio_read_fw_status(card, &firmwarestat);
238 sdio_release_host(card->func);
239 if (ret < 0)
238 continue; 240 continue;
239 241
240 if (firmwarestat == FIRMWARE_READY) { 242 if (firmwarestat == FIRMWARE_READY)
241 ret = 0; 243 return 0;
242 break; 244
243 } else { 245 msleep(10);
244 msleep(10);
245 }
246 } 246 }
247 247
248 return ret; 248 return -ETIMEDOUT;
249} 249}
250 250
251static int btmrvl_sdio_download_helper(struct btmrvl_sdio_card *card) 251static int btmrvl_sdio_download_helper(struct btmrvl_sdio_card *card)
@@ -874,7 +874,7 @@ exit:
874 874
875static int btmrvl_sdio_download_fw(struct btmrvl_sdio_card *card) 875static int btmrvl_sdio_download_fw(struct btmrvl_sdio_card *card)
876{ 876{
877 int ret = 0; 877 int ret;
878 u8 fws0; 878 u8 fws0;
879 int pollnum = MAX_POLL_TRIES; 879 int pollnum = MAX_POLL_TRIES;
880 880
@@ -882,13 +882,14 @@ static int btmrvl_sdio_download_fw(struct btmrvl_sdio_card *card)
882 BT_ERR("card or function is NULL!"); 882 BT_ERR("card or function is NULL!");
883 return -EINVAL; 883 return -EINVAL;
884 } 884 }
885 sdio_claim_host(card->func);
886 885
887 if (!btmrvl_sdio_verify_fw_download(card, 1)) { 886 if (!btmrvl_sdio_verify_fw_download(card, 1)) {
888 BT_DBG("Firmware already downloaded!"); 887 BT_DBG("Firmware already downloaded!");
889 goto done; 888 return 0;
890 } 889 }
891 890
891 sdio_claim_host(card->func);
892
892 /* Check if other function driver is downloading the firmware */ 893 /* Check if other function driver is downloading the firmware */
893 fws0 = sdio_readb(card->func, card->reg->card_fw_status0, &ret); 894 fws0 = sdio_readb(card->func, card->reg->card_fw_status0, &ret);
894 if (ret) { 895 if (ret) {
@@ -918,15 +919,21 @@ static int btmrvl_sdio_download_fw(struct btmrvl_sdio_card *card)
918 } 919 }
919 } 920 }
920 921
922 sdio_release_host(card->func);
923
924 /*
925 * winner or not, with this test the FW synchronizes when the
926 * module can continue its initialization
927 */
921 if (btmrvl_sdio_verify_fw_download(card, pollnum)) { 928 if (btmrvl_sdio_verify_fw_download(card, pollnum)) {
922 BT_ERR("FW failed to be active in time!"); 929 BT_ERR("FW failed to be active in time!");
923 ret = -ETIMEDOUT; 930 return -ETIMEDOUT;
924 goto done;
925 } 931 }
926 932
933 return 0;
934
927done: 935done:
928 sdio_release_host(card->func); 936 sdio_release_host(card->func);
929
930 return ret; 937 return ret;
931} 938}
932 939
@@ -989,8 +996,6 @@ static int btmrvl_sdio_probe(struct sdio_func *func,
989 goto unreg_dev; 996 goto unreg_dev;
990 } 997 }
991 998
992 msleep(100);
993
994 btmrvl_sdio_enable_host_int(card); 999 btmrvl_sdio_enable_host_int(card);
995 1000
996 priv = btmrvl_add_card(card); 1001 priv = btmrvl_add_card(card);
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 3d684d20b584..7a7e5f8ecadc 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -23,6 +23,7 @@
23 23
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/usb.h> 25#include <linux/usb.h>
26#include <linux/firmware.h>
26 27
27#include <net/bluetooth/bluetooth.h> 28#include <net/bluetooth/bluetooth.h>
28#include <net/bluetooth/hci_core.h> 29#include <net/bluetooth/hci_core.h>
@@ -47,6 +48,7 @@ static struct usb_driver btusb_driver;
47#define BTUSB_BROKEN_ISOC 0x20 48#define BTUSB_BROKEN_ISOC 0x20
48#define BTUSB_WRONG_SCO_MTU 0x40 49#define BTUSB_WRONG_SCO_MTU 0x40
49#define BTUSB_ATH3012 0x80 50#define BTUSB_ATH3012 0x80
51#define BTUSB_INTEL 0x100
50 52
51static struct usb_device_id btusb_table[] = { 53static struct usb_device_id btusb_table[] = {
52 /* Generic Bluetooth USB device */ 54 /* Generic Bluetooth USB device */
@@ -207,6 +209,9 @@ static struct usb_device_id blacklist_table[] = {
207 /* Frontline ComProbe Bluetooth Sniffer */ 209 /* Frontline ComProbe Bluetooth Sniffer */
208 { USB_DEVICE(0x16d3, 0x0002), .driver_info = BTUSB_SNIFFER }, 210 { USB_DEVICE(0x16d3, 0x0002), .driver_info = BTUSB_SNIFFER },
209 211
212 /* Intel Bluetooth device */
213 { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL },
214
210 { } /* Terminating entry */ 215 { } /* Terminating entry */
211}; 216};
212 217
@@ -943,6 +948,375 @@ static int btusb_setup_bcm92035(struct hci_dev *hdev)
943 return 0; 948 return 0;
944} 949}
945 950
951struct intel_version {
952 u8 status;
953 u8 hw_platform;
954 u8 hw_variant;
955 u8 hw_revision;
956 u8 fw_variant;
957 u8 fw_revision;
958 u8 fw_build_num;
959 u8 fw_build_ww;
960 u8 fw_build_yy;
961 u8 fw_patch_num;
962} __packed;
963
964static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev,
965 struct intel_version *ver)
966{
967 const struct firmware *fw;
968 char fwname[64];
969 int ret;
970
971 snprintf(fwname, sizeof(fwname),
972 "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq",
973 ver->hw_platform, ver->hw_variant, ver->hw_revision,
974 ver->fw_variant, ver->fw_revision, ver->fw_build_num,
975 ver->fw_build_ww, ver->fw_build_yy);
976
977 ret = request_firmware(&fw, fwname, &hdev->dev);
978 if (ret < 0) {
979 if (ret == -EINVAL) {
980 BT_ERR("%s Intel firmware file request failed (%d)",
981 hdev->name, ret);
982 return NULL;
983 }
984
985 BT_ERR("%s failed to open Intel firmware file: %s(%d)",
986 hdev->name, fwname, ret);
987
988 /* If the correct firmware patch file is not found, use the
989 * default firmware patch file instead
990 */
991 snprintf(fwname, sizeof(fwname), "intel/ibt-hw-%x.%x.bseq",
992 ver->hw_platform, ver->hw_variant);
993 if (request_firmware(&fw, fwname, &hdev->dev) < 0) {
994 BT_ERR("%s failed to open default Intel fw file: %s",
995 hdev->name, fwname);
996 return NULL;
997 }
998 }
999
1000 BT_INFO("%s: Intel Bluetooth firmware file: %s", hdev->name, fwname);
1001
1002 return fw;
1003}
1004
1005static int btusb_setup_intel_patching(struct hci_dev *hdev,
1006 const struct firmware *fw,
1007 const u8 **fw_ptr, int *disable_patch)
1008{
1009 struct sk_buff *skb;
1010 struct hci_command_hdr *cmd;
1011 const u8 *cmd_param;
1012 struct hci_event_hdr *evt = NULL;
1013 const u8 *evt_param = NULL;
1014 int remain = fw->size - (*fw_ptr - fw->data);
1015
1016 /* The first byte indicates the types of the patch command or event.
1017 * 0x01 means HCI command and 0x02 is HCI event. If the first bytes
1018 * in the current firmware buffer doesn't start with 0x01 or
1019 * the size of remain buffer is smaller than HCI command header,
1020 * the firmware file is corrupted and it should stop the patching
1021 * process.
1022 */
1023 if (remain > HCI_COMMAND_HDR_SIZE && *fw_ptr[0] != 0x01) {
1024 BT_ERR("%s Intel fw corrupted: invalid cmd read", hdev->name);
1025 return -EINVAL;
1026 }
1027 (*fw_ptr)++;
1028 remain--;
1029
1030 cmd = (struct hci_command_hdr *)(*fw_ptr);
1031 *fw_ptr += sizeof(*cmd);
1032 remain -= sizeof(*cmd);
1033
1034 /* Ensure that the remain firmware data is long enough than the length
1035 * of command parameter. If not, the firmware file is corrupted.
1036 */
1037 if (remain < cmd->plen) {
1038 BT_ERR("%s Intel fw corrupted: invalid cmd len", hdev->name);
1039 return -EFAULT;
1040 }
1041
1042 /* If there is a command that loads a patch in the firmware
1043 * file, then enable the patch upon success, otherwise just
1044 * disable the manufacturer mode, for example patch activation
1045 * is not required when the default firmware patch file is used
1046 * because there are no patch data to load.
1047 */
1048 if (*disable_patch && le16_to_cpu(cmd->opcode) == 0xfc8e)
1049 *disable_patch = 0;
1050
1051 cmd_param = *fw_ptr;
1052 *fw_ptr += cmd->plen;
1053 remain -= cmd->plen;
1054
1055 /* This reads the expected events when the above command is sent to the
1056 * device. Some vendor commands expects more than one events, for
1057 * example command status event followed by vendor specific event.
1058 * For this case, it only keeps the last expected event. so the command
1059 * can be sent with __hci_cmd_sync_ev() which returns the sk_buff of
1060 * last expected event.
1061 */
1062 while (remain > HCI_EVENT_HDR_SIZE && *fw_ptr[0] == 0x02) {
1063 (*fw_ptr)++;
1064 remain--;
1065
1066 evt = (struct hci_event_hdr *)(*fw_ptr);
1067 *fw_ptr += sizeof(*evt);
1068 remain -= sizeof(*evt);
1069
1070 if (remain < evt->plen) {
1071 BT_ERR("%s Intel fw corrupted: invalid evt len",
1072 hdev->name);
1073 return -EFAULT;
1074 }
1075
1076 evt_param = *fw_ptr;
1077 *fw_ptr += evt->plen;
1078 remain -= evt->plen;
1079 }
1080
1081 /* Every HCI commands in the firmware file has its correspond event.
1082 * If event is not found or remain is smaller than zero, the firmware
1083 * file is corrupted.
1084 */
1085 if (!evt || !evt_param || remain < 0) {
1086 BT_ERR("%s Intel fw corrupted: invalid evt read", hdev->name);
1087 return -EFAULT;
1088 }
1089
1090 skb = __hci_cmd_sync_ev(hdev, le16_to_cpu(cmd->opcode), cmd->plen,
1091 cmd_param, evt->evt, HCI_INIT_TIMEOUT);
1092 if (IS_ERR(skb)) {
1093 BT_ERR("%s sending Intel patch command (0x%4.4x) failed (%ld)",
1094 hdev->name, cmd->opcode, PTR_ERR(skb));
1095 return -PTR_ERR(skb);
1096 }
1097
1098 /* It ensures that the returned event matches the event data read from
1099 * the firmware file. At fist, it checks the length and then
1100 * the contents of the event.
1101 */
1102 if (skb->len != evt->plen) {
1103 BT_ERR("%s mismatch event length (opcode 0x%4.4x)", hdev->name,
1104 le16_to_cpu(cmd->opcode));
1105 kfree_skb(skb);
1106 return -EFAULT;
1107 }
1108
1109 if (memcmp(skb->data, evt_param, evt->plen)) {
1110 BT_ERR("%s mismatch event parameter (opcode 0x%4.4x)",
1111 hdev->name, le16_to_cpu(cmd->opcode));
1112 kfree_skb(skb);
1113 return -EFAULT;
1114 }
1115 kfree_skb(skb);
1116
1117 return 0;
1118}
1119
1120static int btusb_setup_intel(struct hci_dev *hdev)
1121{
1122 struct sk_buff *skb;
1123 const struct firmware *fw;
1124 const u8 *fw_ptr;
1125 int disable_patch;
1126 struct intel_version *ver;
1127
1128 const u8 mfg_enable[] = { 0x01, 0x00 };
1129 const u8 mfg_disable[] = { 0x00, 0x00 };
1130 const u8 mfg_reset_deactivate[] = { 0x00, 0x01 };
1131 const u8 mfg_reset_activate[] = { 0x00, 0x02 };
1132
1133 BT_DBG("%s", hdev->name);
1134
1135 /* The controller has a bug with the first HCI command sent to it
1136 * returning number of completed commands as zero. This would stall the
1137 * command processing in the Bluetooth core.
1138 *
1139 * As a workaround, send HCI Reset command first which will reset the
1140 * number of completed commands and allow normal command processing
1141 * from now on.
1142 */
1143 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
1144 if (IS_ERR(skb)) {
1145 BT_ERR("%s sending initial HCI reset command failed (%ld)",
1146 hdev->name, PTR_ERR(skb));
1147 return -PTR_ERR(skb);
1148 }
1149 kfree_skb(skb);
1150
1151 /* Read Intel specific controller version first to allow selection of
1152 * which firmware file to load.
1153 *
1154 * The returned information are hardware variant and revision plus
1155 * firmware variant, revision and build number.
1156 */
1157 skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_INIT_TIMEOUT);
1158 if (IS_ERR(skb)) {
1159 BT_ERR("%s reading Intel fw version command failed (%ld)",
1160 hdev->name, PTR_ERR(skb));
1161 return -PTR_ERR(skb);
1162 }
1163
1164 if (skb->len != sizeof(*ver)) {
1165 BT_ERR("%s Intel version event length mismatch", hdev->name);
1166 kfree_skb(skb);
1167 return -EIO;
1168 }
1169
1170 ver = (struct intel_version *)skb->data;
1171 if (ver->status) {
1172 BT_ERR("%s Intel fw version event failed (%02x)", hdev->name,
1173 ver->status);
1174 kfree_skb(skb);
1175 return -bt_to_errno(ver->status);
1176 }
1177
1178 BT_INFO("%s: read Intel version: %02x%02x%02x%02x%02x%02x%02x%02x%02x",
1179 hdev->name, ver->hw_platform, ver->hw_variant,
1180 ver->hw_revision, ver->fw_variant, ver->fw_revision,
1181 ver->fw_build_num, ver->fw_build_ww, ver->fw_build_yy,
1182 ver->fw_patch_num);
1183
1184 /* fw_patch_num indicates the version of patch the device currently
1185 * have. If there is no patch data in the device, it is always 0x00.
1186 * So, if it is other than 0x00, no need to patch the deivce again.
1187 */
1188 if (ver->fw_patch_num) {
1189 BT_INFO("%s: Intel device is already patched. patch num: %02x",
1190 hdev->name, ver->fw_patch_num);
1191 kfree_skb(skb);
1192 return 0;
1193 }
1194
1195 /* Opens the firmware patch file based on the firmware version read
1196 * from the controller. If it fails to open the matching firmware
1197 * patch file, it tries to open the default firmware patch file.
1198 * If no patch file is found, allow the device to operate without
1199 * a patch.
1200 */
1201 fw = btusb_setup_intel_get_fw(hdev, ver);
1202 if (!fw) {
1203 kfree_skb(skb);
1204 return 0;
1205 }
1206 fw_ptr = fw->data;
1207
1208 /* This Intel specific command enables the manufacturer mode of the
1209 * controller.
1210 *
1211 * Only while this mode is enabled, the driver can download the
1212 * firmware patch data and configuration parameters.
1213 */
1214 skb = __hci_cmd_sync(hdev, 0xfc11, 2, mfg_enable, HCI_INIT_TIMEOUT);
1215 if (IS_ERR(skb)) {
1216 BT_ERR("%s entering Intel manufacturer mode failed (%ld)",
1217 hdev->name, PTR_ERR(skb));
1218 release_firmware(fw);
1219 return -PTR_ERR(skb);
1220 }
1221
1222 if (skb->data[0]) {
1223 u8 evt_status = skb->data[0];
1224 BT_ERR("%s enable Intel manufacturer mode event failed (%02x)",
1225 hdev->name, evt_status);
1226 kfree_skb(skb);
1227 release_firmware(fw);
1228 return -bt_to_errno(evt_status);
1229 }
1230 kfree_skb(skb);
1231
1232 disable_patch = 1;
1233
1234 /* The firmware data file consists of list of Intel specific HCI
1235 * commands and its expected events. The first byte indicates the
1236 * type of the message, either HCI command or HCI event.
1237 *
1238 * It reads the command and its expected event from the firmware file,
1239 * and send to the controller. Once __hci_cmd_sync_ev() returns,
1240 * the returned event is compared with the event read from the firmware
1241 * file and it will continue until all the messages are downloaded to
1242 * the controller.
1243 *
1244 * Once the firmware patching is completed successfully,
1245 * the manufacturer mode is disabled with reset and activating the
1246 * downloaded patch.
1247 *
1248 * If the firmware patching fails, the manufacturer mode is
1249 * disabled with reset and deactivating the patch.
1250 *
1251 * If the default patch file is used, no reset is done when disabling
1252 * the manufacturer.
1253 */
1254 while (fw->size > fw_ptr - fw->data) {
1255 int ret;
1256
1257 ret = btusb_setup_intel_patching(hdev, fw, &fw_ptr,
1258 &disable_patch);
1259 if (ret < 0)
1260 goto exit_mfg_deactivate;
1261 }
1262
1263 release_firmware(fw);
1264
1265 if (disable_patch)
1266 goto exit_mfg_disable;
1267
1268 /* Patching completed successfully and disable the manufacturer mode
1269 * with reset and activate the downloaded firmware patches.
1270 */
1271 skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_reset_activate),
1272 mfg_reset_activate, HCI_INIT_TIMEOUT);
1273 if (IS_ERR(skb)) {
1274 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1275 hdev->name, PTR_ERR(skb));
1276 return -PTR_ERR(skb);
1277 }
1278 kfree_skb(skb);
1279
1280 BT_INFO("%s: Intel Bluetooth firmware patch completed and activated",
1281 hdev->name);
1282
1283 return 0;
1284
1285exit_mfg_disable:
1286 /* Disable the manufacturer mode without reset */
1287 skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_disable), mfg_disable,
1288 HCI_INIT_TIMEOUT);
1289 if (IS_ERR(skb)) {
1290 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1291 hdev->name, PTR_ERR(skb));
1292 return -PTR_ERR(skb);
1293 }
1294 kfree_skb(skb);
1295
1296 BT_INFO("%s: Intel Bluetooth firmware patch completed", hdev->name);
1297 return 0;
1298
1299exit_mfg_deactivate:
1300 release_firmware(fw);
1301
1302 /* Patching failed. Disable the manufacturer mode with reset and
1303 * deactivate the downloaded firmware patches.
1304 */
1305 skb = __hci_cmd_sync(hdev, 0xfc11, sizeof(mfg_reset_deactivate),
1306 mfg_reset_deactivate, HCI_INIT_TIMEOUT);
1307 if (IS_ERR(skb)) {
1308 BT_ERR("%s exiting Intel manufacturer mode failed (%ld)",
1309 hdev->name, PTR_ERR(skb));
1310 return -PTR_ERR(skb);
1311 }
1312 kfree_skb(skb);
1313
1314 BT_INFO("%s: Intel Bluetooth firmware patch completed and deactivated",
1315 hdev->name);
1316
1317 return 0;
1318}
1319
946static int btusb_probe(struct usb_interface *intf, 1320static int btusb_probe(struct usb_interface *intf,
947 const struct usb_device_id *id) 1321 const struct usb_device_id *id)
948{ 1322{
@@ -1048,6 +1422,9 @@ static int btusb_probe(struct usb_interface *intf,
1048 if (id->driver_info & BTUSB_BCM92035) 1422 if (id->driver_info & BTUSB_BCM92035)
1049 hdev->setup = btusb_setup_bcm92035; 1423 hdev->setup = btusb_setup_bcm92035;
1050 1424
1425 if (id->driver_info & BTUSB_INTEL)
1426 hdev->setup = btusb_setup_intel;
1427
1051 /* Interface numbers are hardcoded in the specification */ 1428 /* Interface numbers are hardcoded in the specification */
1052 data->isoc = usb_ifnum_to_if(data->udev, 1); 1429 data->isoc = usb_ifnum_to_if(data->udev, 1);
1053 1430
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 80d718a9b31f..35a57cd1704c 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1081,17 +1081,19 @@ struct hci_request {
1081 1081
1082void hci_req_init(struct hci_request *req, struct hci_dev *hdev); 1082void hci_req_init(struct hci_request *req, struct hci_dev *hdev);
1083int hci_req_run(struct hci_request *req, hci_req_complete_t complete); 1083int hci_req_run(struct hci_request *req, hci_req_complete_t complete);
1084void hci_req_add(struct hci_request *req, u16 opcode, u32 plen, void *param); 1084void hci_req_add(struct hci_request *req, u16 opcode, u32 plen,
1085void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen, void *param, 1085 const void *param);
1086 u8 event); 1086void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen,
1087 const void *param, u8 event);
1087void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status); 1088void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status);
1088 1089
1089struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, 1090struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
1090 void *param, u32 timeout); 1091 const void *param, u32 timeout);
1091struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, 1092struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
1092 void *param, u8 event, u32 timeout); 1093 const void *param, u8 event, u32 timeout);
1093 1094
1094int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param); 1095int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
1096 const void *param);
1095void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags); 1097void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
1096void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); 1098void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
1097 1099
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index ce82265f5619..33843c5c4939 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -79,7 +79,8 @@ static void hci_req_cancel(struct hci_dev *hdev, int err)
79 } 79 }
80} 80}
81 81
82struct sk_buff *hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 event) 82static struct sk_buff *hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode,
83 u8 event)
83{ 84{
84 struct hci_ev_cmd_complete *ev; 85 struct hci_ev_cmd_complete *ev;
85 struct hci_event_hdr *hdr; 86 struct hci_event_hdr *hdr;
@@ -134,7 +135,7 @@ failed:
134} 135}
135 136
136struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, 137struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
137 void *param, u8 event, u32 timeout) 138 const void *param, u8 event, u32 timeout)
138{ 139{
139 DECLARE_WAITQUEUE(wait, current); 140 DECLARE_WAITQUEUE(wait, current);
140 struct hci_request req; 141 struct hci_request req;
@@ -188,7 +189,7 @@ struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
188EXPORT_SYMBOL(__hci_cmd_sync_ev); 189EXPORT_SYMBOL(__hci_cmd_sync_ev);
189 190
190struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, 191struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
191 void *param, u32 timeout) 192 const void *param, u32 timeout)
192{ 193{
193 return __hci_cmd_sync_ev(hdev, opcode, plen, param, 0, timeout); 194 return __hci_cmd_sync_ev(hdev, opcode, plen, param, 0, timeout);
194} 195}
@@ -377,6 +378,8 @@ static void bredr_setup(struct hci_request *req)
377 378
378static void le_setup(struct hci_request *req) 379static void le_setup(struct hci_request *req)
379{ 380{
381 struct hci_dev *hdev = req->hdev;
382
380 /* Read LE Buffer Size */ 383 /* Read LE Buffer Size */
381 hci_req_add(req, HCI_OP_LE_READ_BUFFER_SIZE, 0, NULL); 384 hci_req_add(req, HCI_OP_LE_READ_BUFFER_SIZE, 0, NULL);
382 385
@@ -391,6 +394,10 @@ static void le_setup(struct hci_request *req)
391 394
392 /* Read LE Supported States */ 395 /* Read LE Supported States */
393 hci_req_add(req, HCI_OP_LE_READ_SUPPORTED_STATES, 0, NULL); 396 hci_req_add(req, HCI_OP_LE_READ_SUPPORTED_STATES, 0, NULL);
397
398 /* LE-only controllers have LE implicitly enabled */
399 if (!lmp_bredr_capable(hdev))
400 set_bit(HCI_LE_ENABLED, &hdev->dev_flags);
394} 401}
395 402
396static u8 hci_get_inquiry_mode(struct hci_dev *hdev) 403static u8 hci_get_inquiry_mode(struct hci_dev *hdev)
@@ -574,6 +581,10 @@ static void hci_set_le_support(struct hci_request *req)
574 struct hci_dev *hdev = req->hdev; 581 struct hci_dev *hdev = req->hdev;
575 struct hci_cp_write_le_host_supported cp; 582 struct hci_cp_write_le_host_supported cp;
576 583
584 /* LE-only devices do not support explicit enablement */
585 if (!lmp_bredr_capable(hdev))
586 return;
587
577 memset(&cp, 0, sizeof(cp)); 588 memset(&cp, 0, sizeof(cp));
578 589
579 if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) { 590 if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) {
@@ -2602,7 +2613,7 @@ int hci_req_run(struct hci_request *req, hci_req_complete_t complete)
2602} 2613}
2603 2614
2604static struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, 2615static struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode,
2605 u32 plen, void *param) 2616 u32 plen, const void *param)
2606{ 2617{
2607 int len = HCI_COMMAND_HDR_SIZE + plen; 2618 int len = HCI_COMMAND_HDR_SIZE + plen;
2608 struct hci_command_hdr *hdr; 2619 struct hci_command_hdr *hdr;
@@ -2628,7 +2639,8 @@ static struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode,
2628} 2639}
2629 2640
2630/* Send HCI command */ 2641/* Send HCI command */
2631int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param) 2642int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
2643 const void *param)
2632{ 2644{
2633 struct sk_buff *skb; 2645 struct sk_buff *skb;
2634 2646
@@ -2652,8 +2664,8 @@ int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param)
2652} 2664}
2653 2665
2654/* Queue a command to an asynchronous HCI request */ 2666/* Queue a command to an asynchronous HCI request */
2655void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen, void *param, 2667void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen,
2656 u8 event) 2668 const void *param, u8 event)
2657{ 2669{
2658 struct hci_dev *hdev = req->hdev; 2670 struct hci_dev *hdev = req->hdev;
2659 struct sk_buff *skb; 2671 struct sk_buff *skb;
@@ -2682,7 +2694,8 @@ void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen, void *param,
2682 skb_queue_tail(&req->cmd_q, skb); 2694 skb_queue_tail(&req->cmd_q, skb);
2683} 2695}
2684 2696
2685void hci_req_add(struct hci_request *req, u16 opcode, u32 plen, void *param) 2697void hci_req_add(struct hci_request *req, u16 opcode, u32 plen,
2698 const void *param)
2686{ 2699{
2687 hci_req_add_ev(req, opcode, plen, param, 0); 2700 hci_req_add_ev(req, opcode, plen, param, 0);
2688} 2701}
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index eae1d9f90b68..a76d1ac0321b 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -6314,12 +6314,13 @@ drop:
6314 kfree_skb(skb); 6314 kfree_skb(skb);
6315} 6315}
6316 6316
6317static void l2cap_att_channel(struct l2cap_conn *conn, u16 cid, 6317static void l2cap_att_channel(struct l2cap_conn *conn,
6318 struct sk_buff *skb) 6318 struct sk_buff *skb)
6319{ 6319{
6320 struct l2cap_chan *chan; 6320 struct l2cap_chan *chan;
6321 6321
6322 chan = l2cap_global_chan_by_scid(0, cid, conn->src, conn->dst); 6322 chan = l2cap_global_chan_by_scid(0, L2CAP_CID_LE_DATA,
6323 conn->src, conn->dst);
6323 if (!chan) 6324 if (!chan)
6324 goto drop; 6325 goto drop;
6325 6326
@@ -6368,7 +6369,7 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
6368 break; 6369 break;
6369 6370
6370 case L2CAP_CID_LE_DATA: 6371 case L2CAP_CID_LE_DATA:
6371 l2cap_att_channel(conn, cid, skb); 6372 l2cap_att_channel(conn, skb);
6372 break; 6373 break;
6373 6374
6374 case L2CAP_CID_SMP: 6375 case L2CAP_CID_SMP:
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 4c830c62ef74..35fef22703e9 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1351,6 +1351,11 @@ static int set_le(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
1351 return cmd_status(sk, hdev->id, MGMT_OP_SET_LE, 1351 return cmd_status(sk, hdev->id, MGMT_OP_SET_LE,
1352 MGMT_STATUS_INVALID_PARAMS); 1352 MGMT_STATUS_INVALID_PARAMS);
1353 1353
1354 /* LE-only devices do not allow toggling LE on/off */
1355 if (!lmp_bredr_capable(hdev))
1356 return cmd_status(sk, hdev->id, MGMT_OP_SET_LE,
1357 MGMT_STATUS_REJECTED);
1358
1354 hci_dev_lock(hdev); 1359 hci_dev_lock(hdev);
1355 1360
1356 val = !!cp->val; 1361 val = !!cp->val;
@@ -3347,7 +3352,8 @@ static int powered_update_hci(struct hci_dev *hdev)
3347 hci_req_add(&req, HCI_OP_WRITE_SSP_MODE, 1, &ssp); 3352 hci_req_add(&req, HCI_OP_WRITE_SSP_MODE, 1, &ssp);
3348 } 3353 }
3349 3354
3350 if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) { 3355 if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags) &&
3356 lmp_bredr_capable(hdev)) {
3351 struct hci_cp_write_le_host_supported cp; 3357 struct hci_cp_write_le_host_supported cp;
3352 3358
3353 cp.le = 1; 3359 cp.le = 1;