/* This is an entry point for the application. All application specific initialization is performed here. */ int main(void) { int ret = 0; /* Initializes console on UART0 */ ret = wmstdio_init(UART0_ID, 0); if (ret == -WM_FAIL) { wmprintf("Failed to initialize console on uart0\r\n"); return -1; } wmprintf(" LED demo application started\r\n"); wmprintf(" This application demonstrates the" " use of blinking led\r\n"); gpio_led = (board_led_2()).gpio; wmprintf(" LED Pin : %d\r\n", gpio_led); configure_gpios(); while (1) { gpio_led_on(); os_thread_sleep(os_msec_to_ticks(1000)); gpio_led_off(); os_thread_sleep(os_msec_to_ticks(1000)); } return 0; }
static void prvBlinkLedTask( void *pvParameters ) { while (1) { gpio_led_on(); vTaskDelay(os_msec_to_ticks(1000)); gpio_led_off(); vTaskDelay(os_msec_to_ticks(1000)); } }
void miio_app_thread(void* arg) { static bool has_sync_time = false; g_mum = mum_create(); //*****************************button init*******************************/ os_timer_create(&g_reset_prov_timer, "reset-prov-timer", os_msec_to_ticks(4000), reset_prov, NULL, OS_TIMER_ONE_SHOT, OS_TIMER_NO_ACTIVATE); button_frame_work_init(); register_button_callback(0, button_1_press_handle); if (WM_SUCCESS != os_semaphore_create(&btn_pressed_sem, "btn_pressed_sem")) { LOG_ERROR("btn_pressed_sem creation failed\r\n"); } else if (WM_SUCCESS != os_semaphore_get(&btn_pressed_sem, OS_WAIT_FOREVER)) { LOG_ERROR("first get btn_pressed_sem failed.\r\n"); } //******************************button init end*******************************************/ local_timer_init();//add by [email protected] miio_led_on(); LOG_INFO("miio_app_thread while loop start.\r\n"); #ifdef MIIO_COMMANDS_DEBUG while(!ot_api_is_online())api_os_tick_sleep(100); uart_wifi_debug_init(); #endif while (1) { if (WM_SUCCESS == os_semaphore_get(&btn_pressed_sem, OS_NO_WAIT)) { mum_set_property(g_mum,"button_pressed","\"wifi_rst\""); } if(has_sync_time)//only after sync time, we start check timer check_schedule_and_set_timer(); else if(otn_is_online()) has_sync_time = true; os_thread_sleep(os_msec_to_ticks(PERIOD_CHECK_BUTTON)); } local_timer_deinit();//add by [email protected] //*****************************button deinit*******************************/ mum_destroy(&g_mum); os_timer_delete(&g_reset_prov_timer); os_semaphore_delete(&btn_pressed_sem); //******************************button deinit end*******************************************/ }
/* Write data from SSP master after every 100msec */ static void ssp_master_write(os_thread_arg_t data) { int len, i, j; wmprintf("SSP Writer Application Started\r\n"); i = 0; while (1) { i++; /* Write random number of random bytes */ len = rand() % BUF_LEN; for (j = 0; j < len; j++) write_data[j] = rand(); /* Write data on SSP bus */ len = ssp_drv_write(ssp, write_data, NULL, len, 0); wmprintf("Write iteration %d: data_len = %d\n\r", i, len); for (j = 0; j < len ; j++) { if ((j % 16) == 0) wmprintf("\n\r"); wmprintf("%02x ", write_data[j]); } if (len) wmprintf("\n\r\n\r"); os_thread_sleep(os_msec_to_ticks(100)); } }
void led_blink(int led_no, int on_duty_cycle, int off_duty_cycle) { int err, idx; idx = decide_led_array_index(led_no); if (idx == -WM_FAIL) return; if (os_timer_is_active(&led_data[idx].timer) == WM_SUCCESS) { err = os_timer_delete(&led_data[idx].timer); if (err != WM_SUCCESS) { return; } } led_data[idx].on_duty_cycle = on_duty_cycle; led_data[idx].off_duty_cycle = off_duty_cycle; board_led_on(led_no); led_data[idx].curr_state = LED_ON; err = os_timer_create(&led_data[idx].timer, "led-timer", os_msec_to_ticks(led_data[idx].on_duty_cycle), led_cb, (void *)idx, OS_TIMER_ONE_SHOT, OS_TIMER_AUTO_ACTIVATE); if (err != WM_SUCCESS) { return; } }
void mc_usb_fin() { usb_exit++; os_thread_sleep(os_msec_to_ticks(USB_READ_TIMEOUT)); /* wait for the thread to termiante */ /* no API to deactivate USB! at least the thread has to be stopped... */ }
static void dhcp_cli(int argc, char **argv) { void *intrfc_handle = NULL; int wait_for_sec = WAIT_FOR_UAP_START; if (argc >= 3 && string_equal(argv[2], "start")) { if (!strncmp(argv[1], "mlan0", 5)) intrfc_handle = net_get_mlan_handle(); else if (!strncmp(argv[1], "uap0", 4)) { while(wait_for_sec) { wait_for_sec--; if (!is_uap_started()) { if (wait_for_sec == 0) { dhcp_e("unable" " to start DHCP server. Retry" " after uAP is started"); return; } } else break; os_thread_sleep(os_msec_to_ticks(1000)); } intrfc_handle = net_get_uap_handle(); } if (dhcp_server_start(intrfc_handle)) dhcp_e("unable to " "start DHCP server"); } else if (argc >= 3 && string_equal(argv[2], "stop")) dhcp_server_stop(); else { wmprintf("Usage: %s %s\r\n", DHCPS_COMMAND, DHCPS_HELP); wmprintf("Error: invalid argument\r\n"); } }
static int i2c_write_bytes(wm_i2c *i2c, int reg, uint8_t *data, int datasize) { int retry = 60; int i; do { if (reg >= 0) { if (!i2c_write_byte(i2c, reg)) return false; } for (i = 0; i < datasize; i++) if (!i2c_write_byte(i2c, data[i])) return false; if (!(i2c->reg->RAW_INTR_STAT.WORDVAL & 0x40 /* TX ABRT */)) break; os_thread_sleep(os_msec_to_ticks(10)); #if I2C_VERBOSE > 1 mc_log_debug("I2C: xmit aborted [%d]: cause = 0x%x.\n", retry, i2c_get_abort_cause(i2c)); #endif i2c_clear_abort(i2c); } while (--retry >= 0); #if I2C_VERBOSE if (retry < 0) mc_log_debug("I2C: xmit aborted!\n"); #endif return (retry >= 0); }
static inline int i2c_timeout(wm_i2c *i2c, uint32_t tout) { uint32_t t = os_ticks_get(); uint32_t tt = os_msec_to_ticks(tout); return tout != 0 && (t >= i2c->sticks ? (t - i2c->sticks) : ((UINT_MAX - i2c->sticks) + t)) >= tt; }
static void __write_to_lcd(mdev_t *dev, const char *line1, const char *line2) { mdev_t *i2c_dev; int temp; memset(lcd_buff, 0, sizeof(lcd_buff)); os_thread_sleep(os_msec_to_ticks(35)); i2c_dev = i2c_drv_open(dev->private_data, I2C_SLAVEADR(I2C_LCD_ADDR >> 1)); if (i2c_dev == NULL) { lcd_d("I2C driver init is required before open"); return; } lcd_buff[0] = LCD_CMD_CONFIG_MODE; /* Set DDRAM Address to line 1 * Bits: 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0 * AC6-0: The address to be written to: * 00H: line 1 * 40H: line 2 */ lcd_buff[1] = 0x80; lcd_buff[2] = 0x06; /* Entry mode as mentioned above */ os_thread_sleep(os_msec_to_ticks(35)); temp = os_enter_critical_section(); i2c_drv_write(i2c_dev, (uint8_t *) lcd_buff, 2); os_exit_critical_section(temp); /* Write data */ lcd_buff[0] = LCD_CMD_DATA_MODE; if (line1) write_line1(lcd_buff, line1); if (line2) write_line2(lcd_buff, line2); os_thread_sleep(os_msec_to_ticks(35)); temp = os_enter_critical_section(); i2c_drv_write(i2c_dev, (uint8_t *) lcd_buff, end_of_line2(lcd_buff)); os_exit_critical_section(temp); i2c_drv_close(i2c_dev); }
void miio_app_test_thread(void* arg) { /*if(STATE_OK == sell_ready()){ LOG_INFO("==================\r\n"); LOG_INFO(" OK. Sell ready. \r\n"); LOG_INFO("==================\r\n"); }*/ while (1) { os_thread_sleep(os_msec_to_ticks(500)); } }
static int i2c_wait_tx_fifo(wm_i2c *i2c) { int tcnt; uint32_t toticks = os_msec_to_ticks(10); /* sending the stop sequence by emptying the TX FIFO */ for (tcnt = 10; !(i2c->reg->STATUS.WORDVAL & 0x04 /* TFE */) && --tcnt >= 0;) os_thread_sleep(toticks); #if I2C_VERBOSE if (tcnt < 0) mc_log_debug("I2C: TX FIFO can't be empty! STATUS = 0x%x\n", i2c->reg->STATUS.WORDVAL); #endif return tcnt >= 0; }
static void usb_thread_main(void *args) { uint8_t c; uint8_t buf[MAX_MSG_LEN], *bp = buf, *bend = buf + sizeof(buf); uint8_t crnl[2] = {'\r', '\n'}; /* usb can't transfer data in the .ro section?? */ uint8_t bs[3] = {'\b', ' ', '\b'}; #define CTRL(c) (c - 'A' + 1) #define ISPRINT(c) ((c) >= 0x20 && (c) < 0x7f) while (!usb_exit) { int ret = usb2Read(&c, 1, USB_READ_TIMEOUT, USB_ENDPOINT); if (ret <= 0) { if (ret != CONIO_TIMEOUT) os_thread_sleep(os_msec_to_ticks(1000)); continue; } if (c == '\n' || c == '\r') { if (bp < bend) *bp = '\0'; else *(bp - 1) = '\0'; usb_drv_write(crnl, 2); mc_event_thread_call(usb_callback, buf, 0); bp = buf; } else if (c == '\b' || c == '\x7f') { if (bp > buf) { --bp; usb_drv_write(bs, 3); } } else if (c == CTRL('U')) { while (bp > buf) { --bp; usb_drv_write(bs, 3); } } else { if (bp < bend) { *bp = c; usb_drv_write(bp, 1); bp++; } } } }
STATIC OPERATE_RET device_differ_init(VOID) { OPERATE_RET op_ret; // key process init op_ret = key_init(key_tbl,(CONST INT)CNTSOF(key_tbl),25); if(OPRT_OK != op_ret) { return op_ret; } STATIC TIMER_ID wfl_timer; // wf direct light timer init int ret; // create timer ret = os_timer_create(&wfl_timer, "wfl_timer", \ os_msec_to_ticks(300),\ wfl_timer_cb, NULL,\ OS_TIMER_PERIODIC, OS_TIMER_AUTO_ACTIVATE); if(ret != WM_SUCCESS) { return OPRT_CR_TIMER_ERR; } return OPRT_OK; }
static void i2c_read_start(wm_i2c *i2c) { int retry; uint32_t abrt; for (retry = 10; !(i2c->reg->STATUS.WORDVAL & 0x02 /* TFNF */);) { if (--retry < 0) { mc_log_debug("I2C: read: cannot write READ CMD\n"); return; } os_thread_sleep(os_msec_to_ticks(10)); } i2c->reg->DATA_CMD.WORDVAL = 0x100; /* READ CMD */ if (i2c->reg->RAW_INTR_STAT.WORDVAL & 0x40 /* TX ABRT */) { abrt = i2c_get_abort_cause(i2c); if (abrt & 0x0f) { #if I2C_VERBOSE mc_log_debug("I2C: read: clear abort: 0x%x\n", abrt); #endif i2c_clear_abort(i2c); } } }
static void i2c_config(wm_i2c *i2c) { i2c_reg_t *reg = i2c->reg; reg->ENABLE.WORDVAL = 0; /* disable I2C */ if (i2c->fast) { reg->FS_SCL_LCNT.BF.FS_SCL_LCNT = NS2CNT(i2c->scl_low); reg->FS_SCL_HCNT.BF.FS_SCL_HCNT = NS2CNT(i2c->scl_high); } else { reg->SS_SCL_LCNT.BF.SS_SCL_LCNT = NS2CNT(i2c->scl_low); reg->SS_SCL_HCNT.BF.SS_SCL_HCNT = NS2CNT(i2c->scl_high); } reg->CON.WORDVAL = 0x40 /* slave disable */ | 0x20 /* restart enable */ | 0x01 /* master enable */ | (i2c->fast ? 0x04 : 0x02) /* speed */; reg->TAR.WORDVAL = i2c->slave_addr; /* 7 bit addr mode | addr */ reg->ENABLE.WORDVAL = 1; /* enable I2C */ i2c_current_slave_addr = i2c->slave_addr; os_thread_sleep(os_msec_to_ticks(35)); #if I2C_VERBOSE if (i2c_get_abort_cause(i2c) & 0x0f) mc_log_debug("I2C: init: NO ACK!\n"); #endif }
/*********************************************************** * Function: gw_cntl_init * Input: * Output: * Return: ***********************************************************/ OPERATE_RET gw_cntl_init(VOID) { OPERATE_RET op_ret; op_ret = httpc_aes_init(); if(OPRT_OK != op_ret) { PR_ERR("op_ret:%d",op_ret); return op_ret; } op_ret = ws_db_init(); if(OPRT_OK != op_ret) { return op_ret; } memset(&gw_cntl,0,sizeof(gw_cntl)); memset(&gw_mutex,0,sizeof(gw_mutex)); // create mutex int ret; ret = os_mutex_create(&gw_mutex, "gw_mutex", 1); if(ret != WM_SUCCESS) { return OPRT_CR_MUTEX_ERR; } // create gw active timer ret = os_timer_create(&gw_actv_timer, "gw_actv_timer", os_msec_to_ticks(1000), &gw_actv_timer_cb, NULL, OS_TIMER_PERIODIC, OS_TIMER_NO_ACTIVATE); if (ret != WM_SUCCESS) { return OPRT_COM_ERROR; } PROD_IF_REC_S prod_if; #if 1 memset(&prod_if,0,sizeof(prod_if)); ws_db_get_prod_if(&prod_if); if(!prod_if.mac[0] || !prod_if.prod_idx[0]) { // un init set_gw_status(UN_INIT); return OPRT_OK; } #else strcpy(prod_if.mac,"112233445566"); strcpy(prod_if.prod_idx,"0da02001"); #endif op_ret = ws_db_get_gw_actv(&gw_cntl.active); if(OPRT_OK != op_ret) { memset(&gw_cntl.active,0,sizeof(gw_cntl.active)); ws_db_set_gw_actv(&gw_cntl.active); set_gw_status(UN_ACTIVE); }else { if(!gw_cntl.active.key[0] || !gw_cntl.active.uid_cnt) { // un active if(!gw_cntl.active.token[0]) { set_gw_status(UN_ACTIVE); }else { start_active_gateway(); } }else { set_gw_status(STAT_WORK); } } strcpy(gw_cntl.gw.sw_ver,GW_VER); #if 0 strcpy(gw_cntl.gw.name,GW_DEF_NAME); #else snprintf(gw_cntl.gw.name,sizeof(gw_cntl.gw.name),"%s-%s",GW_DEF_NAME,&prod_if.mac[8]); #endif snprintf(gw_cntl.gw.id,sizeof(gw_cntl.gw.id),"%s%s",prod_if.prod_idx,prod_if.mac); gw_cntl.gw.ability = GW_DEF_ABI; // create dev upload timer ret = os_timer_create(&dev_ul_timer, "dev_ul_timer", os_msec_to_ticks(600), &dev_ul_timer_cb, NULL, OS_TIMER_PERIODIC, OS_TIMER_NO_ACTIVATE); if (ret != WM_SUCCESS) { return OPRT_COM_ERROR; } return OPRT_OK; }
/* This task configures Evrythng client and connects to the Evrythng cloud */ static void evrythng_task() { psm_handle_t handle; int rc; if ((rc = psm_open(&handle, "evrythng")) != 0) { wmprintf("psm_open failed with: %d (Is the module name registered?)\n\r", rc); goto exit; } char api_key[128]; if (psm_get(&handle, "api_key", api_key, 128) == 0) { wmprintf("api_key: %s\n\r", api_key); } else { wmprintf("api_key doesn't exist\n\r"); goto exit; } char thng_id_buf[64]; if (psm_get(&handle, "thng_id", thng_id_buf, 64) == 0) { if (thng_id != NULL) { os_mem_free(thng_id); } thng_id = (char*)os_mem_alloc((strlen(thng_id_buf)+1)*sizeof(char)); strcpy(thng_id, thng_id_buf); wmprintf("thng_id: %s\n\r", thng_id); } else { wmprintf("thng_id doesn't exist\n\r"); goto exit; } char url_buf[64]; if (psm_get(&handle, "url", url_buf, 64) == 0) { wmprintf("Evrythng URL: %s\n\r", url_buf); } else { wmprintf("Evrythng URL doesn't exist\n\r"); goto exit; } psm_close(&handle); EvrythngInitHandle(&evt_handle); EvrythngSetUrl(evt_handle, url_buf); EvrythngSetKey(evt_handle, api_key); EvrythngSetLogCallback(evt_handle, log_callback); EvrythngSetConnectionCallbacks(evt_handle, on_connection_lost, on_connection_restored); while (EvrythngConnect(evt_handle) != EVRYTHNG_SUCCESS) { wmprintf("Retry\n\r"); os_thread_sleep(os_msec_to_ticks(5000)); } wmprintf("Connected\n\r"); os_semaphore_create_counting(&button1_sem, "button1_sem", 1000, 0); os_semaphore_create_counting(&button2_sem, "button1_sem", 1000, 0); EvrythngSubThngAction(evt_handle, thng_id, "_led1", 0, action_led_callback); EvrythngSubThngAction(evt_handle, thng_id, "_led2", 0, action_led_callback); os_thread_create(&button1_thread, "button1_task", button_task, (void*)button_1, &button_stack, OS_PRIO_3); os_thread_create(&button2_thread, "button2_task", button_task, (void*)button_2, &button_stack, OS_PRIO_3); exit: os_thread_self_complete(0); }
/* WPS main processing thread * */ static void wps_main(os_thread_arg_t data) { #ifdef CONFIG_P2P struct timeval tv, now; WPS_DATA *wps_s = (WPS_DATA *) &wps_global; WFD_DATA *pwfd_data = &wps_global.wfd_data; bss_config_t bss_config; #endif int ret; #ifdef CONFIG_WPA2_ENTP struct wpa2_command *wpa2_cmd = NULL; WPS_DATA *wps_s = (WPS_DATA *) &wps_global; #else struct wps_command *wps_cmd = NULL; #endif #ifdef CONFIG_P2P memset(&bss_config, 0, sizeof(bss_config_t)); /* * Download Wfd configuration if supplied with -p command line. */ if (local_wcc->role == WFD_ROLE) { if (wfd_wlan_update_bss_mode(BSS_MODE_WIFIDIRECT_GO) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to initialize " "BSS Mode!\n"); goto fail; } /* Set WFD uAP configuration */ wifidirectapcmd_sys_config(); if (wfd_wlan_update_bss_mode(BSS_MODE_WIFIDIRECT_CLIENT) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to initialize " "BSS Mode!\n"); goto fail; } /* Set WFD configuration */ wifidirectcmd_config(); if (wfd_set_mode(WFD_MODE_START) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to " "initialize WFD!\n"); goto fail; } if (auto_go) { if (wfd_wlan_update_bss_mode(BSS_MODE_WIFIDIRECT_GO) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to " "initialize BSS Mode!\n"); goto fail; } if (wfd_set_mode(WFD_MODE_START_GROUP_OWNER) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to " "initialize WFD!\n"); goto fail; } if (!wps_s->current_ssid.ssid_len) { apcmd_get_bss_config(&bss_config); load_cred_info(wps_s, gpwps_info, &bss_config); /* * For Wi-Fi Direct, we need to * convert the passphrase to PSK. * * Hence update the default * passphrase */ wlan_generate_psk(gpwps_info); } if (wps.cb(P2P_AUTO_GO_STARTED, &WFD_devicename, strlen(WFD_devicename)) == -WM_FAIL) P2P_LOG("WFD Callback failed for " "event: %d\r\n", P2P_AUTO_GO_STARTED); if (wlan_add_network(&p2p_uap_network) != WLAN_ERROR_NONE) { wps_printf(MSG_ERROR, "failed to add " "wfd network\r\n"); goto fail; } if (wlan_start_network(p2p_uap_network.name) != WLAN_ERROR_NONE) { wps_printf(MSG_ERROR, "failed to start " "wfd network\r\n"); goto fail; } } else { mlanconfig_bgscan(1); if (wfd_set_mode(WFD_MODE_START_FIND_PHASE) != WPS_STATUS_SUCCESS) { wps_printf(MSG_ERROR, "ERROR - Fail to " "initialize WFD!\n"); goto fail; } wps_set_wfd_cfg(); if (wps.cb(P2P_DEVICE_STARTED, &WFD_devicename, strlen(WFD_devicename)) == -WM_FAIL) P2P_LOG("WFD Callback failed for " "event: %d\r\n", P2P_DEVICE_STARTED); wfd_start_peer_ageout_timer(pwfd_data); p2p_scan_on = 1; } } #endif #ifndef CONFIG_P2P if (wps.cb(WPS_STARTED, NULL, 0) == -WM_FAIL) WPS_LOG("WPS Callback failed for event: %d\r\n", WPS_STARTED); #endif #ifndef CONFIG_WPA2_ENTP wps_register_rx_callback(WPSEAPoLRxDataHandler); #endif while (1) { #ifdef CONFIG_WPA2_ENTP ret = os_queue_recv(&wps.cmd_queue, &wpa2_cmd, RX_WAIT); if (ret != WM_SUCCESS || wpa2_cmd == NULL) continue; #else #ifdef CONFIG_P2P if (!auto_go && p2p_scan_on) { if (wps_loop.timeout) { now.tv_sec = os_ticks_to_msec(os_ticks_get()) / 1000; now.tv_usec = (os_ticks_to_msec (os_ticks_get()) % 1000) * 1000; if (timer_cmp(&now, &wps_loop.timeout->time)) timersub(&wps_loop.timeout->time, &now, &tv); else tv.tv_sec = tv.tv_usec = 0; } /* check if some registered timeouts have occurred */ if (wps_loop.timeout) { struct wps_timeout_s *tmp; now.tv_sec = os_ticks_to_msec(os_ticks_get()) / 1000; now.tv_usec = (os_ticks_to_msec (os_ticks_get()) % 1000) * 1000; if (!timer_cmp(&now, &wps_loop.timeout->time)) { tmp = wps_loop.timeout; wps_loop.timeout = wps_loop.timeout->next; tmp->handler(tmp->callback_data); wps_mem_free(tmp); } } } if (go_request) { p2p_scan_on = 0; g_method = CMD_WPS_PBC; wps_init(); go_request = 0; } ret = os_queue_recv(&wps.cmd_queue, &wps_cmd, os_msec_to_ticks(1000)); #else ret = os_queue_recv(&wps.cmd_queue, &wps_cmd, RX_WAIT); #endif if (ret != WM_SUCCESS || wps_cmd == NULL) continue; #endif #ifdef CONFIG_WPA2_ENTP memcpy(&wps_s->wpa2_network, &wpa2_cmd->wpa2_network, sizeof(struct wlan_network)); wps_mem_free(wpa2_cmd); g_method = CMD_WPS_PBC; ret = wps_private_info_allocate(&gpwps_info); ret = wps_init(); continue; #else g_method = wps_cmd->command; g_channel = wps_cmd->res.channel; #ifdef CONFIG_P2P g_bssid = (u8 *) wps_cmd->res.bssid; g_ssid = (u8 *) wps_cmd->res.ssid; #else memcpy(g_ssid, (u8 *) wps_cmd->res.ssid, MAX_SSID_LEN + 1); memcpy(g_bssid, (u8 *) wps_cmd->res.bssid, ETH_ALEN); #endif wps_mem_free(wps_cmd); switch (g_method) { case CMD_WPS_PIN: g_gen_pin = wps_cmd->wps_pin; wps_init(); break; case CMD_WPS_PBC: wps_init(); break; } #endif } #ifdef CONFIG_P2P fail: if (wps.cb(P2P_FAILED, NULL, 0) == -WM_FAIL) P2P_LOG("WPS Callback failed for event: %d\r\n", P2P_FAILED); wps_stop(); #endif }
/* Initialise the LCD configuration */ static void init_lcd(void) { uint8_t buf[20]; mdev_t *i2c_dev; pinmux_dev = pinmux_drv_open("MDEV_PINMUX"); if (pinmux_dev == NULL) { lcd_d("Pinmux driver init is required before open"); return; } gpio_dev = gpio_drv_open("MDEV_GPIO"); if (gpio_dev == NULL) { lcd_d("GPIO driver init is required before open"); return; } board_lcd_reset(); i2c_dev = i2c_drv_open(MDEV_lcd.private_data, I2C_SLAVEADR(I2C_LCD_ADDR >> 1)); if (i2c_dev == NULL) { lcd_d("I2C driver init is required before open"); return; } /* The LCD Screen operates in one of the two modes, configuration and * data. In configuration mode various parameters specific to the LCD * screen are set while in data mode data is written in the RAM of the * screen which is then displayed. Set the configuration mode first. * The device stays in this mode until a I2C_STOP is received. */ buf[0] = LCD_CMD_CONFIG_MODE; /* Com send */ /* Internal OSC Frequency * Bits: 0 0 0 1 BS F2 F1 F0 * BS: 1 -> 1/4 bias, 0 -> 1/5 bias * F2~0: internal oscillator frequency */ buf[1] = 0x14; /* Function Set * Bits: 0 0 1 DL N DH 0 IS * DL: interface data 1 -> 8 bits, 0 -> 4 bits * N: number of lines 1 -> 2 lines, 0 -> 1 line * DH: enable double height font * IS: Instruction set select 0/1 */ buf[2] = 0x39; /* Contrast Set * Bits: 0 1 1 1 C3 C2 C1 C0 * C3~0: Last 4 bits of the contrast value */ buf[3] = 0x78; /* Contrast Set * Bits: 0 1 0 1 I B C5 C4 * I: ICON display on/off * B: booster circuit on/off * C5~4: Higher order 2 bits of the contrast value */ buf[4] = 0x55; /* Follower Control * Bits: 0 1 1 0 F RAB2 RAB1 RAB0 * F : Follower Ckt on/off * RAB2~0: follower amplifier ratio */ buf[5] = 0x6d; /* Display on/off * Bits: 0 0 0 0 1 D C B * D: display on/off * C: cursor on/off * B: cursor position on/off */ buf[6] = 0x0c; /* Clear Display * Bits: 0 0 0 0 0 0 0 1 * Set DDRAM address to 00H, and clear display */ buf[7] = 0x01; /* Entry mode * Bits: 0 0 0 0 0 1 I/D S * I/D: Cursor move direction inc/dec * S: Display shift on/off */ buf[8] = 0x06; os_thread_sleep(os_msec_to_ticks(35)); i2c_drv_write(i2c_dev, buf, 9); i2c_drv_close(i2c_dev); }
/** * @brief Process WPS Enrollee PIN mode and PBC user selection operations * * @param pwps_info A pointer to WPS_INFO structure * @param wps_s A pointer to global WPS structure * @return WPS_STATUS_SUCCESS--success, otherwise--fail */ int wps_enrollee_start(PWPS_INFO pwps_info, WPS_DATA *wps_s) { int ret = WPS_STATUS_SUCCESS; #ifndef CONFIG_WPA2_ENTP int retry_cnt = 5; int connect_retry = 10; enum wlan_connection_state state; #endif ENTER(); pwps_info->enrollee.auth_type_flag = AUTHENTICATION_TYPE_ALL; pwps_info->enrollee.encry_type_flag = ENCRYPTION_TYPE_ALL; #ifndef CONFIG_WPA2_ENTP if (pwps_info->enrollee.device_password_id == DEVICE_PASSWORD_ID_PIN) { /* Generate PIN */ wps_generate_PIN(pwps_info); if (pwps_info->pin_generator == WPS_ENROLLEE) { pwps_info->input_state = WPS_INPUT_STATE_NO_INPUT; pwps_info->pin_pbc_set = WPS_SET; } else { pwps_info->enrollee.updated_device_password_id = DEVICE_PASSWORD_REG_SPECIFIED; } } memset(&wps_network, 0, sizeof(struct wlan_network)); if (g_ssid && strlen((const char *)g_ssid)) strncpy(wps_network.name, (const char *) g_ssid, MAX_SSID_LEN + 1); else strncpy(wps_network.name, "p2p_network", MAX_SSID_LEN + 1); memcpy(wps_network.ssid, (const char *) g_ssid, MAX_SSID_LEN + 1); memcpy(wps_network.bssid, (const char *) g_bssid, ETH_ALEN); wps_network.channel = g_channel; wps_network.address.addr_type = ADDR_TYPE_DHCP; #ifdef CONFIG_WPS2 wps_network.wps_specific = 1; #endif if (g_channel) wps_network.channel_specific = 1; else if (is_mac_all_zero(g_bssid)) wps_network.ssid_specific = 1; else wps_network.bssid_specific = 1; wps_network.security.type = WLAN_SECURITY_NONE; #ifdef CONFIG_P2P wps_network.type = WLAN_BSS_TYPE_WIFIDIRECT; wps_network.role = WLAN_BSS_ROLE_STA; #endif ret = wlan_add_network(&wps_network); if (ret != 0) { WPS_LOG(" Failed to add network %d\r\n", ret); goto fail; } do { WPS_LOG("Connecting to %s .....", wps_network.ssid); ret = wlan_connect(wps_network.name); if (ret != 0) { WPS_LOG("Failed to connect %d\r\n", ret); goto retry; } connect_retry = 200; do { /* wait for interface up */ os_thread_sleep(os_msec_to_ticks(50)); if (wlan_get_connection_state(&state)) { P2P_LOG("Error: unable to get " "connection state\r\n"); continue; } if (state == WLAN_ASSOCIATED || connect_retry == 0) break; #ifdef CONFIG_P2P connect_retry--; } while (state != WLAN_DISCONNECTED); #else } while (connect_retry--); #endif if (state != WLAN_ASSOCIATED) { WPS_LOG("Error: Not connected.\r\n"); goto retry; } WPS_LOG("Connected to following BSS (or IBSS) :"); WPS_LOG ("SSID = [%s], BSSID = [%02x:%02x:%02x:%02x:%02x:%02x]", wps_network.ssid, wps_network.bssid[0], wps_network.bssid[1], wps_network.bssid[2], wps_network.bssid[3], wps_network.bssid[4], wps_network.bssid[5]); /* Save information to global structure */ wps_s->current_ssid.ssid_len = strlen(wps_network.ssid); memcpy(wps_s->current_ssid.ssid, wps_network.ssid, wps_s->current_ssid.ssid_len); memcpy(wps_s->current_ssid.bssid, wps_network.bssid, ETH_ALEN); /* Store Peer MAC Address */ if (pwps_info->role == WPS_ENROLLEE || (IS_DISCOVERY_ENROLLEE(pwps_info)) ) { if (is_mac_all_zero((u8 *) wps_network.bssid)) { if (wlan_get_current_network(&sta_network)) goto fail; memcpy(pwps_info->registrar.mac_address, sta_network.bssid, ETH_ALEN); } else memcpy(pwps_info->registrar.mac_address, wps_network.bssid, ETH_ALEN); } #else /* Save information to global structure */ wps_s->current_ssid.ssid_len = strlen(wps_s->wpa2_network.ssid); memcpy(wps_s->current_ssid.ssid, wps_s->wpa2_network.ssid, wps_s->current_ssid.ssid_len); memcpy(wps_s->current_ssid.bssid, wps_s->wpa2_network.bssid, ETH_ALEN); /* Store Peer MAC Address */ if (pwps_info->role == WPS_ENROLLEE || (IS_DISCOVERY_ENROLLEE(pwps_info)) ) { if (is_mac_all_zero((u8 *) wps_s->wpa2_network.bssid)) { if (wlan_get_current_network(&sta_network)) goto fail; memcpy(pwps_info->registrar.mac_address, sta_network.bssid, ETH_ALEN); } else memcpy(pwps_info->registrar.mac_address, wps_s->wpa2_network.bssid, ETH_ALEN); } #endif #ifdef CONFIG_P2P WPS_LOG("Registration Process Started...."); #elif CONFIG_WPA2_ENTP WPS_LOG("Connected to following BSS (or IBSS) :"); WPS_LOG ("SSID = [%s], BSSID = [%02x:%02x:%02x:%02x:%02x:%02x]", wps_s->wpa2_network.ssid, wps_s->wpa2_network.bssid[0], wps_s->wpa2_network.bssid[1], wps_s->wpa2_network.bssid[2], wps_s->wpa2_network.bssid[3], wps_s->wpa2_network.bssid[4], wps_s->wpa2_network.bssid[5]); WPS_LOG("WPA2 Enterprise (EAP-TLS) Protocol Started ....."); #else WPS_LOG("WPS Registration Protocol Started ....."); if (wps.cb(WPS_SESSION_STARTED, NULL, 0) == -WM_FAIL) WPS_LOG("WPS Callback failed for event: %d\r\n", WPS_SESSION_STARTED); #endif /* Start WPS registration timer */ wps_start_registration_timer(pwps_info); /* Starting WPS Message Exchange Engine */ wps_state_machine_start(pwps_info); ret = WPS_STATUS_SUCCESS; #ifndef CONFIG_WPA2_ENTP break; retry: retry_cnt--; WPS_LOG("Connect to AP FAIL ! Retrying ..... \r\n"); wps_printf(DEBUG_WLAN | DEBUG_INIT, "Retry Count = %d", retry_cnt); } while (retry_cnt != 0);