Diff between 81596d12b173a4d53e8fcf04a775ce3c6573d5e9 and 838abde25be799cc3493867bf97d8b624499312f

Changed Files

File Additions Deletions Status
emulator/le.c +17 -2 modified
emulator/phy.h +2 -0 modified

Full Patch

diff --git a/emulator/le.c b/emulator/le.c
index 6ffa0d4..82ae573 100644
--- a/emulator/le.c
+++ b/emulator/le.c
@@ -71,6 +71,7 @@ struct bt_le {
 	int adv_timeout_id;
 	int scan_timeout_id;
 	bool scan_window_active;
+	uint8_t scan_chan_idx;
 
 	uint8_t  event_mask[16];
 	uint16_t manufacturer;
@@ -424,11 +425,12 @@ static void send_event(struct bt_le *hci, uint8_t event,
 		fprintf(stderr, "Write to /dev/vhci failed (%m)\n");
 }
 
-static void send_adv_pkt(struct bt_le *hci)
+static void send_adv_pkt(struct bt_le *hci, uint8_t channel)
 {
 	struct bt_phy_pkt_adv pkt;
 
 	memset(&pkt, 0, sizeof(pkt));
+	pkt.chan_idx = channel;
 	pkt.pdu_type = hci->le_adv_type;
 	pkt.tx_addr_type = hci->le_adv_own_addr_type;
 	switch (hci->le_adv_own_addr_type) {
@@ -465,7 +467,12 @@ static void adv_timeout_callback(int id, void *user_data)
 	struct bt_le *hci = user_data;
 	unsigned int msec, min_msec, max_msec;
 
-	send_adv_pkt(hci);
+	if (hci->le_adv_channel_map & 0x01)
+		send_adv_pkt(hci, 37);
+	if (hci->le_adv_channel_map & 0x02)
+		send_adv_pkt(hci, 38);
+	if (hci->le_adv_channel_map & 0x04)
+		send_adv_pkt(hci, 39);
 
 	min_msec = (hci->le_adv_min_interval * 625) / 1000;
 	max_msec = (hci->le_adv_max_interval * 625) / 1000;
@@ -515,6 +522,10 @@ static void scan_timeout_callback(int id, void *user_data)
 						!hci->scan_window_active) {
 		msec = (hci->le_scan_window * 625) / 1000;
 		hci->scan_window_active = true;
+
+		hci->scan_chan_idx++;
+		if (hci->scan_chan_idx > 39)
+			hci->scan_chan_idx = 37;
 	} else {
 		msec = ((hci->le_scan_interval -
 					hci->le_scan_window) * 625) / 1000;
@@ -543,6 +554,7 @@ static bool start_scan(struct bt_le *hci)
 		return false;
 
 	hci->scan_window_active = true;
+	hci->scan_chan_idx = 37;
 
 	return true;
 }
@@ -1796,6 +1808,9 @@ static void phy_recv_callback(uint16_t type, const void *data,
 			struct bt_hci_evt_le_adv_report *evt = (void *) buf;
 			uint8_t tx_addr_type, tx_addr[6];
 
+			if (hci->scan_chan_idx != pkt->chan_idx)
+				break;
+
 			resolve_peer_addr(hci, pkt->tx_addr_type, pkt->tx_addr,
 							&tx_addr_type, tx_addr);
 
diff --git a/emulator/phy.h b/emulator/phy.h
index 9abfd68..d5efa51 100644
--- a/emulator/phy.h
+++ b/emulator/phy.h
@@ -49,6 +49,7 @@ bool bt_phy_register(struct bt_phy *phy, bt_phy_callback_func_t callback,
 
 #define BT_PHY_PKT_ADV		0x0001
 struct bt_phy_pkt_adv {
+	uint8_t  chan_idx;
 	uint8_t  pdu_type;
 	uint8_t  tx_addr_type;
 	uint8_t  tx_addr[6];
@@ -60,6 +61,7 @@ struct bt_phy_pkt_adv {
 
 #define BT_PHY_PKT_CONN		0x0002
 struct bt_phy_pkt_conn {
+	uint8_t  chan_idx;
 	uint8_t  link_type;
 	uint8_t  tx_addr_type;
 	uint8_t  tx_addr[6];