示例#1
0
static void assoc_loop(char *ifname, char *staname, char *essid, char *pass, char *bssid, char *beacon)
{
	static int try_count = 0;
	static int assoc_count = 0;

	while (1) {
		if (!check_assoc(staname)) {
			struct survey_table *c;

			led_set_trigger(1);
			iwpriv("ra0", "Beacon", "0");
			syslog(LOG_INFO, "%s is not associated\n", staname);
			syslog(LOG_INFO, "Scanning for networks...\n");
			wifi_site_survey(ifname, 0);
			c = wifi_find_ap(essid, bssid);
			try_count++;
			assoc_count = 0;
			if (c) {
				syslog(LOG_INFO, "Found network, trying to associate (essid: %s, bssid: %s, channel: %s, enc: %s, crypto: %s)\n",
					essid, c->bssid, c->channel, c->security, c->crypto);
				wifi_repeater_start(ifname, staname, c->channel, essid, bssid, pass, c->security, c->crypto);
			} else {
				syslog(LOG_INFO, "No signal found to connect to\n");
				try_count = 0;
			}
		} else {
			if (assoc_count == 0) {
				iwpriv("ra0", "Beacon", beacon);
				syslog(LOG_INFO, "%s is associated\n", staname);
				led_set_trigger(0);
			}

			assoc_count++;
			if (assoc_count > 1)
				try_count = 0;
/*			if ((assoc_count % 4) == 0)
				syslog(LOG_INFO, "%s is still associated\n", staname);*/
		}
		sleep(10);
	}
}
示例#2
0
static int apClient_connect(struct ubus_context *ctx, struct ubus_object *obj,
                           struct ubus_request_data *req, const char *method,
                           struct blob_attr *msg)
{
    struct blob_attr *tb[__CONFIG_MAX];
    int try_count = 0; 
    int wait_count = 3;
    const char *apname;
    const char *staname;
    const char *ssid;
    const char *passwd;
    const char *channel;
    const char *security;
    const char *bssid;
    char *crypto;

    char cmd[100];
    blobmsg_parse(connect_policy, __CONFIG_MAX, tb, blob_data(msg), blob_len(msg));

    if (!tb[CONFIG_APNAME]) return UBUS_STATUS_INVALID_ARGUMENT;

    blob_buf_init(&buf, 0);
    apname = blobmsg_data(tb[CONFIG_APNAME]);
    staname = blobmsg_data(tb[CONFIG_STANAME]);
    ssid = blobmsg_data(tb[CONFIG_SSID]);
    passwd = blobmsg_data(tb[CONFIG_PASSWD]);

    channel = blobmsg_data(tb[CONFIG_CHANNEL]);
    security = blobmsg_data(tb[CONFIG_SECURITY]); 

    crypto = strstr(security, "/");
    if (crypto) {
        *crypto = '\0';
        crypto++;
    }
    wifi_site_survey(apname,NULL,0);

    wifi_repeater_start(apname, staname, channel, ssid, passwd, security, crypto);

    /*ifconfig staname down*/
    snprintf(cmd, lengthof(cmd) - 1, "ifconfig  %s down", staname);
    system(cmd);

    /*ifconfig staname down*/
    snprintf(cmd, lengthof(cmd) - 1, "ifconfig  %s  up", staname);
    system(cmd);


    /*use uci set ssid*/
    snprintf(cmd, lengthof(cmd) - 1, "uci set wireless.sta.ApCliSsid=%s", ssid);
    system(cmd);

     /*use uci set key*/
    snprintf(cmd, lengthof(cmd) - 1, "uci set wireless.sta.ApCliWPAPSK=%s", passwd);
    system(cmd);

     /*uci commit*/
    snprintf(cmd, lengthof(cmd) - 1, "uci commit");
    system(cmd);


     /*udhcpc -i apcli0*/
    snprintf(cmd, lengthof(cmd) - 1, "udhcpc -n -q -i apcli0");
    system(cmd);

    while (wait_count--) {
        if (isStaGetIP(staname)) {
             blobmsg_add_string(&buf, "result", "success");
             break;
        }
        sleep(1);
    }
    if (wait_count == -1) {
        blobmsg_add_string(&buf, "result", "failed");
    }

    ubus_send_reply(ctx, req, buf.head);
    return UBUS_STATUS_OK;
}