Exemplo n.º 1
0
int tls_cmd_get_channel( u8 *channel, u8 *channel_en)
{
    tls_param_get(TLS_PARAM_ID_CHANNEL, (void *)channel, (bool)0);
    tls_param_get(TLS_PARAM_ID_CHANNEL_EN, (void *)channel_en, (bool)0);

    /* 未指定信道时默认选择1信道 for BUG #429 */
    if (0 == *channel_en)
    {
        *channel = 1;
    }

    return 0; 
}
Exemplo n.º 2
0
//联网demo,根据参数判断是一键配置联网还是主动联网
//一键配置命令示例:t-oneshot
//主动联网命令示例:t-connet("ssid","pwd");
int DemoConnectNet(char *buf)
{	
	if(strstr(buf,DEMO_ONESHOT) != NULL)	//一键配置
	{
		ifoneshot = 1;
		CreateOneshotDemoTask();
	}
	else if(strstr(buf, DEMO_CONNET) != NULL)
	{
		char *p1 = NULL,*p2 = NULL;
		char ssid[64];
		char pwd[70];
		struct tls_param_ip ip_param;
		
		if(strchr(buf, ';') != NULL || strchr(buf,')') != NULL)		//收到了命令结束符
		{
			printf("\ninput:%s\n",buf);
			memset(ssid,0,sizeof(ssid));
			memset(pwd,0,sizeof(pwd));
			p1 = strchr(buf,'"');
			if(NULL == p1)
				return WM_FAILED;
			p2 = p1 +1;	//ssid的起始位置
			p1 = strchr(p2,'"');	//ssid的结束位置
			if(NULL == p1)
				return WM_FAILED;
			MEMCPY(ssid, p2, p1 - p2);
			printf("\nssid=%s\n",ssid);
			p2 = p1 + 1;
			p1 = strchr(p2,'"');	
			if(NULL == p1)
				return WM_FAILED;
			p2 = p1 + 1;		//pwd 的起始位置
			p1 = strchr(p2, '"');	//pwd的结束位置
			if(NULL == p1)
				return WM_FAILED;			
			if(p1 - p2 > 64)
			{
				printf("\npassword too long,error!\n");
				return WM_FAILED;	
			}
			MEMCPY(pwd, p2, p1 - p2);
			printf("\npassword=%s\n",pwd);
			tls_wifi_set_oneshot_flag(0);
			ifoneshot = 0;

			tls_param_get(TLS_PARAM_ID_IP, &ip_param, FALSE);
			ip_param.dhcp_enable = true;
			tls_param_set(TLS_PARAM_ID_IP, &ip_param, FALSE);
			
			tls_wifi_connect((u8 *)ssid, strlen(ssid), (u8 *)pwd, strlen(pwd));
			tls_netif_add_status_event(con_net_status_changed_event);
			printf("\nplease wait connect net......\n");
		}
		else
			return DEMO_CONSOLE_SHORT_CMD;
	}

	return WM_SUCCESS;
}
Exemplo n.º 3
0
void tls_cmd_init_socket_cfg(void)
{
    int timeout = 0, host_len;
    struct tls_param_socket remote_socket_cfg;
    tls_param_get(TLS_PARAM_ID_DEFSOCKET, &remote_socket_cfg, FALSE);
    /* read default socket params */
    socket_cfg.proto = remote_socket_cfg.protocol;
    socket_cfg.client = remote_socket_cfg.client_or_server ? 0 : 1;
    socket_cfg.port = remote_socket_cfg.port_num;
	TLS_DBGPRT_INFO("socket_cfg.proto = %d, socket_cfg.client = %d, socket_cfg.port = %d\n", socket_cfg.proto, socket_cfg.client, socket_cfg.port);
    host_len = strlen((char *)remote_socket_cfg.host);  
    if (socket_cfg.client) {
        /*  host name */
		if (host_len){
	        MEMCPY(socket_cfg.host, 
	                remote_socket_cfg.host, host_len);
			string_to_ipaddr((char *)remote_socket_cfg.host, &socket_cfg.ip_addr[0]);
		}
    } else if (!socket_cfg.client && socket_cfg.proto == 0) {
	    if (strtodec(&timeout, (char *)remote_socket_cfg.host)<0){
			timeout = 0;
	    }

        socket_cfg.timeout = timeout; 
    } else
        ;
}
Exemplo n.º 4
0
int tls_cmd_get_uart_params( 
        struct tls_cmd_uart_params_t *params)
{
    struct tls_param_uart uart_params;

    tls_param_get(TLS_PARAM_ID_UART, 
            (void *)&uart_params, 0);
    params->baud_rate = uart_params.baudrate;
    params->flow_ctrl = uart_params.flow;
    params->parity = uart_params.parity;
	switch (uart_params.stop_bits){
		case TLS_UART_ONE_STOPBITS:
			params->stop_bit = 0;
			break;
		case TLS_UART_TWO_STOPBITS:
			params->stop_bit = 2;
			break;
		default:
			params->stop_bit = 0;
			break;
	}
	switch (uart_params.charsize){
		case TLS_UART_CHSIZE_8BIT:
			params->charlength = 0;
			break;
		case TLS_UART_CHSIZE_7BIT:
			params->charlength = 1;
			break;
		default:
			params->charlength = 0;
	}

    
    return 0;
}
Exemplo n.º 5
0
int tls_cmd_get_atpt( u16 *period)
{
	struct tls_hostif *hif = tls_get_hostif();
	tls_param_get(TLS_PARAM_ID_AUTO_TRIGGER_PERIOD, (void *)period, 0);	
	hif->uart_atpt = *period;
	return 0;
}
Exemplo n.º 6
0
int tls_cmd_get_warc( u8 *autoretrycnt)
{
    tls_param_get(TLS_PARAM_ID_AUTO_RETRY_CNT, 
        (void *)autoretrycnt,
        (bool)1);
	return 0;
}
Exemplo n.º 7
0
static void netif_status_changed(struct netif *netif)
{
    struct tls_netif_status_event *status_event;
    ethif->status = netif_is_up(nif);
#if TLS_CONFIG_APSTA
    u8 mode;
    tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);
#endif
    dl_list_for_each(status_event, &netif_status_event.list, struct tls_netif_status_event, list)
    {
        if(status_event->status_callback != NULL && netif_is_up(netif))
        {
            if (0 == tls_wifi_get_oneshot_flag())
            {
#if TLS_CONFIG_APSTA
                if (IEEE80211_MODE_APSTA == mode)
                {
                    if (netif_is_up(nif) && !netif_is_up(nif->next))
                        status_event->status_callback(NETIF_APSTA_STA_NET_UP);
                    else if (netif_is_up(nif) && netif_is_up(nif->next))
                        status_event->status_callback(NETIF_IP_NET_UP);
                }
                else
#endif
                {
                    status_event->status_callback(NETIF_IP_NET_UP);
                }
            }
        }
    }
}
Exemplo n.º 8
0
int tls_cmd_get_cmdm( u8 *cmdmode)
{
    tls_param_get(TLS_PARAM_ID_CMD_MODE, 
            (void *)cmdmode,
            (bool)0);

	return 0;
}
Exemplo n.º 9
0
int tls_cmd_get_wireless_mode(u8 *mode)
{

	tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )mode, true);	
	/*set WPAS_MODE to do*/

    return 0;
}
Exemplo n.º 10
0
static void sys_net_up()
{
    struct ip_addr ip_addr, net_mask, gateway, dns1, dns2;
    struct tls_param_ip ip_param;
	u8 mode;
#if TLS_CONFIG_AP
	u8 dnsname[32];
#endif
	
    tls_param_get(TLS_PARAM_ID_IP, &ip_param, FALSE);
	tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);
    if (ip_param.dhcp_enable && 
            (mode != IEEE80211_MODE_AP)) {
        ip_addr_set_zero(&ip_addr);
        ip_addr_set_zero(&net_mask);
        ip_addr_set_zero(&gateway); 
        tls_netif_set_addr(
                &ip_addr, &net_mask, &gateway);
         tls_dhcp_start();
    } else {
        tls_dhcp_stop();
		MEMCPY((char *)&ip_addr.addr, &ip_param.ip, 4);
        MEMCPY((char *)&net_mask.addr, &ip_param.netmask, 4);
        MEMCPY((char *)&gateway.addr, &ip_param.gateway, 4);
        tls_netif_set_addr(
                &ip_addr, &net_mask, &gateway); 
        MEMCPY((char *)&dns1.addr, &ip_param.dns1, 4);
        MEMCPY((char *)&dns2.addr, &ip_param.dns2, 4);
        tls_netif_dns_setserver(0, &dns1);
        tls_netif_dns_setserver(1, &dns2);
        tls_netif_set_up();	
    }
	
#if TLS_CONFIG_AP
    if (mode == IEEE80211_MODE_AP)
    {	
        tls_dhcps_start();
        tls_param_get(TLS_PARAM_ID_DNSNAME, dnsname, 0);
        tls_dnss_start(dnsname);
    }
#endif	
}
Exemplo n.º 11
0
int tls_cmd_get_hw_mode( 
        struct tls_cmd_wl_hw_mode_t *hw_mode)
{
    struct tls_param_bgr bgr;	

    tls_param_get(TLS_PARAM_ID_WBGR, (void *)&bgr, (bool)0);
	hw_mode->hw_mode = bgr.bg;
	hw_mode->max_rate = bgr.max_rate;

    return 0; 
}
Exemplo n.º 12
0
int tls_cmd_get_original_ssid(struct tls_param_ssid *original_ssid)
{
	tls_param_get(TLS_PARAM_ID_ORIGIN_SSID, (void *)original_ssid, 1);
	if(original_ssid->ssid_len > 32)
       {
           original_ssid->ssid_len = 0;
           original_ssid->ssid[0] = '\0';
	}

	return 0;
}
Exemplo n.º 13
0
INT8S tls_dhcps_start(void)
{
#if TLS_CONFIG_APSTA
    u8 mode;
    tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);
    if (IEEE80211_MODE_APSTA == mode)
        return DHCPS_Start(nif->next);
    else
#endif
        return DHCPS_Start(nif);
}
Exemplo n.º 14
0
int tls_cmd_get_work_mode(u8 *mode)
{
	u8 auto_mode;
	
    tls_param_get(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode, 0);
    if (0 == auto_mode)
        *mode = 1;
    else
        *mode = 0;
    return 0;
}
Exemplo n.º 15
0
int tls_cmd_get_ip_info(
        struct tls_cmd_ip_params_t *params)
{
    struct tls_param_ip ip_param;
    tls_param_get(TLS_PARAM_ID_IP, &ip_param, FALSE);

    MEMCPY(params->ip_addr, (char *)ip_param.ip, 4);
    MEMCPY(params->netmask, (char *)ip_param.netmask, 4);
    MEMCPY(params->gateway, (char *)ip_param.gateway, 4);
    MEMCPY(params->dns, (char *)ip_param.dns1, 4);
    params->type = ip_param.dhcp_enable ? 0 : 1;
    return 0;
}
Exemplo n.º 16
0
int tls_cmd_get_bssid(struct tls_cmd_bssid_t *bssid)
{
    struct tls_param_bssid param_bssid;

	if (bssid){
	    tls_param_get(TLS_PARAM_ID_BSSID, (void *)&param_bssid, 
    	        (bool)0);
		MEMCPY(bssid->bssid, param_bssid.bssid, 6);
		bssid->enable = param_bssid.bssid_enable;
	}

    return 0;
}
Exemplo n.º 17
0
int tls_cmd_get_ssid2(struct tls_cmd_ssid_t *ssid)
{
    struct tls_param_ssid params_ssid;

    tls_param_get(TLS_PARAM_ID_APSTA_SSID, (void *)&params_ssid, 1);
    if (params_ssid.ssid_len > 32){
    	ssid->ssid_len = 0;
		params_ssid.ssid[0] = '\0';
    }else{
		ssid->ssid_len = params_ssid.ssid_len;
	    MEMCPY(ssid->ssid, params_ssid.ssid, ssid->ssid_len);
    }
    return 0; 
}
Exemplo n.º 18
0
static void demo_sock_fwup_task(void *sdata)
{
//	ST_Demo_Sys *sys = (ST_Demo_Sys *)sdata;
	void *msg;
	struct tls_ethif * ethif = tls_netif_get_ethif();

	printf("\nsock fwup task\n");
	if(ethif->status)	//已经在网
	{
		tls_os_queue_send(demo_sock_fwup_q, (void *)DEMO_MSG_SOCKET_CREATE, 0);
	}
	else
	{
		struct tls_param_ip ip_param;
		
		tls_param_get(TLS_PARAM_ID_IP, &ip_param, TRUE);
		ip_param.dhcp_enable = true;
		tls_param_set(TLS_PARAM_ID_IP, &ip_param, TRUE);
		tls_wifi_set_oneshot_flag(1);		/*一键配置使能*/
		printf("\nwait one shot......\n");
	}
	tls_netif_add_status_event(sock_fwup_net_status_changed_event);

	for(;;) 
	{
		tls_os_queue_receive(demo_sock_fwup_q, (void **)&msg, 0, 0);
		//printf("\n msg =%d\n",msg);
		switch((u32)msg)
		{
			case DEMO_MSG_WJOIN_SUCCESS:
				break;
				
			case DEMO_MSG_SOCKET_CREATE:
				create_socket_fwup_demo();
				break;
				
			case DEMO_MSG_WJOIN_FAILD:
				break;

			case DEMO_MSG_SOCKET_ERR:
				printf("\nsocket err\n");
				break;

			default:
				break;
		}
	}

}
Exemplo n.º 19
0
int tls_cmd_get_key(struct tls_cmd_key_t *key)
{
    struct tls_param_key *param_key;
	
	param_key = tls_mem_alloc(sizeof(struct tls_cmd_key_t));
	if(!param_key)
		return -1;
	memset(param_key, 0, sizeof(struct tls_cmd_key_t));
    tls_param_get(TLS_PARAM_ID_KEY, (void *)param_key, 1);
    key->index = param_key->key_index;
    key->key_len = param_key->key_length;
    key->format = param_key->key_format;
    MEMCPY(key->key, param_key->psk, 64);

	tls_mem_free(param_key);
    return 0; 
}
Exemplo n.º 20
0
int tls_cmd_set_ip_info(
        struct tls_cmd_ip_params_t *params, u8 update_flash)
{
    struct tls_ethif *ethif;
    struct tls_param_ip param_ip;

    ethif=tls_netif_get_ethif();
	if(tls_param_get_updp_mode() == 0)
	{
	    if (params->type == 0) {
	        /* enable dhcp */
			u8 mode;
			tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, false);
	        if ((mode == IEEE80211_MODE_INFRA)
#if TLS_CONFIG_APSTA
	            || (mode == IEEE80211_MODE_APSTA)
#endif
	           ) {
	            tls_dhcp_start(); 
	        }
	        else
	            return -1;
	    } else {
	        tls_dhcp_stop();
	        MEMCPY((char *)&ethif->ip_addr.addr, &params->ip_addr, 4);
	        MEMCPY((char *)&ethif->dns1.addr, &params->dns, 4);
	        MEMCPY((char *)&ethif->netmask.addr, &params->netmask, 4);
	        MEMCPY((char *)&ethif->gw.addr, &params->gateway, 4); 
	        tls_netif_set_addr(
	                &ethif->ip_addr, &ethif->netmask, &ethif->gw);
	    }
	}

    /* update flash params */
    param_ip.dhcp_enable = params->type ? 0 : 1;
    MEMCPY((char *)param_ip.dns1, &params->dns, 4);
    MEMCPY((char *)param_ip.dns2, param_ip.dns2, 4);
    MEMCPY((char *)param_ip.gateway, &params->gateway, 4);
    MEMCPY((char *)param_ip.ip, &params->ip_addr, 4);
    MEMCPY((char *)param_ip.netmask, &params->netmask, 4);
    tls_param_set(TLS_PARAM_ID_IP, (void *)&param_ip, (bool)update_flash);

    return 0;
}
Exemplo n.º 21
0
static void sys_net_down()
{
#if TLS_CONFIG_AP
	u8 mode;
#endif

    tls_netif_set_down();

	/* Try to reconnect if auto_connect is set*/
	tls_auto_reconnect();
	
#if TLS_CONFIG_AP
	tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);
	if (mode == IEEE80211_MODE_AP){
		tls_dhcps_stop();
		tls_dnss_stop();
	}
#endif
}
Exemplo n.º 22
0
int soft_ap_demo(char *buf)
{
	struct tls_softap_info_t apinfo;
	struct tls_ip_info_t ipinfo;
	u8 ret=0;
	u8 ssid_set = 0;

	u8* ssid = "soft_ap_demo";
	u8 ssid_len = strlen("soft_ap_demo");

	tls_wifi_set_oneshot_flag(0);          /*清除一键配置标志*/

	tls_param_get(TLS_PARAM_ID_BRDSSID, (void *)&ssid_set, (bool)0);
	if (0 == ssid_set){
		ssid_set = 1;
		tls_param_set(TLS_PARAM_ID_BRDSSID, (void *)&ssid_set, (bool)1); /*设置BSSID广播标志*/
	}

	MEMCPY(apinfo.ssid, ssid, ssid_len);
	apinfo.ssid[ssid_len]='\0';
	
	apinfo.encrypt = 0;  /*0:open, 1:wep64, 2:wep128*/
	apinfo.channel = 11; /*channel*/
	apinfo.keyinfo.format = 1; /*密码格式:0是hex格式,1是ascii格式*/
	apinfo.keyinfo.index = 1;  /*wep索引*/
	apinfo.keyinfo.key_len = strlen("1234567890123"); /*密码长度*/
	MEMCPY(apinfo.keyinfo.key, "1234567890123", strlen("1234567890123"));
	/*ip配置信息:ip地址,掩码,dns名称*/
	ipinfo.ip_addr[0] = 192;
	ipinfo.ip_addr[1] = 168;
	ipinfo.ip_addr[2] = 1;
	ipinfo.ip_addr[3] = 1;
	ipinfo.netmask[0] = 255;
	ipinfo.netmask[1] = 255;
	ipinfo.netmask[2] = 255;
	ipinfo.netmask[3] = 0;
	MEMCPY(ipinfo.dnsname, "local.wm", sizeof("local.wm"));
	ret = tls_wifi_softap_create((struct tls_softap_info_t* )&apinfo, (struct tls_ip_info_t* )&ipinfo);
	printf("\n ap create %s ! \n", (ret == WM_SUCCESS)? "Successfully" : "Error");

	return ret;
}
Exemplo n.º 23
0
int tls_sys_init()
{
    int err;
    void *msg;
#if TLS_CONFIG_WEB_SERVER
	struct tls_webs_cfg webcfg;
#endif

    /* create messge queue */
#define SYS_MSG_SIZE     20
    msg  = tls_mem_alloc(SYS_MSG_SIZE * sizeof(void *));
    if (!msg)
        return -1;

    err = tls_os_queue_create(&msg_queue,
            msg,
            SYS_MSG_SIZE, 0);
    if (err)
        return -1;

    /* create task */
    tls_os_task_create(NULL, NULL,
            tls_sys_task,
            (void *)0,
            (void *)&sys_task_stk,          /* 任务栈的起始地址 */
            SYS_TASK_STK_SIZE * sizeof(u32), /* 任务栈的大小     */
            TLS_SYS_TASK_PRIO,
            0);

    tls_netif_add_status_event(sys_net_status_changed);

#if TLS_CONFIG_WEB_SERVER
    tls_param_get(TLS_PARAM_ID_WEBS_CONFIG, (void *)&webcfg, FALSE);
    if ((webcfg.AutoRun)){
        httpd_init(webcfg.PortNum);
        //printf("Web manager server start (tcp port:%d)\n\r",webcfg.PortNum);
    }
#endif
    return 0;

}
Exemplo n.º 24
0
static void demo_oneshot_task(void *sdata)
{
	//ST_Demo_Sys *sys = (ST_Demo_Sys *)sdata;
	void *msg;
	struct tls_param_ip ip_param;

	tls_param_get(TLS_PARAM_ID_IP, &ip_param, TRUE);
	ip_param.dhcp_enable = true;
	tls_param_set(TLS_PARAM_ID_IP, &ip_param, TRUE);

	tls_wifi_set_oneshot_flag(1);		/*一键配置使能*/
	tls_netif_add_status_event(con_net_status_changed_event);
	printf("\nwait one shot......\n");
	for(;;) 
	{
		tls_os_queue_receive(demo_oneshot_q, (void **)&msg, 0, 0);
		//printf("\n msg =%d\n",msg);
		switch((u32)msg)
		{
			case DEMO_MSG_WJOIN_SUCCESS:
				break;
				
			case DEMO_MSG_SOCKET_CREATE:
#if TLS_CONFIG_SOCKET_STD
				DemoStdSockOneshotSendMac();		//任选一个		
#endif
#if TLS_CONFIG_SOCKET_RAW
				//DemoRawSockOneshotSendMac();
#endif //TLS_CONFIG_SOCKET_RAW
				break;
				
			case DEMO_MSG_WJOIN_FAILD:
				break;
			default:
				break;
		}
	}

}
Exemplo n.º 25
0
int tls_cmd_get_webs( struct tls_webs_cfg *webcfg)
{
	tls_param_get(TLS_PARAM_ID_WEBS_CONFIG, (void *)webcfg, 0);
	return 0;
}
Exemplo n.º 26
0
int tls_cmd_get_wps_pin( struct tls_param_wps *wps)
{
	tls_param_get(TLS_PARAM_ID_WPS, (void *)wps,1);

	return 0;
}
Exemplo n.º 27
0
int tls_cmd_get_original_key(struct tls_param_original_key *original_key)
{
	tls_param_get(TLS_PARAM_ID_ORIGIN_KEY, (void *)original_key, 1);
	return 0;	
}
Exemplo n.º 28
0
int tls_cmd_get_pass( u8 *password)
{
    tls_param_get(TLS_PARAM_ID_PASSWORD, (void *)password,(bool)0);
	return 0;
}
Exemplo n.º 29
0
u8 tls_cmd_get_auto_mode(void)
{
    u8 auto_mode_set;
    tls_param_get(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode_set, FALSE);
    return auto_mode_set;
}
Exemplo n.º 30
0
int tls_cmd_get_encrypt( u8 *encrypt)
{
	tls_param_get(TLS_PARAM_ID_ENCRY, (void *)encrypt, (bool)0);

    return 0;
}