提交 b24752fe 编写于 作者: J Johan Hedberg 提交者: Gustavo F. Padovan

Bluetooth: Fix mgmt response when adapter goes down or is removed

When an adapter gets powered off or is removed any pending commands
should receive a ENETDOWN or ENODEV status response.
Signed-off-by: NJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: NGustavo F. Padovan <padovan@profusion.mobi>
上级 08add513
...@@ -262,7 +262,7 @@ static void mgmt_pending_foreach(u16 opcode, int index, ...@@ -262,7 +262,7 @@ static void mgmt_pending_foreach(u16 opcode, int index,
cmd = list_entry(p, struct pending_cmd, list); cmd = list_entry(p, struct pending_cmd, list);
if (cmd->opcode != opcode) if (opcode > 0 && cmd->opcode != opcode)
continue; continue;
if (index >= 0 && cmd->index != index) if (index >= 0 && cmd->index != index)
...@@ -1949,6 +1949,14 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen) ...@@ -1949,6 +1949,14 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
return err; return err;
} }
static void cmd_status_rsp(struct pending_cmd *cmd, void *data)
{
u8 *status = data;
cmd_status(cmd->sk, cmd->index, cmd->opcode, *status);
mgmt_pending_remove(cmd);
}
int mgmt_index_added(u16 index) int mgmt_index_added(u16 index)
{ {
return mgmt_event(MGMT_EV_INDEX_ADDED, index, NULL, 0, NULL); return mgmt_event(MGMT_EV_INDEX_ADDED, index, NULL, 0, NULL);
...@@ -1956,6 +1964,10 @@ int mgmt_index_added(u16 index) ...@@ -1956,6 +1964,10 @@ int mgmt_index_added(u16 index)
int mgmt_index_removed(u16 index) int mgmt_index_removed(u16 index)
{ {
u8 status = ENODEV;
mgmt_pending_foreach(0, index, cmd_status_rsp, &status);
return mgmt_event(MGMT_EV_INDEX_REMOVED, index, NULL, 0, NULL); return mgmt_event(MGMT_EV_INDEX_REMOVED, index, NULL, 0, NULL);
} }
...@@ -1992,6 +2004,11 @@ int mgmt_powered(u16 index, u8 powered) ...@@ -1992,6 +2004,11 @@ int mgmt_powered(u16 index, u8 powered)
mgmt_pending_foreach(MGMT_OP_SET_POWERED, index, mode_rsp, &match); mgmt_pending_foreach(MGMT_OP_SET_POWERED, index, mode_rsp, &match);
if (!powered) {
u8 status = ENETDOWN;
mgmt_pending_foreach(0, index, cmd_status_rsp, &status);
}
ev.val = powered; ev.val = powered;
ret = mgmt_event(MGMT_EV_POWERED, index, &ev, sizeof(ev), match.sk); ret = mgmt_event(MGMT_EV_POWERED, index, &ev, sizeof(ev), match.sk);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册