mgmt.c (f17d858ed0a48270db4368d8cf370e3839ee6f4f) | mgmt.c (2064ee332e4c1b7495cf68b84355c213d8fe71fd) |
---|---|
1/* 2 BlueZ - Bluetooth protocol stack for Linux 3 4 Copyright (C) 2010 Nokia Corporation 5 Copyright (C) 2011-2012 Intel Corporation 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License version 2 as --- 2145 unchanged lines hidden (view full) --- 2154 BT_DBG("request for %s", hdev->name); 2155 2156 if (!lmp_bredr_capable(hdev)) 2157 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 2158 MGMT_STATUS_NOT_SUPPORTED); 2159 2160 key_count = __le16_to_cpu(cp->key_count); 2161 if (key_count > max_key_count) { | 1/* 2 BlueZ - Bluetooth protocol stack for Linux 3 4 Copyright (C) 2010 Nokia Corporation 5 Copyright (C) 2011-2012 Intel Corporation 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License version 2 as --- 2145 unchanged lines hidden (view full) --- 2154 BT_DBG("request for %s", hdev->name); 2155 2156 if (!lmp_bredr_capable(hdev)) 2157 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 2158 MGMT_STATUS_NOT_SUPPORTED); 2159 2160 key_count = __le16_to_cpu(cp->key_count); 2161 if (key_count > max_key_count) { |
2162 BT_ERR("load_link_keys: too big key_count value %u", 2163 key_count); | 2162 bt_dev_err(hdev, "load_link_keys: too big key_count value %u", 2163 key_count); |
2164 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 2165 MGMT_STATUS_INVALID_PARAMS); 2166 } 2167 2168 expected_len = sizeof(*cp) + key_count * 2169 sizeof(struct mgmt_link_key_info); 2170 if (expected_len != len) { | 2164 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 2165 MGMT_STATUS_INVALID_PARAMS); 2166 } 2167 2168 expected_len = sizeof(*cp) + key_count * 2169 sizeof(struct mgmt_link_key_info); 2170 if (expected_len != len) { |
2171 BT_ERR("load_link_keys: expected %u bytes, got %u bytes", 2172 expected_len, len); | 2171 bt_dev_err(hdev, "load_link_keys: expected %u bytes, got %u bytes", 2172 expected_len, len); |
2173 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 2174 MGMT_STATUS_INVALID_PARAMS); 2175 } 2176 2177 if (cp->debug_keys != 0x00 && cp->debug_keys != 0x01) 2178 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 2179 MGMT_STATUS_INVALID_PARAMS); 2180 --- 375 unchanged lines hidden (view full) --- 2556 goto failed; 2557 } 2558 2559 if (conn->pending_sec_level == BT_SECURITY_HIGH && cp->pin_len != 16) { 2560 struct mgmt_cp_pin_code_neg_reply ncp; 2561 2562 memcpy(&ncp.addr, &cp->addr, sizeof(ncp.addr)); 2563 | 2173 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 2174 MGMT_STATUS_INVALID_PARAMS); 2175 } 2176 2177 if (cp->debug_keys != 0x00 && cp->debug_keys != 0x01) 2178 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 2179 MGMT_STATUS_INVALID_PARAMS); 2180 --- 375 unchanged lines hidden (view full) --- 2556 goto failed; 2557 } 2558 2559 if (conn->pending_sec_level == BT_SECURITY_HIGH && cp->pin_len != 16) { 2560 struct mgmt_cp_pin_code_neg_reply ncp; 2561 2562 memcpy(&ncp.addr, &cp->addr, sizeof(ncp.addr)); 2563 |
2564 BT_ERR("PIN code is not 16 bytes long"); | 2564 bt_dev_err(hdev, "PIN code is not 16 bytes long"); |
2565 2566 err = send_pin_code_neg_reply(sk, hdev, &ncp); 2567 if (err >= 0) 2568 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, 2569 MGMT_STATUS_INVALID_PARAMS); 2570 2571 goto failed; 2572 } --- 813 unchanged lines hidden (view full) --- 3386 status = MGMT_STATUS_FAILED; 3387 else 3388 status = MGMT_STATUS_SUCCESS; 3389 3390 err = mgmt_cmd_complete(sk, hdev->id, 3391 MGMT_OP_ADD_REMOTE_OOB_DATA, 3392 status, &cp->addr, sizeof(cp->addr)); 3393 } else { | 2565 2566 err = send_pin_code_neg_reply(sk, hdev, &ncp); 2567 if (err >= 0) 2568 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, 2569 MGMT_STATUS_INVALID_PARAMS); 2570 2571 goto failed; 2572 } --- 813 unchanged lines hidden (view full) --- 3386 status = MGMT_STATUS_FAILED; 3387 else 3388 status = MGMT_STATUS_SUCCESS; 3389 3390 err = mgmt_cmd_complete(sk, hdev->id, 3391 MGMT_OP_ADD_REMOTE_OOB_DATA, 3392 status, &cp->addr, sizeof(cp->addr)); 3393 } else { |
3394 BT_ERR("add_remote_oob_data: invalid length of %u bytes", len); | 3394 bt_dev_err(hdev, "add_remote_oob_data: invalid len of %u bytes", 3395 len); |
3395 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, 3396 MGMT_STATUS_INVALID_PARAMS); 3397 } 3398 3399unlock: 3400 hci_dev_unlock(hdev); 3401 return err; 3402} --- 196 unchanged lines hidden (view full) --- 3599 MGMT_OP_START_SERVICE_DISCOVERY, 3600 MGMT_STATUS_BUSY, &cp->type, 3601 sizeof(cp->type)); 3602 goto failed; 3603 } 3604 3605 uuid_count = __le16_to_cpu(cp->uuid_count); 3606 if (uuid_count > max_uuid_count) { | 3396 err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_REMOTE_OOB_DATA, 3397 MGMT_STATUS_INVALID_PARAMS); 3398 } 3399 3400unlock: 3401 hci_dev_unlock(hdev); 3402 return err; 3403} --- 196 unchanged lines hidden (view full) --- 3600 MGMT_OP_START_SERVICE_DISCOVERY, 3601 MGMT_STATUS_BUSY, &cp->type, 3602 sizeof(cp->type)); 3603 goto failed; 3604 } 3605 3606 uuid_count = __le16_to_cpu(cp->uuid_count); 3607 if (uuid_count > max_uuid_count) { |
3607 BT_ERR("service_discovery: too big uuid_count value %u", 3608 uuid_count); | 3608 bt_dev_err(hdev, "service_discovery: too big uuid_count value %u", 3609 uuid_count); |
3609 err = mgmt_cmd_complete(sk, hdev->id, 3610 MGMT_OP_START_SERVICE_DISCOVERY, 3611 MGMT_STATUS_INVALID_PARAMS, &cp->type, 3612 sizeof(cp->type)); 3613 goto failed; 3614 } 3615 3616 expected_len = sizeof(*cp) + uuid_count * 16; 3617 if (expected_len != len) { | 3610 err = mgmt_cmd_complete(sk, hdev->id, 3611 MGMT_OP_START_SERVICE_DISCOVERY, 3612 MGMT_STATUS_INVALID_PARAMS, &cp->type, 3613 sizeof(cp->type)); 3614 goto failed; 3615 } 3616 3617 expected_len = sizeof(*cp) + uuid_count * 16; 3618 if (expected_len != len) { |
3618 BT_ERR("service_discovery: expected %u bytes, got %u bytes", 3619 expected_len, len); | 3619 bt_dev_err(hdev, "service_discovery: expected %u bytes, got %u bytes", 3620 expected_len, len); |
3620 err = mgmt_cmd_complete(sk, hdev->id, 3621 MGMT_OP_START_SERVICE_DISCOVERY, 3622 MGMT_STATUS_INVALID_PARAMS, &cp->type, 3623 sizeof(cp->type)); 3624 goto failed; 3625 } 3626 3627 if (!discovery_type_is_valid(hdev, cp->type, &status)) { --- 310 unchanged lines hidden (view full) --- 3938 hci_req_init(&req, hdev); 3939 3940 err = __hci_req_schedule_adv_instance(&req, instance, true); 3941 3942 if (!err) 3943 err = hci_req_run(&req, enable_advertising_instance); 3944 3945 if (err) | 3621 err = mgmt_cmd_complete(sk, hdev->id, 3622 MGMT_OP_START_SERVICE_DISCOVERY, 3623 MGMT_STATUS_INVALID_PARAMS, &cp->type, 3624 sizeof(cp->type)); 3625 goto failed; 3626 } 3627 3628 if (!discovery_type_is_valid(hdev, cp->type, &status)) { --- 310 unchanged lines hidden (view full) --- 3939 hci_req_init(&req, hdev); 3940 3941 err = __hci_req_schedule_adv_instance(&req, instance, true); 3942 3943 if (!err) 3944 err = hci_req_run(&req, enable_advertising_instance); 3945 3946 if (err) |
3946 BT_ERR("Failed to re-configure advertising"); | 3947 bt_dev_err(hdev, "failed to re-configure advertising"); |
3947 3948unlock: 3949 hci_dev_unlock(hdev); 3950} 3951 3952static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, 3953 u16 len) 3954{ --- 704 unchanged lines hidden (view full) --- 4659 BT_DBG("request for %s", hdev->name); 4660 4661 if (!lmp_le_capable(hdev)) 4662 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, 4663 MGMT_STATUS_NOT_SUPPORTED); 4664 4665 irk_count = __le16_to_cpu(cp->irk_count); 4666 if (irk_count > max_irk_count) { | 3948 3949unlock: 3950 hci_dev_unlock(hdev); 3951} 3952 3953static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data, 3954 u16 len) 3955{ --- 704 unchanged lines hidden (view full) --- 4660 BT_DBG("request for %s", hdev->name); 4661 4662 if (!lmp_le_capable(hdev)) 4663 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, 4664 MGMT_STATUS_NOT_SUPPORTED); 4665 4666 irk_count = __le16_to_cpu(cp->irk_count); 4667 if (irk_count > max_irk_count) { |
4667 BT_ERR("load_irks: too big irk_count value %u", irk_count); | 4668 bt_dev_err(hdev, "load_irks: too big irk_count value %u", 4669 irk_count); |
4668 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, 4669 MGMT_STATUS_INVALID_PARAMS); 4670 } 4671 4672 expected_len = sizeof(*cp) + irk_count * sizeof(struct mgmt_irk_info); 4673 if (expected_len != len) { | 4670 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, 4671 MGMT_STATUS_INVALID_PARAMS); 4672 } 4673 4674 expected_len = sizeof(*cp) + irk_count * sizeof(struct mgmt_irk_info); 4675 if (expected_len != len) { |
4674 BT_ERR("load_irks: expected %u bytes, got %u bytes", 4675 expected_len, len); | 4676 bt_dev_err(hdev, "load_irks: expected %u bytes, got %u bytes", 4677 expected_len, len); |
4676 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, 4677 MGMT_STATUS_INVALID_PARAMS); 4678 } 4679 4680 BT_DBG("%s irk_count %u", hdev->name, irk_count); 4681 4682 for (i = 0; i < irk_count; i++) { 4683 struct mgmt_irk_info *key = &cp->irks[i]; --- 56 unchanged lines hidden (view full) --- 4740 BT_DBG("request for %s", hdev->name); 4741 4742 if (!lmp_le_capable(hdev)) 4743 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 4744 MGMT_STATUS_NOT_SUPPORTED); 4745 4746 key_count = __le16_to_cpu(cp->key_count); 4747 if (key_count > max_key_count) { | 4678 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_IRKS, 4679 MGMT_STATUS_INVALID_PARAMS); 4680 } 4681 4682 BT_DBG("%s irk_count %u", hdev->name, irk_count); 4683 4684 for (i = 0; i < irk_count; i++) { 4685 struct mgmt_irk_info *key = &cp->irks[i]; --- 56 unchanged lines hidden (view full) --- 4742 BT_DBG("request for %s", hdev->name); 4743 4744 if (!lmp_le_capable(hdev)) 4745 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 4746 MGMT_STATUS_NOT_SUPPORTED); 4747 4748 key_count = __le16_to_cpu(cp->key_count); 4749 if (key_count > max_key_count) { |
4748 BT_ERR("load_ltks: too big key_count value %u", key_count); | 4750 bt_dev_err(hdev, "load_ltks: too big key_count value %u", 4751 key_count); |
4749 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 4750 MGMT_STATUS_INVALID_PARAMS); 4751 } 4752 4753 expected_len = sizeof(*cp) + key_count * 4754 sizeof(struct mgmt_ltk_info); 4755 if (expected_len != len) { | 4752 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 4753 MGMT_STATUS_INVALID_PARAMS); 4754 } 4755 4756 expected_len = sizeof(*cp) + key_count * 4757 sizeof(struct mgmt_ltk_info); 4758 if (expected_len != len) { |
4756 BT_ERR("load_keys: expected %u bytes, got %u bytes", 4757 expected_len, len); | 4759 bt_dev_err(hdev, "load_keys: expected %u bytes, got %u bytes", 4760 expected_len, len); |
4758 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 4759 MGMT_STATUS_INVALID_PARAMS); 4760 } 4761 4762 BT_DBG("%s key_count %u", hdev->name, key_count); 4763 4764 for (i = 0; i < key_count; i++) { 4765 struct mgmt_ltk_info *key = &cp->keys[i]; --- 102 unchanged lines hidden (view full) --- 4868 if (!cp) { 4869 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER); 4870 status = MGMT_STATUS_SUCCESS; 4871 } else { 4872 status = mgmt_status(hci_status); 4873 } 4874 4875 if (!cp) { | 4761 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 4762 MGMT_STATUS_INVALID_PARAMS); 4763 } 4764 4765 BT_DBG("%s key_count %u", hdev->name, key_count); 4766 4767 for (i = 0; i < key_count; i++) { 4768 struct mgmt_ltk_info *key = &cp->keys[i]; --- 102 unchanged lines hidden (view full) --- 4871 if (!cp) { 4872 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER); 4873 status = MGMT_STATUS_SUCCESS; 4874 } else { 4875 status = mgmt_status(hci_status); 4876 } 4877 4878 if (!cp) { |
4876 BT_ERR("invalid sent_cmd in conn_info response"); | 4879 bt_dev_err(hdev, "invalid sent_cmd in conn_info response"); |
4877 goto unlock; 4878 } 4879 4880 handle = __le16_to_cpu(cp->handle); 4881 conn = hci_conn_hash_lookup_handle(hdev, handle); 4882 if (!conn) { | 4880 goto unlock; 4881 } 4882 4883 handle = __le16_to_cpu(cp->handle); 4884 conn = hci_conn_hash_lookup_handle(hdev, handle); 4885 if (!conn) { |
4883 BT_ERR("unknown handle (%d) in conn_info response", handle); | 4886 bt_dev_err(hdev, "unknown handle (%d) in conn_info response", 4887 handle); |
4884 goto unlock; 4885 } 4886 4887 cmd = pending_find_data(MGMT_OP_GET_CONN_INFO, hdev, conn); 4888 if (!cmd) 4889 goto unlock; 4890 4891 cmd->cmd_complete(cmd, status); --- 580 unchanged lines hidden (view full) --- 5472 int i; 5473 5474 if (!lmp_le_capable(hdev)) 5475 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 5476 MGMT_STATUS_NOT_SUPPORTED); 5477 5478 param_count = __le16_to_cpu(cp->param_count); 5479 if (param_count > max_param_count) { | 4888 goto unlock; 4889 } 4890 4891 cmd = pending_find_data(MGMT_OP_GET_CONN_INFO, hdev, conn); 4892 if (!cmd) 4893 goto unlock; 4894 4895 cmd->cmd_complete(cmd, status); --- 580 unchanged lines hidden (view full) --- 5476 int i; 5477 5478 if (!lmp_le_capable(hdev)) 5479 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 5480 MGMT_STATUS_NOT_SUPPORTED); 5481 5482 param_count = __le16_to_cpu(cp->param_count); 5483 if (param_count > max_param_count) { |
5480 BT_ERR("load_conn_param: too big param_count value %u", 5481 param_count); | 5484 bt_dev_err(hdev, "load_conn_param: too big param_count value %u", 5485 param_count); |
5482 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 5483 MGMT_STATUS_INVALID_PARAMS); 5484 } 5485 5486 expected_len = sizeof(*cp) + param_count * 5487 sizeof(struct mgmt_conn_param); 5488 if (expected_len != len) { | 5486 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 5487 MGMT_STATUS_INVALID_PARAMS); 5488 } 5489 5490 expected_len = sizeof(*cp) + param_count * 5491 sizeof(struct mgmt_conn_param); 5492 if (expected_len != len) { |
5489 BT_ERR("load_conn_param: expected %u bytes, got %u bytes", 5490 expected_len, len); | 5493 bt_dev_err(hdev, "load_conn_param: expected %u bytes, got %u bytes", 5494 expected_len, len); |
5491 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 5492 MGMT_STATUS_INVALID_PARAMS); 5493 } 5494 5495 BT_DBG("%s param_count %u", hdev->name, param_count); 5496 5497 hci_dev_lock(hdev); 5498 --- 8 unchanged lines hidden (view full) --- 5507 BT_DBG("Adding %pMR (type %u)", ¶m->addr.bdaddr, 5508 param->addr.type); 5509 5510 if (param->addr.type == BDADDR_LE_PUBLIC) { 5511 addr_type = ADDR_LE_DEV_PUBLIC; 5512 } else if (param->addr.type == BDADDR_LE_RANDOM) { 5513 addr_type = ADDR_LE_DEV_RANDOM; 5514 } else { | 5495 return mgmt_cmd_status(sk, hdev->id, MGMT_OP_LOAD_CONN_PARAM, 5496 MGMT_STATUS_INVALID_PARAMS); 5497 } 5498 5499 BT_DBG("%s param_count %u", hdev->name, param_count); 5500 5501 hci_dev_lock(hdev); 5502 --- 8 unchanged lines hidden (view full) --- 5511 BT_DBG("Adding %pMR (type %u)", ¶m->addr.bdaddr, 5512 param->addr.type); 5513 5514 if (param->addr.type == BDADDR_LE_PUBLIC) { 5515 addr_type = ADDR_LE_DEV_PUBLIC; 5516 } else if (param->addr.type == BDADDR_LE_RANDOM) { 5517 addr_type = ADDR_LE_DEV_RANDOM; 5518 } else { |
5515 BT_ERR("Ignoring invalid connection parameters"); | 5519 bt_dev_err(hdev, "ignoring invalid connection parameters"); |
5516 continue; 5517 } 5518 5519 min = le16_to_cpu(param->min_interval); 5520 max = le16_to_cpu(param->max_interval); 5521 latency = le16_to_cpu(param->latency); 5522 timeout = le16_to_cpu(param->timeout); 5523 5524 BT_DBG("min 0x%04x max 0x%04x latency 0x%04x timeout 0x%04x", 5525 min, max, latency, timeout); 5526 5527 if (hci_check_conn_params(min, max, latency, timeout) < 0) { | 5520 continue; 5521 } 5522 5523 min = le16_to_cpu(param->min_interval); 5524 max = le16_to_cpu(param->max_interval); 5525 latency = le16_to_cpu(param->latency); 5526 timeout = le16_to_cpu(param->timeout); 5527 5528 BT_DBG("min 0x%04x max 0x%04x latency 0x%04x timeout 0x%04x", 5529 min, max, latency, timeout); 5530 5531 if (hci_check_conn_params(min, max, latency, timeout) < 0) { |
5528 BT_ERR("Ignoring invalid connection parameters"); | 5532 bt_dev_err(hdev, "ignoring invalid connection parameters"); |
5529 continue; 5530 } 5531 5532 hci_param = hci_conn_params_add(hdev, ¶m->addr.bdaddr, 5533 addr_type); 5534 if (!hci_param) { | 5533 continue; 5534 } 5535 5536 hci_param = hci_conn_params_add(hdev, ¶m->addr.bdaddr, 5537 addr_type); 5538 if (!hci_param) { |
5535 BT_ERR("Failed to add connection parameters"); | 5539 bt_dev_err(hdev, "failed to add connection parameters"); |
5536 continue; 5537 } 5538 5539 hci_param->conn_min_interval = min; 5540 hci_param->conn_max_interval = max; 5541 hci_param->conn_latency = latency; 5542 hci_param->supervision_timeout = timeout; 5543 } --- 2036 unchanged lines hidden --- | 5540 continue; 5541 } 5542 5543 hci_param->conn_min_interval = min; 5544 hci_param->conn_max_interval = max; 5545 hci_param->conn_latency = latency; 5546 hci_param->supervision_timeout = timeout; 5547 } --- 2036 unchanged lines hidden --- |