Exemple #1
0
int netcfg_wireless_set_essid(struct debconfclient *client, char *iface, char *priority)
{
    wireless_config wconf;
    int choose_ret;

    iw_get_basic_config(wfd, iface, &wconf);

select_essid:
    choose_ret = netcfg_wireless_show_essids(client, iface, priority);

    if (choose_ret == GO_BACK) {
        return GO_BACK;
    }

    if (choose_ret == ENTER_MANUALLY) {
        int manually_ret = netcfg_wireless_choose_essid_manually(client, iface);

        if (manually_ret == GO_BACK) {
            goto select_essid;
        }
    }


    /* Something like:
     * - choose essid
     * - if manual, go to manual (use what is already there)
     *      - if manual = go_back, go back to choose essid
     * - set config
     */

    fprintf(stderr, "%d\n", IW_ESSID_MAX_SIZE);

    fprintf(stderr, "%s\n%d\n%d\n", wconf.essid, wconf.has_essid,
            wconf.essid_on);

    fprintf(stderr, "%s\n", essid);


    return 0;
}
Exemple #2
0
int netcfg_wireless_set_essid(struct debconfclient *client, struct netcfg_interface *interface)
{
    wireless_config wconf;
    int choose_ret;

select_essid:
    iw_get_basic_config(wfd, interface->name, &wconf);

    choose_ret = netcfg_wireless_show_essids(client, interface);

    if (choose_ret == GO_BACK) {
        return GO_BACK;
    }

    if (choose_ret == ENTER_MANUALLY) {
        if (netcfg_wireless_choose_essid_manually(client, interface,
                "netcfg/wireless_essid") == GO_BACK) {
            goto select_essid;
        }
    }

    return 0;
}
Exemple #3
0
int netcfg_wireless_show_essids(struct debconfclient *client, struct netcfg_interface *interface)
{
    wireless_scan_head network_list;
    wireless_config wconf;
    char *buffer;
    int essid_list_len = 1;

    iw_get_basic_config (wfd, interface->name, &wconf);
    interface_up(interface->name);

    if (iw_scan(wfd, interface->name, iw_get_kernel_we_version(),
                &network_list) >= 0 ) {
        wireless_scan *network;

        di_info("Scan of wireless interface %s succeeded.", interface->name);

        /* Determine the actual length of the buffer. */
        for (network = network_list.result; network; network =
                    network->next) {
            if (!exists_in_network_list(network_list, network)) {
                essid_list_len += (strlen(network->b.essid) + 2);
            }
        }
        /* Buffer initialization. */
        buffer = malloc(essid_list_len * sizeof(char));
        if (buffer == NULL) {
            /* Error in memory allocation. */
            di_warning("Unable to allocate memory for network list buffer.");
            return ENTER_MANUALLY;
        }
        strcpy(buffer, "");

        /* Create list of available ESSIDs. */
        for (network = network_list.result; network; network = network->next) {
            if (!exists_in_network_list(network_list, network)) {
                strcat(buffer, network->b.essid);
                strcat(buffer, ", ");
            }
        }

        /* Asking the user. */
        debconf_capb(client, "backup");
        debconf_subst(client, "netcfg/wireless_show_essids", "essid_list", buffer);
        debconf_fset(client, "netcfg/wireless_show_essids", "seen", "false");
        debconf_input(client, "high", "netcfg/wireless_show_essids");

        if (debconf_go(client) == CMD_GOBACK) {
            debconf_fset(client, "netcfg/wireless_show_essids", "seen",
                         "false");
            free_network_list(&network_list.result);
            free(buffer);

            return GO_BACK;
        }

        debconf_get(client, "netcfg/wireless_show_essids");

        /* User wants to enter an ESSID manually. */
        if (strcmp(client->value, "manual") == 0) {
            free_network_list(&network_list.result);
            free(buffer);

            return ENTER_MANUALLY;
        }

        /* User has chosen a network from the list, need to find which one and
         * get its cofiguration. */
        for (network = network_list.result; network; network = network->next) {
            if (strcmp(network->b.essid, client->value) == 0) {
                wconf = network->b;
                interface->essid = strdup(network->b.essid);
                break;
            }
        }

        /* Free the network list. */
        free_network_list(&network_list.result);
        free(buffer);
    }
    else {
        /* Go directly to choosing manually, use the wireless_essid_again
         * question. */
        if (netcfg_wireless_choose_essid_manually(client, interface,
                "netcfg/wireless_essid_again") == GO_BACK) {

            return GO_BACK;
        }

        return 0;
    }

    iw_set_basic_config(wfd, interface->name, &wconf);
    interface_down(interface->name);

    di_info("Network chosen: %s. Proceeding to connect.", interface->essid);

    return 0;
}