Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 247247
b: refs/heads/master
c: 14a5366
h: refs/heads/master
i:
  247245: b4f3524
  247243: 09d38d4
  247239: aabaf0f
  247231: c228e3f
v: v3
  • Loading branch information
Johan Hedberg authored and Gustavo F. Padovan committed Apr 28, 2011
1 parent 84d67d5 commit b0c7177
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cf2f90f59bbf2c2a539d171cde6e1dfe72048555
refs/heads/master: 14a53664138a8407382745bb470045d1817b7801
4 changes: 4 additions & 0 deletions trunk/include/net/bluetooth/mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ struct mgmt_cp_remove_remote_oob_data {
bdaddr_t bdaddr;
} __packed;

#define MGMT_OP_START_DISCOVERY 0x001B

#define MGMT_OP_STOP_DISCOVERY 0x001C

#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
Expand Down
76 changes: 75 additions & 1 deletion trunk/net/bluetooth/mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,75 @@ static int remove_remote_oob_data(struct sock *sk, u16 index,
return err;
}

static int start_discovery(struct sock *sk, u16 index)
{
u8 lap[3] = { 0x33, 0x8b, 0x9e };
struct hci_cp_inquiry cp;
struct pending_cmd *cmd;
struct hci_dev *hdev;
int err;

BT_DBG("hci%u", index);

hdev = hci_dev_get(index);
if (!hdev)
return cmd_status(sk, index, MGMT_OP_START_DISCOVERY, ENODEV);

hci_dev_lock_bh(hdev);

cmd = mgmt_pending_add(sk, MGMT_OP_START_DISCOVERY, index, NULL, 0);
if (!cmd) {
err = -ENOMEM;
goto failed;
}

memset(&cp, 0, sizeof(cp));
memcpy(&cp.lap, lap, 3);
cp.length = 0x08;
cp.num_rsp = 0x00;

err = hci_send_cmd(hdev, HCI_OP_INQUIRY, sizeof(cp), &cp);
if (err < 0)
mgmt_pending_remove(cmd);

failed:
hci_dev_unlock_bh(hdev);
hci_dev_put(hdev);

return err;
}

static int stop_discovery(struct sock *sk, u16 index)
{
struct hci_dev *hdev;
struct pending_cmd *cmd;
int err;

BT_DBG("hci%u", index);

hdev = hci_dev_get(index);
if (!hdev)
return cmd_status(sk, index, MGMT_OP_STOP_DISCOVERY, ENODEV);

hci_dev_lock_bh(hdev);

cmd = mgmt_pending_add(sk, MGMT_OP_STOP_DISCOVERY, index, NULL, 0);
if (!cmd) {
err = -ENOMEM;
goto failed;
}

err = hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL);
if (err < 0)
mgmt_pending_remove(cmd);

failed:
hci_dev_unlock_bh(hdev);
hci_dev_put(hdev);

return err;
}

int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
{
unsigned char *buf;
Expand Down Expand Up @@ -1677,7 +1746,12 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
err = remove_remote_oob_data(sk, index, buf + sizeof(*hdr),
len);
break;

case MGMT_OP_START_DISCOVERY:
err = start_discovery(sk, index);
break;
case MGMT_OP_STOP_DISCOVERY:
err = stop_discovery(sk, index);
break;
default:
BT_DBG("Unknown op %u", opcode);
err = cmd_status(sk, index, opcode, 0x01);
Expand Down

0 comments on commit b0c7177

Please sign in to comment.