Sniffer模式下不能接收到任何数据

zhjxy
Posts: 11
Joined: Fri Jan 08, 2016 1:52 pm

Sniffer模式下不能接收到任何数据

Postby zhjxy » Mon Sep 12, 2016 8:17 pm

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

Code: Select all

/*
 * ESPRSSIF MIT License
 *
 * Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
 *
 * 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:%s\n", 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:%s\n", 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!\n\n");
}


Who is online

Users browsing this forum: No registered users and 56 guests