/**
 *  @brief Set frequency/channel
 *
 *  @param dev                  A pointer to net_device structure
 *  @param info                 A pointer to iw_request_info structure
 *  @param fwrq                 A pointer to iw_freq structure
 *  @param extra                A pointer to extra data buf
 *
 *  @return                     0 --success, otherwise fail
 */
static int
woal_set_freq(struct net_device *dev, struct iw_request_info *info,
              struct iw_freq *fwrq, char *extra)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_uap_bss_param sys_cfg, ap_cfg;
    int ret = 0, chan = 0, i = 0;

    ENTER();

    if (MLAN_STATUS_SUCCESS !=
        woal_set_get_sys_config(priv, MLAN_ACT_GET, &ap_cfg)) {
        PRINTM(MERROR, "Error getting AP confiruration\n");
        ret = -EFAULT;
        goto done;
    }
    i = ap_cfg.chan_list.num_of_chan;

    /* Initialize the invalid values so that the correct values below are
       downloaded to firmware */
    woal_set_sys_config_invalid_data(&sys_cfg);

    /* If setting by frequency, convert to a channel */
    if (fwrq->e == 1)
        chan = freq_to_chan(fwrq->m / 100000);
    else
        chan = fwrq->m;
    if (chan > 0 && chan < MAX_CHANNEL)
        sys_cfg.channel = chan;
    else {
        ret = -EINVAL;
        goto done;
    }
    for (i = 0; i < ap_cfg.chan_list.num_of_chan; i++)
        if (ap_cfg.chan_list.chan[i] == chan)
            break;
    if (i == ap_cfg.chan_list.num_of_chan) {
        PRINTM(MERROR, "Channel %d is not supported\n", chan);
        ret = -EINVAL;
        goto done;
    }

    if (MLAN_STATUS_SUCCESS !=
        woal_set_get_sys_config(priv, MLAN_ACT_SET, &sys_cfg)) {
        PRINTM(MERROR, "Error setting AP confiruration\n");
        ret = -EFAULT;
        goto done;
    }

  done:
    LEAVE();
    return ret;
}
Exemple #2
0
int
kernel_interface_channel(const char *ifname, int ifindex)
{
    struct iwreq_subset iwreq;
    int rc;

    memset(&iwreq, 0, sizeof(iwreq));
    strncpy(iwreq.ifr_ifrn.ifrn_name, ifname, IFNAMSIZ);

    rc = ioctl(dgram_socket, SIOCGIWFREQ, &iwreq);
    if(rc >= 0)
        return freq_to_chan(&iwreq.u.freq);
    else
        return -1;
}