乐鑫技术交流
直播中

张桂英

8年用户 1604经验值
私信 关注
[问答]

RTOS V1.4.2 Sniffer模式下不能接收到任何数据是怎么回事?

测试平台RTOS V1.4.2
测试现象:wifi_set_promiscuous_rx_cb注册的回调并没有调用,PC一直向6信道发送数据
使用:主要是使用Sniffer模式简单评估信道的利用率
代码如下:

/*
* ESPRSSIF MIT License
*
* Copyright (c) 2015
*
* Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/

#include "esp_common.h"
#include "user_config.h"
#include "uart.h"

static void promisc_cb(uint8 *buf, uint16 len);
#define printmac(buf, i) printf("t%02X:%02X:%02X:%02X:%02X:%02X", buf[i+0], buf[i+1], buf[i+2],
                                                   buf[i+3], buf[i+4], buf[i+5])
                                       
/******************************************************************************
* FunctionName : user_rf_cal_sector_set
* Description  : SDK just reversed 4 sectors, used for rf init data and paramters.
*                We add this function to force users to set rf cal sector, since
*                we don't know which sector is free in user's application.
*                sector map for last several sectors : ABCCC
*                A : rf cal
*                B : rf init data
*                C : sdk parameters
* Parameters   : none
* Returns      : rf cal sector
*******************************************************************************/
uint32 user_rf_cal_sector_set(void)
{
    flash_size_map size_map = system_get_flash_size_map();
    uint32 rf_cal_sec = 0;

    switch (size_map) {
        case FLASH_SIZE_4M_MAP_256_256:
            rf_cal_sec = 128 - 5;
            break;

        case FLASH_SIZE_8M_MAP_512_512:
            rf_cal_sec = 256 - 5;
            break;

        case FLASH_SIZE_16M_MAP_512_512:
        case FLASH_SIZE_16M_MAP_1024_1024:
            rf_cal_sec = 512 - 5;
            break;

        case FLASH_SIZE_32M_MAP_512_512:
        case FLASH_SIZE_32M_MAP_1024_1024:
            rf_cal_sec = 1024 - 5;
            break;

        default:
            rf_cal_sec = 0;
            break;
    }

    return rf_cal_sec;
}


void test_task(void *pvParameters)
{
   
   while(1)
   {
      //printf("SDK version:%sn", system_get_sdk_version());
      vTaskDelay(500);
      /*uint8 new_channel = wifi_get_channel() % 12 + 1;
      printf("** hop to %d **n", new_channel);
      wifi_set_channel(new_channel);*/
      printf("** channel : %d **n", wifi_get_channel());
      
   }
}

static void promisc_cb(uint8 *buf, uint16 len)
{
    printf("-> %3d: %d", wifi_get_channel(), len);
    //printmac(buf,  4);
    //printmac(buf, 10);
    //printmac(buf, 16);
    printf("n");
}

/******************************************************************************
* FunctionName : user_init
* Description  : entry of user application, init user function here
* Parameters   : none
* Returns      : none
*******************************************************************************/
void user_init(void)
{
   wifi_station_set_auto_connect(0);
   //uart_init_new();
    printf("SDK version:%sn", system_get_sdk_version());
   //os_delay_us(100);
   
   // Promiscuous works only with station mode
   printf(" -> Set opmode ... ");
    wifi_set_opmode( 0x1 );//1---STATION_MODE
    printf("done.n");
   
   // Set up promiscuous callback
   wifi_set_channel(6);
   //wifi_promiscuous_enable(0);
   printf(" -> Promisc mode setup ... ");
    wifi_set_promiscuous_rx_cb(promisc_cb);
    wifi_promiscuous_enable(1);
    printf("done.n");
      
   xTaskCreate(test_task, "test_task", 512, NULL, 3, NULL);
   
   printf(" -> Init finished!nn");
}


回帖(1)

杨海清

2024-7-12 18:02:16
在RTOS V1.4.2的Sniffer模式下无法接收到数据,可能是由以下几个原因导致的:

1. 确保您的ESP8266模块支持Sniffer模式。并非所有ESP8266模块都支持此功能。

2. 检查您的代码是否正确配置了Sniffer模式。以下是配置Sniffer模式的示例代码:

```c
#include "esp_common.h"
#include "esp_wifi.h"

void ICACHE_FLASH_ATTR
wifi_set_promiscuous_rx_cb(void *cb)
{
    system_os_task(wifi_promiscuous_packet_handler, cb, 1);
}

void ICACHE_FLASH_ATTR
wifi_promiscuous_packet_handler(void *arg)
{
    struct rx_info *info = (struct rx_info *)arg;
    // 处理接收到的数据包
}
```

3. 确保您已正确注册了回调函数。使用`wifi_set_promiscuous_rx_cb`函数注册回调函数,如下所示:

```c
void user_init(void)
{
    // 初始化WiFi
    wifi_set_opmode(STATION_MODE);
    wifi_set_promiscuous_rx_cb(&wifi_promiscuous_packet_handler);
}
```

4. 检查您的PC是否在正确的信道上发送数据。确保您的PC和ESP8266模块都设置为相同的信道(在您的例子中是信道6)。

5. 确保您的ESP8266模块的固件版本与您的代码兼容。如果您使用的是RTOS V1.4.2,请确保您的固件版本也是1.4.2或兼容的版本。


举报

更多回帖

发帖
×
20
完善资料,
赚取积分