@@ -25,7 +25,10 @@ LOG_MODULE_REGISTER(raw_tx_packet, CONFIG_LOG_DEFAULT_LEVEL);
25
25
#include "wifi_connection.h"
26
26
27
27
#define BEACON_PAYLOAD_LENGTH 256
28
+ #define DEFAULT_RAW_TX_WIFI_CHANNEL 6
28
29
#define PADDING_ZERO_THRESHOLD 10
30
+ #define DS_PARAMETER_SET_ELEMENT_ID 3
31
+ #define DS_PARAMETER_SET_LENGTH 1
29
32
#define CONTINUOUS_MODE_TRANSMISSION 0
30
33
#define FIXED_MODE_TRANSMISSION 1
31
34
@@ -256,6 +259,51 @@ static unsigned short calculate_beacon_frame_length(const struct beacon *beacon_
256
259
return header_length + payload_length ;
257
260
}
258
261
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
+
259
307
static void fill_raw_tx_pkt_hdr (struct raw_tx_pkt_header * raw_tx_pkt )
260
308
{
261
309
/* Raw Tx Packet header */
@@ -313,6 +361,8 @@ static void wifi_send_raw_tx_packets(void)
313
361
unsigned int buf_length , num_pkts , transmission_mode , num_failures = 0 ;
314
362
unsigned short beacon_frame_length = calculate_beacon_frame_length (& test_beacon_frame );
315
363
364
+ update_beacon_channel ();
365
+
316
366
ret = setup_raw_pkt_socket (& sockfd , & sa );
317
367
if (ret < 0 ) {
318
368
LOG_ERR ("Setting socket for raw pkt transmission failed %d" , errno );
0 commit comments