Skip to content

Commit be9690c

Browse files
kapbhnordicjm
authored andcommitted
samples: raw_tx_packet: Set operating channel in DS parameter
In payload set operating channel in DS parameter feild for connected and non-connected mode. Signed-off-by: Kapil Bhatt <[email protected]>
1 parent c411d38 commit be9690c

File tree

1 file changed

+50
-0
lines changed
  • samples/wifi/raw_tx_packet/src

1 file changed

+50
-0
lines changed

samples/wifi/raw_tx_packet/src/main.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ LOG_MODULE_REGISTER(raw_tx_packet, CONFIG_LOG_DEFAULT_LEVEL);
2525
#include "wifi_connection.h"
2626

2727
#define BEACON_PAYLOAD_LENGTH 256
28+
#define DEFAULT_RAW_TX_WIFI_CHANNEL 6
2829
#define PADDING_ZERO_THRESHOLD 10
30+
#define DS_PARAMETER_SET_ELEMENT_ID 3
31+
#define DS_PARAMETER_SET_LENGTH 1
2932
#define CONTINUOUS_MODE_TRANSMISSION 0
3033
#define FIXED_MODE_TRANSMISSION 1
3134

@@ -256,6 +259,51 @@ static unsigned short calculate_beacon_frame_length(const struct beacon *beacon_
256259
return header_length + payload_length;
257260
}
258261

262+
static void update_beacon_channel(void)
263+
{
264+
uint8_t channel;
265+
struct net_if *iface = net_if_get_first_wifi();
266+
267+
if (!iface) {
268+
channel = DEFAULT_RAW_TX_WIFI_CHANNEL;
269+
} else {
270+
#ifdef CONFIG_RAW_TX_PKT_SAMPLE_CONNECTION_MODE
271+
struct wifi_iface_status status = {0};
272+
273+
if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &status, sizeof(status)) == 0) {
274+
if (status.state >= WIFI_STATE_ASSOCIATED && status.channel > 0) {
275+
channel = (uint8_t)status.channel;
276+
} else {
277+
channel = DEFAULT_RAW_TX_WIFI_CHANNEL;
278+
}
279+
} else {
280+
channel = DEFAULT_RAW_TX_WIFI_CHANNEL;
281+
}
282+
#else
283+
channel = CONFIG_RAW_TX_PKT_SAMPLE_CHANNEL;
284+
#endif
285+
}
286+
287+
/* Update channel in DS Parameter */
288+
uint8_t *payload = test_beacon_frame.payload;
289+
unsigned short pos = 12;
290+
291+
while ((pos + 2) < BEACON_PAYLOAD_LENGTH) {
292+
uint8_t tag = payload[pos];
293+
uint8_t length = payload[pos + 1];
294+
295+
if (tag == DS_PARAMETER_SET_ELEMENT_ID && length == DS_PARAMETER_SET_LENGTH) {
296+
payload[pos + 2] = channel;
297+
return;
298+
}
299+
300+
pos += 2 + length;
301+
if (pos >= BEACON_PAYLOAD_LENGTH) {
302+
break;
303+
}
304+
}
305+
}
306+
259307
static void fill_raw_tx_pkt_hdr(struct raw_tx_pkt_header *raw_tx_pkt)
260308
{
261309
/* Raw Tx Packet header */
@@ -313,6 +361,8 @@ static void wifi_send_raw_tx_packets(void)
313361
unsigned int buf_length, num_pkts, transmission_mode, num_failures = 0;
314362
unsigned short beacon_frame_length = calculate_beacon_frame_length(&test_beacon_frame);
315363

364+
update_beacon_channel();
365+
316366
ret = setup_raw_pkt_socket(&sockfd, &sa);
317367
if (ret < 0) {
318368
LOG_ERR("Setting socket for raw pkt transmission failed %d", errno);

0 commit comments

Comments
 (0)