コード例 #1
0
static void send_char( char c )
{
    wiced_result_t result;
    result = wiced_uart_transmit_bytes( cons.uart, &c, 1 );
    wiced_assert("", result == WICED_SUCCESS);
    REFERENCE_DEBUG_ONLY_VARIABLE( result );
}
コード例 #2
0
ファイル: platform_rtc.c プロジェクト: 119/bcm-wiced-sdk
static void reset_rtc_values( void )
{
    ErrorStatus status;

    /* Disable write protection of rtc registers */
    RTC_WriteProtectionCmd(DISABLE);
    status = RTC_EnterInitMode();
    REFERENCE_DEBUG_ONLY_VARIABLE(status);
    wiced_assert( "Rtc can not enter intialisation mode", status==SUCCESS );

    /* Reset calendar date registers */
    RTC->TR = 0;
    RTC_ExitInitMode();
    status = RTC_WaitForSynchro();
    wiced_assert( "Rtc can not synchronize", status==SUCCESS );

    /* Enable write protection of rtc registers */
    RTC_WriteProtectionCmd(ENABLE);

    /* Disable write protection of the rtc registers */
    RTC_WriteProtectionCmd(DISABLE);
    status = RTC_EnterInitMode();
    wiced_assert( "Rtc can not enter intialisation mode", status==SUCCESS );

    /* 2000 year 01/01 */
    RTC->DR= 0;
    RTC->DR= ( 1<<13 ) | ( 1<<8 ) | ( 1<<0 );
    RTC_ExitInitMode();
    status = RTC_WaitForSynchro();
    wiced_assert( "Rtc can not synchronize", status==SUCCESS );

    /* Enable write protection of rtc registers */
    RTC_WriteProtectionCmd(ENABLE);

}
コード例 #3
0
ファイル: wiced_rtos.c プロジェクト: humminglab/wiced-project
void application_thread_main( ULONG thread_input )
{
    UNUSED_PARAMETER( thread_input);

#ifndef WICED_DISABLE_WATCHDOG
    /* Start the watchdog kicking thread */
    wiced_rtos_create_thread( &system_monitor_thread_handle, RTOS_HIGHEST_PRIORITY, "system monitor", (wiced_thread_function_t)system_monitor_thread_main, SYSTEM_MONITOR_THREAD_STACK_SIZE, NULL );
#endif /* WICED_DISABLE_WATCHDOG */

#ifdef TX_ENABLE_EVENT_TRACE
    {
        wiced_result_t        result;
        wiced_tracex_config_t tracex_config;

        tracex_config.loop_rec = WICED_FALSE;
        tracex_config.filter = 0;
        tracex_config.tcp_server.enable = WICED_FALSE;
        tracex_config.tcp_server.port = WICED_TRACEX_TCP_SERVER_PORT;
        tracex_config.tcp_server.max_data_len = WICED_TRACEX_TCP_MAX_PACKET_LENGTH;
        tracex_config.tcp_server.timeout = WICED_TRACEX_TCP_CONNECT_TIMEOUT;
        tracex_config.tcp_server.num_retries = WICED_TRACEX_TCP_CONNECTION_NUM_RETRIES;
        SET_IPV4_ADDRESS(tracex_config.tcp_server.ip, WICED_TRACEX_TCP_SERVER_IP);
        tracex_config.buf.addr = WICED_TRACEX_BUFFER_ADDRESS;
        tracex_config.buf.size = WICED_TRACEX_BUFFER_SIZE;
        tracex_config.buf.obj_cnt = WICED_TRACEX_OBJECT_COUNT;

        result = wiced_tracex_enable(&tracex_config);
        wiced_assert( "TraceX enable failed", result == WICED_SUCCESS );
        REFERENCE_DEBUG_ONLY_VARIABLE( result );
    }
#endif /* TX_ENABLE_EVENT_TRACE */

    application_start( );
    malloc_leak_check(NULL, LEAK_CHECK_THREAD);
}
コード例 #4
0
static void send_charstr( const char* s )
{
    while ( *s != 0 )
    {
        wiced_result_t result;
        result = wiced_uart_transmit_bytes( cons.uart, s, 1 );
        wiced_assert("", result == WICED_SUCCESS );
        REFERENCE_DEBUG_ONLY_VARIABLE( result );
        s++;
    }
}
コード例 #5
0
static void send_str( const char* s )
{
    uint32_t length = strlen(s);
    if ( length > 0 )
    {
        wiced_result_t result;
        result = wiced_uart_transmit_bytes( cons.uart, s, length );
        wiced_assert("", result == WICED_SUCCESS);
        REFERENCE_DEBUG_ONLY_VARIABLE( result );
    }
}
コード例 #6
0
ファイル: wiced_p2p.c プロジェクト: 119/bcm-wiced-sdk
static void p2p_discover( p2p_workspace_t* workspace )
{
    wwd_result_t result;
    p2p_message_t  message;
    REFERENCE_DEBUG_ONLY_VARIABLE(result);

    if ( workspace->p2p_current_state == P2P_STATE_SCANNING )
    {
        workspace->p2p_current_state = P2P_STATE_DISCOVERING;
    }

    result = p2p_set_discovery_state( P2P_DISCOVERY_STATE_LISTEN );
    wiced_assert("", result == WWD_SUCCESS);

    while ( host_rtos_pop_from_queue( &p2p_outgoing_packet_queue, &message, 0 ) == WWD_SUCCESS )
    {
        result = wwd_sdpcm_send_iovar( SDPCM_SET, (wiced_buffer_t) message.data, NULL, WICED_STA_INTERFACE );
        wiced_assert("", result == WWD_SUCCESS);
    }
}
コード例 #7
0
ファイル: platform_rtc.c プロジェクト: cyysu/AliOS-Things
static void reset_rtc_values( void )
{
    ErrorStatus status;
    int retry = 3;

    /* Disable write protection of rtc registers */
    do{
      RTC_WriteProtectionCmd(DISABLE);
      status = RTC_EnterInitMode();
      REFERENCE_DEBUG_ONLY_VARIABLE(status);
      retry--;
    }while( retry && (status!=SUCCESS) );

    check_string( status==SUCCESS, "Rtc can not enter intialisation mode");  

    /* Reset calendar date registers */
    RTC->TR = 0;
    RTC_ExitInitMode();
    status = RTC_WaitForSynchro();
    check_string(  status==SUCCESS, "Rtc can not synchronize" );


    /* Enable write protection of rtc registers */
    RTC_WriteProtectionCmd(ENABLE);

    /* Disable write protection of the rtc registers */
    RTC_WriteProtectionCmd(DISABLE);
    status = RTC_EnterInitMode();
    check_string(  status==SUCCESS, "Rtc can not enter intialisation mode" );

    /* 2000 year 01/01 */
    RTC->DR= 0;
    RTC->DR= ( 1<<13 ) | ( 1<<8 ) | ( 1<<0 );
    RTC_ExitInitMode();
    status = RTC_WaitForSynchro();
    check_string(status==SUCCESS, "Rtc can not synchronize");

    /* Enable write protection of rtc registers */
    RTC_WriteProtectionCmd(ENABLE);
}
コード例 #8
0
ファイル: wwd_ap.c プロジェクト: humminglab/wiced-project
static void* wwd_handle_apsta_event( const wwd_event_header_t* event_header, const uint8_t* event_data, /*@returned@*/ void* handler_user_data )
{
    UNUSED_PARAMETER( event_header );
    UNUSED_PARAMETER( event_data );
    UNUSED_PARAMETER( handler_user_data );

    if ( (wwd_interface_t) event_header->interface != WWD_AP_INTERFACE)
    {
        return handler_user_data;
    }

    if ( ( ( event_header->event_type == (wwd_event_num_t) WLC_E_LINK ) &&
           ( event_header->interface == WWD_AP_INTERFACE ) ) ||
           ( event_header->event_type == WLC_E_IF ) )
    {
        wwd_result_t result;
        result = host_rtos_set_semaphore( &wwd_wifi_sleep_flag, WICED_FALSE );
        wiced_assert( "failed to post AP link semaphore", result == WWD_SUCCESS );
        REFERENCE_DEBUG_ONLY_VARIABLE( result );
    }
    return handler_user_data;
}
コード例 #9
0
ファイル: platform_rtc.c プロジェクト: 119/bcm-wiced-sdk
static platform_result_t stm32f2_rtc_change_clock( rtc_clock_state_t* current, rtc_clock_state_t target )
{
    uint8_t sync_div;
    uint8_t async_div;
    ErrorStatus status;

    /* Changing the synchronous and asynchronous prescalers according to the current clocking state and target_clock_state */
    /* of the RTC */
    if( *current == CLOCKING_EVERY_SEC )
    {
        if( target == CLOCKING_EVERY_1p25MSEC )
        {
            sync_div = 0;
            async_div= 40;

            /* Disable write protection of rtc registers, now we will be able to update RTC register values */
            RTC_WriteProtectionCmd(DISABLE);

            /* Enable initialisation mode */
            status = RTC_EnterInitMode();
            REFERENCE_DEBUG_ONLY_VARIABLE(status);
            wiced_assert( "Rtc can not enter intialisation mode", status==SUCCESS );

            /* Update RTC prescaler */
            RTC->PRER = (uint32_t)( sync_div );
            RTC->PRER |= (uint32_t)(async_div << 16);
            RTC_ExitInitMode();

            /* Enable write proteciton of rtc registers back */
            RTC_WriteProtectionCmd(ENABLE);
            *current = CLOCKING_EVERY_1p25MSEC;
            return PLATFORM_SUCCESS;
        }
        else
        {
            return PLATFORM_SUCCESS;
        }
    }
    else if( *current == CLOCKING_EVERY_1p25MSEC )
    {
        if( target == CLOCKING_EVERY_SEC )
        {
            /* We will get approximately 800Hz clock, 1 tick will correspond to 1.25ms(0,00125s), by addind 8 together we will get 1ms  */
            /* the closest division factor which is 40.96( 32768/800 ), we will take 41, the error will be very very tiny */
            async_div = 127;
            sync_div = 255;

            /* Disable write protection of rtc registers */
            RTC_WriteProtectionCmd(DISABLE);

            /* Enable initialisation mode */
            status = RTC_EnterInitMode();
            wiced_assert( "Rtc can not enter intialisation mode", status==SUCCESS );

            /* Update RTC prescaler */
            RTC->PRER = (uint32_t)( sync_div );
            RTC->PRER |= (uint32_t)(async_div << 16);

            RTC_ExitInitMode();

            /* Enable write proteciton of rtc registers back */
            RTC_WriteProtectionCmd(ENABLE);
            *current = CLOCKING_EVERY_SEC;
            return PLATFORM_SUCCESS;
        }
        else
        {
            return PLATFORM_SUCCESS;
        }
    }
    return PLATFORM_SUCCESS;
}
コード例 #10
0
ファイル: MICOEntrance.c プロジェクト: brucehelen/MICO
int application_start(void)
{
  OSStatus err = kNoErr;
  IPStatusTypedef para;
  struct tm currentTime;
  mico_rtc_time_t time;
 
  /*Read current configurations*/
  context = ( mico_Context_t *)malloc(sizeof(mico_Context_t) );
  require_action( context, exit, err = kNoMemoryErr );
  memset(context, 0x0, sizeof(mico_Context_t));
  mico_rtos_init_mutex(&context->flashContentInRam_mutex);
  mico_rtos_init_semaphore(&context->micoStatus.sys_state_change_sem, 1); 

  MICOReadConfiguration( context );

  err = MICOInitNotificationCenter  ( context );

  err = MICOAddNotification( mico_notify_READ_APP_INFO, (void *)micoNotify_ReadAppInfoHandler );
  require_noerr( err, exit );  

  err = MICOAddNotification( mico_notify_WIFI_CONNECT_FAILED, (void *)micoNotify_ConnectFailedHandler );
  require_noerr( err, exit ); 

  err = MICOAddNotification( mico_notify_WIFI_Fatal_ERROR, (void *)micoNotify_WlanFatalErrHandler );
  require_noerr( err, exit ); 

  err = MICOAddNotification( mico_notify_Stack_Overflow_ERROR, (void *)micoNotify_StackOverflowErrHandler );
  require_noerr( err, exit ); 

  /*wlan driver and tcpip init*/
  MicoInit();
  MicoSysLed(true);

  /* Enter test mode, call a build-in test function amd output on STDIO */
  if(MicoShouldEnterMFGMode()==true)
    mico_mfg_test();

  /*Read current time from RTC.*/
  MicoRtcGetTime(&time);
  currentTime.tm_sec = time.sec;
  currentTime.tm_min = time.min;
  currentTime.tm_hour = time.hr;
  currentTime.tm_mday = time.date;
  currentTime.tm_wday = time.weekday;
  currentTime.tm_mon = time.month - 1;
  currentTime.tm_year = time.year + 100;
  mico_log("Current Time: %s",asctime(&currentTime));

  micoWlanGetIPStatus(&para, Station);
  formatMACAddr(context->micoStatus.mac, (char *)&para.mac);
  
  mico_log_trace(); 
  mico_log("%s mxchipWNet library version: %s", APP_INFO, MicoGetVer());

  /*Start system monotor thread*/
  err = MICOStartSystemMonitor(context);
  require_noerr_action( err, exit, mico_log("ERROR: Unable to start the system monitor.") );

  err = MICORegisterSystemMonitor(&mico_monitor, APPLICATION_WATCHDOG_TIMEOUT_SECONDS*1000);
  require_noerr( err, exit );
  mico_init_timer(&_watchdog_reload_timer,APPLICATION_WATCHDOG_TIMEOUT_SECONDS*1000 - 100, _watchdog_reload_timer_handler, NULL);
  mico_start_timer(&_watchdog_reload_timer);
  
  if(context->flashContentInRam.micoSystemConfig.configured != allConfigured){
    mico_log("Empty configuration. Starting configuration mode...");

#if defined (CONFIG_MODE_EASYLINK) || defined (CONFIG_MODE_EASYLINK_WITH_SOFTAP) || defined (CONFIG_MODE_EASYLINK_PLUS)
  err = startEasyLink( context );
  require_noerr( err, exit );
#endif

#if defined (CONFIG_MODE_WPS) || defined (CONFIG_MODE_WPS_WITH_SOFTAP)
  err = startWPS( context );
  require_noerr( err, exit );
#endif

#ifdef CONFIG_MODE_WAC
  WACPlatformParameters_t* WAC_Params = NULL;
  WAC_Params = calloc(1, sizeof(WACPlatformParameters_t));
  require(WAC_Params, exit);

  str2hex((unsigned char *)para.mac, WAC_Params->macAddress, 6);
  WAC_Params->isUnconfigured          = 1;
  WAC_Params->supportsAirPlay         = 0;
  WAC_Params->supportsAirPrint        = 0;
  WAC_Params->supports2_4GHzWiFi      = 1;
  WAC_Params->supports5GHzWiFi        = 0;
  WAC_Params->supportsWakeOnWireless  = 0;

  WAC_Params->firmwareRevision =  FIRMWARE_REVISION;
  WAC_Params->hardwareRevision =  HARDWARE_REVISION;
  WAC_Params->serialNumber =      SERIAL_NUMBER;
  WAC_Params->name =              context->flashContentInRam.micoSystemConfig.name;
  WAC_Params->model =             MODEL;
  WAC_Params->manufacturer =      MANUFACTURER;

  WAC_Params->numEAProtocols =    1;
  WAC_Params->eaBundleSeedID =    BUNDLE_SEED_ID;
  WAC_Params->eaProtocols =       (char **)eaProtocols;;

  err = startMFiWAC( context, WAC_Params, 1200);
  free(WAC_Params);
  require_noerr( err, exit );
#endif
  }
  else{
    mico_log("Available configuration. Starting Wi-Fi connection...");
    
    /* Regisist notifications */
    err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)micoNotify_WifiStatusHandler );
    require_noerr( err, exit ); 
    
    err = MICOAddNotification( mico_notify_WiFI_PARA_CHANGED, (void *)micoNotify_WiFIParaChangedHandler );
    require_noerr( err, exit ); 

    err = MICOAddNotification( mico_notify_DHCP_COMPLETED, (void *)micoNotify_DHCPCompleteHandler );
    require_noerr( err, exit );  
   
    if(context->flashContentInRam.micoSystemConfig.rfPowerSaveEnable == true){
      micoWlanEnablePowerSave();
    }

    if(context->flashContentInRam.micoSystemConfig.mcuPowerSaveEnable == true){
      MicoMcuPowerSaveConfig(true);
    }

    /*Local configuration server*/
    if(context->flashContentInRam.micoSystemConfig.configServerEnable == true){
      err =  MICOStartConfigServer(context);
      require_noerr_action( err, exit, mico_log("ERROR: Unable to start the local server thread.") );
    }

    err =  MICOStartNTPClient(context);
    require_noerr_action( err, exit, mico_log("ERROR: Unable to start the NTP client thread.") );

    /*Start mico application*/
    err = MICOStartApplication( context );
    require_noerr( err, exit );

    _ConnectToAP( context );
  }

  int free_memory;
  free_memory = MicoGetMemoryInfo()->free_memory;
  REFERENCE_DEBUG_ONLY_VARIABLE(free_memory);
  mico_log("Free memory %d bytes", free_memory) ; 
  
  /*System status changed*/
  while(mico_rtos_get_semaphore(&context->micoStatus.sys_state_change_sem, MICO_WAIT_FOREVER)==kNoErr){
    switch(context->micoStatus.sys_state){
      case eState_Normal:
        break;
      case eState_Software_Reset:
        sendNotifySYSWillPowerOff();
        mico_thread_msleep(500);
        MicoSystemReboot();
        break;
      case eState_Wlan_Powerdown:
        sendNotifySYSWillPowerOff();
        mico_thread_msleep(500);
        micoWlanPowerOff();
        break;
      case eState_Standby:
        mico_log("Enter standby mode");
        sendNotifySYSWillPowerOff();
        mico_thread_msleep(200);
        micoWlanPowerOff();
        MicoSystemStandBy(MICO_WAIT_FOREVER);
        break;
      default:
        break;
    }
  }
    
  require_noerr_action( err, exit, mico_log("Closing main thread with err num: %d.", err) );

exit:
  mico_rtos_delete_thread(NULL);
  return kNoErr;
}
コード例 #11
0
ファイル: wiced_p2p.c プロジェクト: 119/bcm-wiced-sdk
void besl_p2p_test( p2p_workspace_t* workspace )
{
    wiced_buffer_t buffer;
    wiced_result_t result;
    uint32_t* data;
    wiced_mac_t my_mac;

    REFERENCE_DEBUG_ONLY_VARIABLE(result);

    wiced_wifi_get_mac_address( &my_mac );
    my_mac.octet[0] |= 0x2;

    wl_p2p_if_t* p2p_if = wwd_sdpcm_get_iovar_buffer( &buffer, sizeof(wl_p2p_if_t), IOVAR_STR_P2P_IFADD );
    p2p_if->interface_type = P2P_GROUP_OWNER_MODE;
    memcpy( &p2p_if->mac_address, &my_mac, sizeof(besl_mac_t) );
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS);

    /*  Enable discovery */
    data = wwd_sdpcm_get_iovar_buffer( &buffer, 4, IOVAR_STR_P2P_DISC );
    *data = 1;
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS);

    wiced_buffer_t response;
    wwd_sdpcm_get_iovar_buffer( &buffer, 4, IOVAR_STR_P2P_DEV );
    result = wwd_sdpcm_send_iovar( SDPCM_GET, buffer, &response, WICED_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS);
    workspace->p2p_interface = BESL_READ_32(host_buffer_get_current_piece_data_pointer(response));
    host_buffer_release( response, WICED_NETWORK_RX );
    BESL_DEBUG( ("interface = %lu\n", workspace->p2p_interface) );

    data = wiced_get_ioctl_buffer( &buffer, 4 );
    *data = 1;
    result = wiced_send_ioctl( SDPCM_SET, WLC_SET_CHANNEL, buffer, NULL, workspace->p2p_interface );
    wiced_assert("", result == WICED_SUCCESS);

    /*  Set WSEC */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 8, IOVAR_STR_BSSCFG_WSEC );
    data[0] = (uint32_t) workspace->p2p_interface;
    data[1] = WICED_SECURITY_WPA2_AES_PSK;
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, SDPCM_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS);

    wsec_pmk_t* psk;

    /* Set the wpa auth */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 8, IOVAR_STR_BSSCFG_WPA_AUTH );
    data[0] = (uint32_t) workspace->p2p_interface;
    data[1] = (uint32_t) WPA2_AUTH_PSK;
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, SDPCM_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS );

    /* Set the passphrase */
    psk = (wsec_pmk_t*) wiced_get_ioctl_buffer( &buffer, sizeof(wsec_pmk_t) );
    memcpy( psk->key, "YOUR_AP_PASSPHRASE", 18 );
    psk->key_len = 18;
    psk->flags = (uint16_t) WSEC_PASSPHRASE;
    host_rtos_delay_milliseconds( 1 ); /*  Delay required to allow radio firmware to be ready to receive PMK and avoid intermittent failure */
    result = wiced_send_ioctl( SDPCM_SET, WLC_SET_WSEC_PMK, buffer, 0, workspace->p2p_interface );
    wiced_assert("", result == WICED_SUCCESS );

    wlc_ssid_t* p2p_ssid = wwd_sdpcm_get_iovar_buffer( &buffer, sizeof(wl_p2p_if_t), IOVAR_STR_P2P_SSID );
    p2p_ssid->SSID_len = 9;
    memcpy( p2p_ssid->SSID, "DIRECT-ww", 9 );
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS);

    /* Bring up P2P interface */
    wiced_get_ioctl_buffer( &buffer, 0 );
    result = wiced_send_ioctl( SDPCM_SET, WLC_UP, buffer, NULL, workspace->p2p_interface );
    wiced_assert("", result == WICED_SUCCESS);

    p2p_set_discovery_state( P2P_DISCOVERY_STATE_LISTEN );
}
コード例 #12
0
ファイル: wiced_p2p.c プロジェクト: 119/bcm-wiced-sdk
static besl_result_t p2p_run_as_go( p2p_workspace_t* workspace, wps_agent_t* wps_registrar )
{
    uint32_t*             data;
    wwd_result_t          result;
    besl_wps_credential_t credential;
    wiced_buffer_t        buffer;
    uint8_t               passphrase_buffer[32];
    uint8_t               a;

    REFERENCE_DEBUG_ONLY_VARIABLE(result);

    host_rtos_delay_milliseconds( 500 );

    /* Limit the rates used on the P2P soft AP */
    data    = wwd_sdpcm_get_iovar_buffer( &buffer, 4, IOVAR_STR_BSS_RATESET );
    data[0] = 1;
    result  = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WICED_AP_INTERFACE );
    wiced_assert("", result == WWD_SUCCESS);

    /* Prepare the AP credentials */
    credential.security = WICED_SECURITY_WPA2_AES_PSK;
    credential.ssid.length = workspace->group_candidate.ssid.length;
    memcpy( credential.ssid.value, workspace->group_candidate.ssid.value, credential.ssid.length );
    credential.passphrase_length = 64;
    besl_host_random_bytes(passphrase_buffer, 32);
    for ( a = 0; a < 32; ++a )
    {
        credential.passphrase[2*a]     = nibble_to_hexchar(passphrase_buffer[a] >> 4);
        credential.passphrase[2*a + 1] = nibble_to_hexchar(passphrase_buffer[a] & 0x0F);
    }

    /* Start the AP */
    wwd_wifi_start_ap( &workspace->group_candidate.ssid, WICED_SECURITY_WPA2_AES_PSK | WPS_ENABLED, credential.passphrase, credential.passphrase_length, 1 );

    workspace->p2p_interface = WICED_AP_INTERFACE;
    memcpy( &workspace->device_info.mac_address, &workspace->intended_mac_address, sizeof(besl_mac_t) );

    wl_p2p_if_t* p2p_if = wwd_sdpcm_get_iovar_buffer( &buffer, sizeof(wl_p2p_if_t), IOVAR_STR_P2P_IFUPD );
    p2p_if->interface_type = P2P_GROUP_OWNER_MODE;
    memcpy( &p2p_if->mac_address, &workspace->intended_mac_address, sizeof(besl_mac_t) );
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE );
    wiced_assert("", result == WWD_SUCCESS);

    p2p_write_probe_response_ie( workspace );
    p2p_write_beacon_ie( workspace );

    /* Bring up IP layer on AP interface */
    wiced_ip_up( WICED_AP_INTERFACE, WICED_USE_INTERNAL_DHCP_SERVER, &p2p_ip_settings );

    besl_wps_init( wps_registrar, workspace->wps_device_details, WPS_REGISTRAR_AGENT, WICED_AP_INTERFACE );

    /* Init WPS */
    wps_internal_init( wps_registrar, WICED_AP_INTERFACE, WPS_PBC_MODE, "00000000", &credential, 1 );

    /* Run WPS state machine in P2P thread */
    wiced_wps_thread_main( (uint32_t) wps_registrar );

    if ( wps_registrar->wps_result == WPS_COMPLETE )
    {
        workspace->p2p_result = BESL_SUCCESS;
    }
    else
    {
        workspace->p2p_result = wps_registrar->wps_result;
    }

    return BESL_SUCCESS;
}
コード例 #13
0
ファイル: wiced_p2p.c プロジェクト: 119/bcm-wiced-sdk
besl_result_t besl_p2p_init( p2p_workspace_t* workspace, const besl_p2p_device_detail_t* device_details )
{
    wiced_buffer_t buffer;
    wiced_buffer_t response;
    uint32_t*      data;
    wwd_result_t result;
    REFERENCE_DEBUG_ONLY_VARIABLE(result);

    memset(workspace, 0, sizeof(p2p_workspace_t));

    workspace->p2p_capability = 0x0000;
    workspace->p2p_name       = device_details->device_name;
    workspace->group_owner_intent = 1;

    /* Turn off all the other Wi-Fi interfaces */
    wiced_network_down(WICED_STA_INTERFACE);
    wiced_network_down(WICED_AP_INTERFACE);

    /* Query the AP interface to ensure that it is up */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 36, IOVAR_STR_BSSCFG_SSID );
    memset(data, 0, 36);
    data[0] = (uint32_t) CHIP_AP_INTERFACE;
    wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WWD_STA_INTERFACE );

    /*  Enable discovery */
    data = wwd_sdpcm_get_iovar_buffer(&buffer, 4, IOVAR_STR_P2P_DISC );
    *data = 1;
    result = wwd_sdpcm_send_iovar(SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE);
    wiced_assert("", result == WWD_SUCCESS);

    /*  Find what interface is the P2P device */
    wwd_sdpcm_get_iovar_buffer(&buffer, 4, IOVAR_STR_P2P_DEV );
    result = wwd_sdpcm_send_iovar(SDPCM_GET, buffer, &response, WICED_STA_INTERFACE);
    wiced_assert("", result == WWD_SUCCESS);
    workspace->p2p_interface = BESL_READ_32(host_buffer_get_current_piece_data_pointer(response));
    host_buffer_release(response, WWD_NETWORK_RX);

    /* Get the P2P interface MAC address */
    besl_host_get_mac_address(&workspace->device_info.mac_address, workspace->p2p_interface);

    /* Set the standard interface MAC address to be the same as the P2P interface */
    besl_host_set_mac_address(&workspace->device_info.mac_address, WICED_STA_INTERFACE);
    besl_host_set_mac_address(&workspace->device_info.mac_address, WICED_AP_INTERFACE);

    /* Get the standard MAC address to confirm */
    besl_host_get_mac_address(&workspace->intended_mac_address, WICED_STA_INTERFACE);

    BESL_INFO( ("STA MAC: %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", workspace->intended_mac_address.octet[0],
        workspace->intended_mac_address.octet[1],
        workspace->intended_mac_address.octet[2],
        workspace->intended_mac_address.octet[3],
        workspace->intended_mac_address.octet[4],
        workspace->intended_mac_address.octet[5]) );


    /* Set the device details */
    workspace->wps_device_details = &device_details->wps_device_details;

    /* Allow the P2P library to initialize */
    p2p_init(workspace, workspace->p2p_name);

    /* Bring up P2P interface */
    wwd_sdpcm_get_ioctl_buffer( &buffer, 0 );
    result = wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_UP, buffer, NULL, workspace->p2p_interface);
    wiced_assert("", result == WWD_SUCCESS);

    /* Set wsec to any non-zero value in the discovery bsscfg to ensure our P2P probe responses have the privacy bit set in the 802.11 WPA IE.
     * Some peer devices may not initiate WPS with us if this bit is not set. */
    data = wwd_sdpcm_get_iovar_buffer(&buffer, 8, IOVAR_STR_BSSCFG_WSEC );
    data[0] = workspace->p2p_interface;
    data[1] = WICED_SECURITY_WPA2_AES_PSK;
    result = wwd_sdpcm_send_iovar(SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE);
    wiced_assert("", result == WWD_SUCCESS);

    workspace->p2p_current_state = P2P_STATE_DISCOVERING;

    /*  Add P2P event handler */
    result = wwd_management_set_event_handler( p2p_events, p2p_event_handler, workspace, workspace->p2p_interface );
    wiced_assert("", result == WWD_SUCCESS);

    /* Create the message queue */
    host_rtos_init_queue(&p2p_message_queue, p2p_message_queue_buffer, sizeof(p2p_message_queue_buffer), sizeof(p2p_message_t));

    /* Create the pending outgoing packet queue */
    host_rtos_init_queue(&p2p_outgoing_packet_queue, p2p_outgoing_packet_queue_buffer, sizeof(p2p_outgoing_packet_queue_buffer), sizeof(p2p_message_t));

    /* Create the P2P thread */
    host_rtos_create_thread_with_arg( &p2p_thread, p2p_thread_main, "p2p", p2p_thread_stack, sizeof(p2p_thread_stack), RTOS_HIGHER_PRIORTIY_THAN(RTOS_DEFAULT_THREAD_PRIORITY), (uint32_t)workspace );

    return BESL_SUCCESS;
}