From: Felix Fietkau Date: Sat, 19 Nov 2005 00:36:16 +0000 (+0000) Subject: add wl0_txpwr setting to wificonf X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=894e2f118ea101b4c6df7d6624afe582d16e89de;p=openwrt%2Fstaging%2Frmilecki.git add wl0_txpwr setting to wificonf SVN-Revision: 2528 --- diff --git a/openwrt/package/wificonf/wificonf.c b/openwrt/package/wificonf/wificonf.c index f5f43f1b3ec..a93bba3eda3 100644 --- a/openwrt/package/wificonf/wificonf.c +++ b/openwrt/package/wificonf/wificonf.c @@ -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) { struct ifreq ifr; @@ -523,6 +581,12 @@ static void setup_bcom_common(int skfd, char *ifname) buf[3] = 0; 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 */ val = nvram_enabled(wl_var("lazywds")); bcom_ioctl(skfd, ifname, WLC_SET_LAZYWDS, &val, sizeof(val));