mirror of https://github.com/hak5/openwrt.git
parent
5fcf2e5c8c
commit
894e2f118e
|
@ -112,6 +112,64 @@ static int nvram_disabled(char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Quarter dBm units to mW
|
||||||
|
* Table starts at QDBM_OFFSET, so the first entry is mW for qdBm=153
|
||||||
|
* Table is offset so the last entry is largest mW value that fits in
|
||||||
|
* a uint16.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define QDBM_OFFSET 153
|
||||||
|
#define QDBM_TABLE_LEN 40
|
||||||
|
|
||||||
|
/* Smallest mW value that will round up to the first table entry, QDBM_OFFSET.
|
||||||
|
* Value is ( mW(QDBM_OFFSET - 1) + mW(QDBM_OFFSET) ) / 2
|
||||||
|
*/
|
||||||
|
#define QDBM_TABLE_LOW_BOUND 6493
|
||||||
|
|
||||||
|
/* Largest mW value that will round down to the last table entry,
|
||||||
|
* QDBM_OFFSET + QDBM_TABLE_LEN-1.
|
||||||
|
* Value is ( mW(QDBM_OFFSET + QDBM_TABLE_LEN - 1) + mW(QDBM_OFFSET + QDBM_TABLE_LEN) ) / 2.
|
||||||
|
*/
|
||||||
|
#define QDBM_TABLE_HIGH_BOUND 64938
|
||||||
|
|
||||||
|
static const uint16 nqdBm_to_mW_map[QDBM_TABLE_LEN] = {
|
||||||
|
/* qdBm: +0 +1 +2 +3 +4 +5 +6 +7 */
|
||||||
|
/* 153: */ 6683, 7079, 7499, 7943, 8414, 8913, 9441, 10000,
|
||||||
|
/* 161: */ 10593, 11220, 11885, 12589, 13335, 14125, 14962, 15849,
|
||||||
|
/* 169: */ 16788, 17783, 18836, 19953, 21135, 22387, 23714, 25119,
|
||||||
|
/* 177: */ 26607, 28184, 29854, 31623, 33497, 35481, 37584, 39811,
|
||||||
|
/* 185: */ 42170, 44668, 47315, 50119, 53088, 56234, 59566, 63096
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned char mw_to_qdbm(uint16 mw)
|
||||||
|
{
|
||||||
|
char qdbm;
|
||||||
|
int offset;
|
||||||
|
uint mw_uint = mw;
|
||||||
|
uint boundary;
|
||||||
|
|
||||||
|
/* handle boundary case */
|
||||||
|
if (mw_uint <= 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
offset = QDBM_OFFSET;
|
||||||
|
|
||||||
|
/* move mw into the range of the table */
|
||||||
|
while (mw_uint < QDBM_TABLE_LOW_BOUND) {
|
||||||
|
mw_uint *= 10;
|
||||||
|
offset -= 40;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (qdbm = 0; qdbm < QDBM_TABLE_LEN-1; qdbm++) {
|
||||||
|
boundary = nqdBm_to_mW_map[qdbm] + (nqdBm_to_mW_map[qdbm+1] - nqdBm_to_mW_map[qdbm])/2;
|
||||||
|
if (mw_uint < boundary) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
qdbm += (unsigned char)offset;
|
||||||
|
|
||||||
|
return(qdbm);
|
||||||
|
}
|
||||||
|
|
||||||
static int bcom_ioctl(int skfd, char *ifname, int cmd, void *buf, int len)
|
static int bcom_ioctl(int skfd, char *ifname, int cmd, void *buf, int len)
|
||||||
{
|
{
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
@ -523,6 +581,12 @@ static void setup_bcom_common(int skfd, char *ifname)
|
||||||
buf[3] = 0;
|
buf[3] = 0;
|
||||||
bcom_ioctl(skfd, ifname, WLC_SET_COUNTRY, buf, 4);
|
bcom_ioctl(skfd, ifname, WLC_SET_COUNTRY, buf, 4);
|
||||||
|
|
||||||
|
if (v = nvram_get(wl_var("txpwr"))) {
|
||||||
|
val = atoi(v);
|
||||||
|
val = mw_to_qdbm(val);
|
||||||
|
bcom_set_int(skfd, ifname, "qtxpower", val);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set other options */
|
/* Set other options */
|
||||||
val = nvram_enabled(wl_var("lazywds"));
|
val = nvram_enabled(wl_var("lazywds"));
|
||||||
bcom_ioctl(skfd, ifname, WLC_SET_LAZYWDS, &val, sizeof(val));
|
bcom_ioctl(skfd, ifname, WLC_SET_LAZYWDS, &val, sizeof(val));
|
||||||
|
|
Loading…
Reference in New Issue