aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/mgmt.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2015-03-06 14:08:51 -0500
committerMarcel Holtmann <marcel@holtmann.org>2015-03-06 14:15:21 -0500
commit6d785aa345f525e1fdf098b7c590168f0b00f3f1 (patch)
tree90aa79cca35cabed308ca3719bef5b516867b490 /net/bluetooth/mgmt.c
parent801c1e8da57499a9922223ee1882b2b59debd47c (diff)
Bluetooth: Convert mgmt to use HCI chan registration API
This patch converts the existing mgmt code to use the newly introduced generic API for registering HCI channels with mgmt-like semantics. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth/mgmt.c')
-rw-r--r--net/bluetooth/mgmt.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index d185a9800983..bb02dd1b82bf 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -6130,12 +6130,7 @@ unlock:
6130 return err; 6130 return err;
6131} 6131}
6132 6132
6133static const struct mgmt_handler { 6133static const struct hci_mgmt_handler mgmt_handlers[] = {
6134 int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
6135 u16 data_len);
6136 bool var_len;
6137 size_t data_len;
6138} mgmt_handlers[] = {
6139 { NULL }, /* 0x0000 (no command) */ 6134 { NULL }, /* 0x0000 (no command) */
6140 { read_version, false, MGMT_READ_VERSION_SIZE }, 6135 { read_version, false, MGMT_READ_VERSION_SIZE },
6141 { read_commands, false, MGMT_READ_COMMANDS_SIZE }, 6136 { read_commands, false, MGMT_READ_COMMANDS_SIZE },
@@ -6197,14 +6192,15 @@ static const struct mgmt_handler {
6197 { start_service_discovery,true, MGMT_START_SERVICE_DISCOVERY_SIZE }, 6192 { start_service_discovery,true, MGMT_START_SERVICE_DISCOVERY_SIZE },
6198}; 6193};
6199 6194
6200int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) 6195int mgmt_control(struct hci_mgmt_chan *chan, struct sock *sk,
6196 struct msghdr *msg, size_t msglen)
6201{ 6197{
6202 void *buf; 6198 void *buf;
6203 u8 *cp; 6199 u8 *cp;
6204 struct mgmt_hdr *hdr; 6200 struct mgmt_hdr *hdr;
6205 u16 opcode, index, len; 6201 u16 opcode, index, len;
6206 struct hci_dev *hdev = NULL; 6202 struct hci_dev *hdev = NULL;
6207 const struct mgmt_handler *handler; 6203 const struct hci_mgmt_handler *handler;
6208 int err; 6204 int err;
6209 6205
6210 BT_DBG("got %zu bytes", msglen); 6206 BT_DBG("got %zu bytes", msglen);
@@ -6257,8 +6253,8 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
6257 } 6253 }
6258 } 6254 }
6259 6255
6260 if (opcode >= ARRAY_SIZE(mgmt_handlers) || 6256 if (opcode >= chan->handler_count ||
6261 mgmt_handlers[opcode].func == NULL) { 6257 chan->handlers[opcode].func == NULL) {
6262 BT_DBG("Unknown op %u", opcode); 6258 BT_DBG("Unknown op %u", opcode);
6263 err = cmd_status(sk, index, opcode, 6259 err = cmd_status(sk, index, opcode,
6264 MGMT_STATUS_UNKNOWN_COMMAND); 6260 MGMT_STATUS_UNKNOWN_COMMAND);
@@ -6279,7 +6275,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
6279 goto done; 6275 goto done;
6280 } 6276 }
6281 6277
6282 handler = &mgmt_handlers[opcode]; 6278 handler = &chan->handlers[opcode];
6283 6279
6284 if ((handler->var_len && len < handler->data_len) || 6280 if ((handler->var_len && len < handler->data_len) ||
6285 (!handler->var_len && len != handler->data_len)) { 6281 (!handler->var_len && len != handler->data_len)) {
@@ -7470,3 +7466,19 @@ void mgmt_reenable_advertising(struct hci_dev *hdev)
7470 enable_advertising(&req); 7466 enable_advertising(&req);
7471 hci_req_run(&req, adv_enable_complete); 7467 hci_req_run(&req, adv_enable_complete);
7472} 7468}
7469
7470static struct hci_mgmt_chan chan = {
7471 .channel = HCI_CHANNEL_CONTROL,
7472 .handler_count = ARRAY_SIZE(mgmt_handlers),
7473 .handlers = mgmt_handlers,
7474};
7475
7476int mgmt_init(void)
7477{
7478 return hci_mgmt_chan_register(&chan);
7479}
7480
7481void mgmt_exit(void)
7482{
7483 hci_mgmt_chan_unregister(&chan);
7484}