static int
lua_ctl_aclchk(lua_State *L, void *wl, lua_cmd_t *cmd, char *argv)
{
	struct maclist *maclist = (struct maclist *) buf;
	struct maclist *acllist = (struct maclist *) (buf + WLC_IOCTL_MAXLEN);
	uint i, j, max = (WLC_IOCTL_MAXLEN - sizeof(int)) / ETHER_ADDR_LEN;
	struct ether_addr *ea, *tea;
	int ret, val, deauth;

	if ((ret = wlu_get(wl, WLC_GET_MACMODE, &val, sizeof(int))) < 0)
		return ret;

	val = dtoh32(val);

	if (val == 0)
	{
		return 0;
	}

	maclist->count = htod32(max);
	if ((ret = wlu_get(wl, WLC_GET_ASSOCLIST, maclist, WLC_IOCTL_MAXLEN)) < 0)
	{
		return ret;
	}
	maclist->count = dtoh32(maclist->count);

	acllist->count = htod32(max);
	if ((ret = wlu_get(wl, WLC_GET_MACLIST, acllist, WLC_IOCTL_MAXLEN)) < 0)
	{
		return ret;
	}
	acllist->count = dtoh32(maclist->count);

	for (i = 0, ea = maclist->ea; i < maclist->count && i < max; i++, ea++)
	{
		deauth = (val == 2) ? 1 : 0;
		for (j = 0, tea = acllist->ea; j < acllist->count && j < max; j++, tea++)
		{
			if (memcmp(ea, tea, sizeof(struct ether_addr)) == 0)
			{
				deauth = !deauth;
			}
		}
		if (deauth)
		{
			/* No reason code furnished, so driver will use its default */
			ret = wlu_set(wl, WLC_SCB_DEAUTHENTICATE, ea, ETHER_ADDR_LEN);
		}
	}
	return 0;
}
Beispiel #2
0
int wlmEstimatedPowerGet(int *estPower, int chain)
{
	tx_power_t power;
	int mimo;

	memset(&power, 0, sizeof(power));

	if (wlu_get(irh, WLC_CURRENT_PWR, &power, sizeof(power)) < 0) {
		printf("wlmEstimatedPowerGet: %s\n", wlmLastError());
		return FALSE;
	}
	power.flags = dtoh32(power.flags);
	power.chanspec = dtohchanspec(power.chanspec);
	mimo = (power.flags & WL_TX_POWER_F_MIMO);

	/* value returned is in units of quarter dBm, need to multiply by 250 to get milli-dBm */
	if (mimo) {
		*estPower = power.est_Pout[chain] * 250;
	} else {
		*estPower = power.est_Pout[0] * 250;
	}

	if (!mimo && CHSPEC_IS2G(power.chanspec)) {
		*estPower = power.est_Pout_cck * 250;
	}

	return TRUE;
}
Beispiel #3
0
int
wl_get_channels(void *wl, int max, int *len, uint16 *channels)
{
	uint32 chan_buf[WL_NUMCHANNELS + 1];
	wl_uint32_list_t *list;
	int ret;
	uint i;
	int count;

	list = (wl_uint32_list_t *)(void *)chan_buf;
	list->count = htod32(WL_NUMCHANNELS);
	ret = wlu_get(wl, WLC_GET_VALID_CHANNELS, chan_buf, sizeof(chan_buf));
	if (ret < 0)
		return ret;

	count = 0;
	for (i = 0; i < dtoh32(list->count); i++) {
		if (count >= max)
			break;
		channels[count++] = dtoh32(list->element[i]);
	}

	*len = count;
	return ret;
}
static int
lua_get_acllist(lua_State *L, void *wl, lua_cmd_t *cmd, char *argv)
{
	struct maclist *maclist = (struct maclist *) buf;
	uint i, max = (WLC_IOCTL_MAXLEN - sizeof(int)) / ETHER_ADDR_LEN;
	struct ether_addr *ea;
	int ret;

	maclist->count = htod32(max);
	if ((ret = wlu_get(wl, WLC_GET_MACLIST, maclist, WLC_IOCTL_MAXLEN)) < 0)
	{
		return ret;
	}
	maclist->count = dtoh32(maclist->count);
	lua_newtable(L);
	for (i = 0, ea = maclist->ea; i < maclist->count && i < max; i++, ea++)
	{
		lua_newtable(L);

		lua_pushstring(L, wl_ether_etoa(ea));
		lua_setfield(L, -2, "macaddr");

		lua_rawseti(L, -2, i+1);
	}

	return ret;
}
Beispiel #5
0
int wlmIoctlGet(int cmd, void *buf, int len)
{
	if (wlu_get(irh, cmd, buf, len)) {
		printf("wlmIoctlGet: %s\n", wlmLastError());
		return FALSE;
	}
	return TRUE;
}
Beispiel #6
0
int wlmIsAdapterUp(int *up)
{
	/*  Get 'isup' - check if adapter is up */
	up = dtoh32(up);
	if (wlu_get(irh, WLC_GET_UP, up, sizeof(int))) {
		printf("wlmIsAdapterUp: %s\n", wlmLastError());
		return FALSE;
	}

	return TRUE;
}
Beispiel #7
0
/*
 * get named iovar providing both parameter and i/o buffers
 * iovar name is converted to lower case
 */
int
wlu_iovar_getbuf(void* wl, const char *iovar,
	void *param, int paramlen, void *bufptr, int buflen)
{
	int err;

	wl_iovar_mkbuf(iovar, param, paramlen, bufptr, buflen, &err);
	if (err)
		return err;

	return wlu_get(wl, WLC_GET_VAR, bufptr, buflen);
}
Beispiel #8
0
int wl_status(void *wl, int *isAssociated, int biBufferSize, wl_bss_info_t *biBuffer)
{
	int ret;
	struct ether_addr bssid;
	wl_bss_info_t *bi;

	*isAssociated = FALSE;

	if ((ret = wlu_get(wl, WLC_GET_BSSID, &bssid, ETHER_ADDR_LEN)) == 0) {
		/* The adapter is associated. */
		*(uint32*)buf = htod32(WLC_IOCTL_MAXLEN);
		if ((ret = wlu_get(wl, WLC_GET_BSS_INFO, buf, WLC_IOCTL_MAXLEN)) < 0)
			return ret;

		bi = (wl_bss_info_t*)(buf + 4);
		if (dtoh32(bi->version) == WL_BSS_INFO_VERSION ||
		    dtoh32(bi->version) == LEGACY2_WL_BSS_INFO_VERSION ||
		    dtoh32(bi->version) == LEGACY_WL_BSS_INFO_VERSION) {

		    *isAssociated = TRUE;
		    if (bi->length <= (uint32)biBufferSize) {
				memcpy(biBuffer, bi, bi->length);
			}
		    else {
				fprintf(stderr, "buffer too small %d > %d\n",
					bi->length, biBufferSize);
			}
		}
		else
			fprintf(stderr, "Sorry, your driver has bss_info_version %d "
				"but this program supports only version %d.\n",
				bi->version, WL_BSS_INFO_VERSION);
	}

	return 0;
}
static int
lua_get_status(lua_State *L, void *wl, lua_cmd_t *cmd, char *argv)
{
	int ret;
	struct ether_addr bssid;

	if ((ret = wlu_get(wl, WLC_GET_BSSID, &bssid, ETHER_ADDR_LEN)) == 0)
	{
		/* The adapter is associated. */
		lua_pushnumber(L, 1);
	}
	else
	{
		lua_pushnumber(L, 0);
	}

	return 0;
}
Beispiel #10
0
int wlmBssidGet(char *bssid, int length)
{
	struct ether_addr ea;

	if (length != ETHER_ADDR_LEN) {
		printf("wlmBssiGet: bssid requires %d bytes", ETHER_ADDR_LEN);
		return FALSE;
	}

	if (wlu_get(irh, WLC_GET_BSSID, &ea, ETHER_ADDR_LEN) == 0) {
		/* associated - format and return bssid */
		strncpy(bssid, wl_ether_etoa(&ea), length);
	}
	else {
		/* not associated - return empty string */
		memset(bssid, 0, length);
	}

	return TRUE;
}
Beispiel #11
0
int wlmSsidGet(char *ssid, int length)
{
	wlc_ssid_t wlc_ssid;

	if (length < SSID_FMT_BUF_LEN) {
		printf("wlmSsidGet: Ssid buffer too short - %d bytes at least\n",
		SSID_FMT_BUF_LEN);
		return FALSE;
	}

	/* query for 'ssid' */
	if (wlu_get(irh, WLC_GET_SSID, &wlc_ssid, sizeof(wlc_ssid_t))) {
		printf("wlmSsidGet: %s\n", wlmLastError());
		return FALSE;
	}

	wl_format_ssid(ssid, wlc_ssid.SSID, dtoh32(wlc_ssid.SSID_len));

	return TRUE;
}
static int
lua_get_acl(lua_State *L, void *wl, lua_cmd_t *cmd, char *argv)
{
	int ret;
	int val;
	char *str_policy[] = {
		"open",
		"deny",
		"allow"
	};

	if ((ret = wlu_get(wl, WLC_GET_MACMODE, &val, sizeof(int))) < 0)
		return ret;

	val = dtoh32(val);

	lua_pushstring(L, str_policy[val]);	

	return ret;
}
Beispiel #13
0
int wlmGetBandList(WLM_BAND * bands)
{
	unsigned int list[3];
	unsigned int i;

	if (wlu_get(irh, WLC_GET_BANDLIST, list, sizeof(list))) {
		printf("wlmGetBandList: %s\n", wlmLastError());
		return FALSE;
	}

	list[0] = dtoh32(list[0]);
	list[1] = dtoh32(list[1]);
	list[2] = dtoh32(list[2]);

	/* list[0] is count, followed by 'count' bands */

	if (list[0] > 2)
		list[0] = 2;

	for (i = 1, *bands = (WLM_BAND)0; i <= list[0]; i++)
		*bands |= list[i];

	return TRUE;
}
Beispiel #14
0
int wlmDeviceImageRead(char* byteStream, unsigned int len, WLM_IMAGE_TYPE imageType)
{
	srom_rw_t *srt;
	cis_rw_t *cish;
	char buf[WLC_IOCTL_MAXLEN] = {0};
	unsigned int numRead = 0;

	if (byteStream == NULL) {
		printf("wlmDeviceImageRead: Buffer is invalid!\n");
		return FALSE;
	}

	if (len > SROM_MAX) {
	    printf("wlmDeviceImageRead: byteStream should be less than %d bytes!\n", SROM_MAX);
	    return FALSE;
	}

	if (len & 1) {
			printf("wlmDeviceImageRead: Invalid byte count %d, must be even\n", len);
			return FALSE;
	}

	switch (imageType) {
	case WLM_TYPE_SROM:
		if (len < 2*SROM4_WORDS) {
			printf("wlmDeviceImageRead: Buffer not large enough!\n");
			return FALSE;
		}

		srt = (srom_rw_t *)buf;
		srt->byteoff = 0;
		srt->nbytes = htod32(2 * SROM4_WORDS);
		/* strlen("cisdump ") = 9 */
		if (wlu_get(irh, WLC_GET_SROM, buf, 9 + (len < SROM_MAX ? len : SROM_MAX)) < 0) {
			printf("wlmDeviceImageRead: %s\n", wlmLastError());
			return FALSE;
		}
		memcpy(byteStream, buf + 8, srt->nbytes);
		numRead = srt->nbytes;
		break;
	case WLM_TYPE_OTP:
		strcpy(buf, "cisdump");
		/* strlen("cisdump ") = 9 */
		if (wl_get(irh, WLC_GET_VAR, buf, 9  + (len < SROM_MAX ? len : SROM_MAX)) < 0) {
		    printf("wlmDeviceImageRead: %s\n", wlmLastError());
		    return FALSE;
		}

		cish = (cis_rw_t *)buf;
		cish->source = dtoh32(cish->source);
		cish->byteoff = dtoh32(cish->byteoff);
		cish->nbytes = dtoh32(cish->nbytes);

		if (len < cish->nbytes) {
			printf("wlmDeviceImageRead: Buffer not large enough!\n");
			return FALSE;
		}
		memcpy(byteStream, buf + sizeof(cis_rw_t), cish->nbytes);
		numRead = cish->nbytes;
		break;
	case WLM_TYPE_AUTO:
	  numRead = wlmDeviceImageRead(byteStream, len, WLM_TYPE_SROM);
		if (!numRead) {
			numRead = wlmDeviceImageRead(byteStream, len, WLM_TYPE_OTP);
		    printf("wlmDeviceImageRead: %s\n", wlmLastError());
		    return FALSE;
	    }
	    break;
	default:
		printf("wlmDeviceImageRead: Invalid image type!\n");
		return FALSE;
	}
	return numRead;
}
static int
lua_get_stalist(lua_State *L, void *wl, lua_cmd_t *cmd, char *argv)
{
	sta_info_t *sta;
	struct maclist *maclist = (struct maclist *) buf;
	uint i, max = (WLC_IOCTL_MAXLEN - sizeof(int)) / ETHER_ADDR_LEN;
	struct ether_addr *ea;
	int buflen, ret;
	char *param;

	maclist->count = htod32(max);
	if ((ret = wlu_get(wl, WLC_GET_ASSOCLIST, maclist, WLC_IOCTL_MAXLEN)) < 0)
	{
		return ret;
	}
	maclist->count = dtoh32(maclist->count);
	lua_newtable(L);
	for (i = 0, ea = maclist->ea; i < maclist->count && i < max; i++, ea++)
	{
		strcpy(buf, "sta_info");
		buflen = strlen(buf) + 1;
		param = (char *)(buf + buflen);
		memcpy(param, (char*)&ea, ETHER_ADDR_LEN);

		if ((ret = wlu_get(wl, WLC_GET_VAR, buf, WLC_IOCTL_MEDLEN)) < 0)
			return ret;

		/* display the sta info */
		sta = (sta_info_t *)buf;
		sta->flags = dtoh32(sta->flags);

		lua_newtable(L);
		lua_pushstring(L, wl_ether_etoa(ea));
		lua_setfield(L, -2, "macaddr");

		lua_pushstring(L, (sta->flags & WL_STA_N_CAP) ? " 11n" : "11g");
		lua_setfield(L, -2, "mode");

		lua_pushboolean(L, ((sta->flags & WL_STA_PS) != 0));
		lua_setfield(L, -2, "pwr");

		lua_pushnumber(L, sta->RSSI);
		lua_setfield(L, -2, "ccq");

		lua_pushnumber(L, sta->tx_rate);
		lua_setfield(L, -2, "rate");

		lua_pushstring(L, (sta->flags & WL_STA_AUTHO) ? "psk" : "none");
		lua_setfield(L, -2, "auth");

		lua_pushstring(L, (sta->flags & WL_STA_AUTHO) ? "aes" : "none");
		lua_setfield(L, -2, "cipher");

		lua_pushnumber(L, dtoh32(sta->tx_pkts));
		lua_setfield(L, -2, "tx_packets");

		lua_pushnumber(L, dtoh32(sta->rx_ucast_pkts));
		lua_setfield(L, -2, "rx_packets");

		lua_pushnumber(L, sta->idle);
		lua_setfield(L, -2, "inact");

		lua_pushnumber(L, sta->in);
		lua_setfield(L, -2, "assoc_time");

		lua_rawseti(L, -2, i+1);
	}

	return ret;
}