static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv)
{
	u32 feat = 0;
	struct nl_msg *msg;

	msg = nlmsg_alloc();
	if (!msg)
		return 0;

	if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES)) {
		nlmsg_free(msg);
		return 0;
	}

	if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0)
		return feat;

	return 0;
}
Exemplo n.º 2
0
int nl80211_unset_ap(struct nl80211_data *ctx)
{
    struct nl_msg *msg = NULL;
    int ret;
    
    if (!ctx) return -1;
    if (ctx->ifindex<0) return -1;

    msg = nlmsg_alloc();
    if (!msg) goto fail;
    if (!nl80211_cmd(ctx, msg, 0, NL80211_CMD_DEL_BEACON)) goto fail;
    if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, ctx->ifindex)) goto fail;
    ret = send_and_recv_msgs(ctx, msg, NULL, NULL);
    if (ret) {
        fprintf(stderr, "nl80211: advanced settings failed: %d (%s)\n", ret, strerror(-ret));
        goto fail;
    } 
    return 0;
fail:
    if (msg) nlmsg_free(msg);
    return -1;

}
Exemplo n.º 3
0
void nl80211_remove_iface(struct nl80211_data *ctx, int ifidx)
{
    struct nl_msg *msg = NULL;

    fprintf(stderr, "nl80211: Remove interface ifindex=%d\n", ifidx);

    msg = nlmsg_alloc();
    if (!msg)
        goto failed;

    if (!nl80211_cmd(ctx, msg, 0, NL80211_CMD_DEL_INTERFACE)) 
        goto failed;

    if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifidx))
        goto failed;

    if (send_and_recv_msgs(ctx, msg, NULL, NULL) == 0)
        return;

failed:
    if (msg) nlmsg_free(msg);
    fprintf(stderr, "failed to remove interface (ifidx=%d)\n", ifidx);
}
Exemplo n.º 4
0
int nl80211_set_ap(struct nl80211_data *ctx)
{
    struct nl_msg *msg = NULL;
    int ret;

    u16   beacon_period = 100;
    u8    beacon_DTIM = 1;
    char* ssid_name = "TEST";
    u8    ssid_sz = strlen(ssid_name);

    int j;
    u8 rates[NL80211_MAX_SUPP_RATES];
    u8 nbBascis = (u8)(sizeof(BASIC_RATES)/sizeof(int));
    
    // format basics rates
    for (j = 0; j<nbBascis; j++) rates[j] = BASIC_RATE(BASIC_RATES[j]);

    //portion of the beacon before the TIM IE
    u8 * head = NULL;
    int  head_sz = 0;
    
    //portion of the beacon after the TIM IE
    u8 * tail = NULL;
    int  tail_sz = 0;

    // BEACON HEAD
    {
        u8 * pos = NULL;        
        packet_element_t macheader = { 0 };
        packet_element_t ssid = { 0 };
        packet_element_t rates = { 0 };
        packet_element_t ds = { 0 };

        head_sz += hostapd_header_beacon(&macheader, ctx->macaddr, beacon_period);
        head_sz += hostapd_eid_ssid(&ssid, ssid_name);
        head_sz += hostapd_eid_supp_rates(&rates);
        head_sz += hostapd_eid_ds_params(&ds);

        head = (u8*)malloc(head_sz); pos = head;
        pos = packet_element_concatnfree(pos, macheader);
        pos = packet_element_concatnfree(pos, ssid);
        pos = packet_element_concatnfree(pos, rates);
        pos = packet_element_concatnfree(pos, ds);

        fhexdump(stderr, "nl80211: Beacon head", head, head_sz);
    }

    // BEACON TAIL
    {
        u8 * pos = NULL;
        packet_element_t rates = { 0 };
        //packet_element_t emilie = { 0 };

        tail_sz += hostapd_eid_ext_rates(&rates);
        //tail_sz += hostapd_eid_emilie(&emilie);

        tail = (u8*)malloc(tail_sz); pos = tail;
        pos = packet_element_concatnfree(pos, rates);
        //pos = packet_element_concatnfree(pos, emilie);

        fhexdump(stderr, "nl80211: Beacon tail", tail, tail_sz);
    }

    // NL80211 BEACON SETTING
    msg = nlmsg_alloc();
    if (!msg) goto fail;
    if (!nl80211_cmd(ctx, msg, 0, NL80211_CMD_NEW_BEACON)) goto fail;
    if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, ctx->ifindex)) goto fail;
    
    if (nla_put(msg, NL80211_ATTR_BEACON_HEAD, head_sz, head)) goto fail;
    if (nla_put(msg, NL80211_ATTR_BEACON_TAIL, tail_sz, tail)) goto fail;
    if (nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, beacon_period)) goto fail;
    if (nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, beacon_DTIM)) goto fail;    
    if (nla_put(msg, NL80211_ATTR_SSID, ssid_sz, ssid_name)) goto fail;
    
    
    if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, NL80211_HIDDEN_SSID_NOT_IN_USE)) goto fail;
    if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) goto fail;
    if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, NL80211_AUTHTYPE_OPEN_SYSTEM)) goto fail;
    if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, NL80211_SMPS_OFF)) goto fail;
    ret = send_and_recv_msgs(ctx, msg, NULL, NULL);
    if (ret) {
        fprintf(stderr, "nl80211: Beacon set failed: %d (%s)\n", ret, strerror(-ret));
        goto fail;
    }

    // NL80211 BSS ADVDANCED SETTING
    msg = nlmsg_alloc();
    if (!msg)
        goto fail;
    if (!nl80211_cmd(ctx, msg, 0, NL80211_CMD_SET_BSS))
        goto fail;
    if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, ctx->ifindex))
        goto fail;
    if (nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, 0))
        goto fail;
    if (nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, 0))
        goto fail;
    if (nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, 1))
        goto fail;
    if (nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, 0))
        goto fail;
    if (nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, 0))
        goto fail;
    if (nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, nbBascis, rates))
       goto fail;;
    ret = send_and_recv_msgs(ctx, msg, NULL, NULL);
    if (ret) {
        fprintf(stderr, "nl80211: advanced settings failed: %d (%s)\n", ret, strerror(-ret));
        goto fail;
    } 

    if (head) free(head);
    if (tail) free(tail);
    return 0;
fail:
    if (msg) nlmsg_free(msg);
    if (head) free(head);
    if (tail) free(tail);
    return -1;
}