Disclaimer: This is for educational purposes only.

Get current country code and txpower:


$ sudo iw reg get

global
country XX: DFS-ETSI
	(2402 - 2482 @ 40), (N/A, 20), (N/A)
	(5170 - 5250 @ 80), (N/A, 20), (N/A), AUTO-BW
	(5250 - 5330 @ 80), (N/A, 20), (0 ms), DFS, AUTO-BW
	(5490 - 5730 @ 160), (N/A, 20), (0 ms), DFS
	(5735 - 5835 @ 80), (N/A, 20), (N/A)


Get interface status:


$ sudo iwconfig

wlanX IEEE 802.11 ESSID:”MySSID”
Mode:Managed Frequency:2.412 GHz Access Point: XX:XX:XX:XX:XX:XX
Bit Rate=6.8 Mb/s Tx-Power=20 dBm
Retry short long limit:2 RTS thr:off Fragment thr:off
Power Management:off
Link Quality=47/70 Signal level=-73 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0

Changing txpower manually:


$ sudo ifconfig wlanX down
$ sudo iw reg set AS
$ sudo iwconfig wlanX txpower 30
$ sudo ifconfig wlanX up

Change wlan to your interface name.

Countries with txpower 30 (2.4GHz):
country code:


AS
BM
BZ
CA
DM
DO
FM
GD
GT
GU
GY
HT
MH
MP
NI
NZ
PR
PW
TW
US
VE
VI

If you cannot set your adapter’s txpower to greater than 30 or your kernel auto set this based on your router settings. We can force it to just use our own rules.

– Backup old wireless-regd and CRDA
– Recompile wireless-regd
– Recompile CRDA
– Install modified wireless-regd and CRDA

Requirements:


$ sudo apt install build-essential python-m2crypto python-pip libgcrypt20 libgcrypt20-dev libnl-3-dev libnl-genl-3-dev

wireless-regd Source Code:
https://mirrors.edge.kernel.org/pub/software/network/wireless-regdb/

Choose the latest version: wireless-regdb-2019.06.03.tar.xz

CRDA source code:
https://mirrors.edge.kernel.org/pub/software/network/crda/

Choose the latest version: crda-3.18.tar.xz
If you want to verify the authenticity of the downloads, you need to install GNUPG, download the signature file and the public key.

Extract the downloaded files:


$ tar xvf crda-3.18.tar.xz
$ tar xvf wireless-regdb-2019.06.03.tar.xz

Modify the db.txt in the wireless-regdb-2019.06.03 folder, you can now change the txpower based on the country code.


# This is the world regulatory domain
country 00:
	(2402 - 2472 @ 40), (20)
	# Channel 12 - 13.
....

Notes:
00 is the default non-assigned country code for the devices. You can change the (20) to >30 depending on your adapter’s advertised power.
The maintainers have changed the country Bolivia (BO) txpower to 20 from 30. We can change this again to be 30 or higher.


...

country BO: DFS-JP
	(2402 - 2482 @ 40), (20)
	(5250 - 5330 @ 80), (30), DFS
	(5735 - 5835 @ 80), (30)

...
  

after:


...

country BO: DFS-JP
	(2402 - 2482 @ 40), (36)
	(5250 - 5330 @ 80), (30), DFS
	(5735 - 5835 @ 80), (30)

...

Locating the system’s crda directory.


$ locate regulatory.bin
/lib/crda/regulatory.bin
/usr/share/man/man5/regulatory.bin.5.gz

On Raspbian (Debian) the crda is located at /lib . We need to back it up before installing the new one.


$ sudo tar -cvpf bacup-crda.tar /lib/crda

Copy the newly generated regulatory.bin to /lib/crda/ and your username.key.pub.pem to your extracted crda-3.18/pubkeys directory.
Edit the crda-3.18/Makefile

Remove the ‘-Werror’ to silence the error:


GEN  keys-gcrypt.c
Trusted pubkeys: pubkeys/username.key.pub.pem
CC   libreg.so
keys-gcrypt.c:53:32: error: ‘keys’ defined but not used [-Werror=unused-const-variable=]
static const struct key_params keys[] = {
                              ^~~~
cc1: all warnings being treated as errors
make: *** [Makefile:119: libreg.so] Error 1

We can now compile and install it. I suggest that you replace the regulatory.bin and libreg.so to /lib/crda instead of running sudo make install.


$ make

Generating regulatory.bin digitally signed by username...
./db2bin.py regulatory.bin db.txt ~/.wireless-regdb-username.key.priv.pem
sha1sum db.txt > sha1sum.txt
Generating regulatory.db
./db2fw.py regulatory.db db.txt
Signing regulatory.db (by username)...



GEN  keys-gcrypt.c
Trusted pubkeys: pubkeys/username.key.pub.pem
CC   libreg.so
keys-gcrypt.c:53:32: warning: ‘keys’ defined but not used [-Wunused-const-variable=]
static const struct key_params keys[] = {
                              ^~~~
CC   crda.o
LD   crda
CC   intersect.o
LD   intersect
CC   regdbdump.o
LD   regdbdump
CC   db2rd.o
LD   db2rd
CC   optimize.o
LD   optimize
CHK  /home/username/wireless-regdb-2019.06.03/regulatory.bin

$ sudo make install

gzip  regulatory.bin.5.gz
gzip  regulatory.db.5.gz
install -m 755 -d //usr/lib/crda
install -m 755 -d //usr/lib/crda/pubkeys
install -m 755 -d //lib/firmware
if [ -f .custom ]; then \
	install -m 644 -t //usr/lib/crda/pubkeys/ username.key.pub.pem; \
fi
install -m 644 -t //usr/lib/crda/pubkeys/ sforshee.key.pub.pem
install -m 644 -t //usr/lib/crda/ regulatory.bin
install -m 644 -t //lib/firmware regulatory.db regulatory.db.p7s
install -m 755 -d //usr/share/man//man5/
install -m 644 -t //usr/share/man//man5/ regulatory.bin.5.gz regulatory.db.5.gz

INSTALL  libreg
INSTALL  libreg-headers
GZIP crda.8
GZIP regdbdump.8
INSTALL  crda
INSTALL  regdbdump
INSTALL  85-regulatory.rules
INSTALL  crda.8.gz
INSTALL  regdbdump.8.gz

Change directory to crda-3.18, edit the Makefile and specify your regulatory.bin location:
REG_BIN?=/home/username/wireless/crda-3.18/regulatory.bin

Build and Install crda:


$ make

GEN  keys-gcrypt.c
Trusted pubkeys: pubkeys/username.key.pub.pem
CC   libreg.so
keys-gcrypt.c:53:32: warning: ‘keys’ defined but not used [-Wunused-const-variable=]
static const struct key_params keys[] = {
                              ^~~~
CC   crda.o
LD   crda
CC   intersect.o
LD   intersect
CC   regdbdump.o
LD   regdbdump
CC   db2rd.o
LD   db2rd
CC   optimize.o
LD   optimize
CHK  /home/username/crda-3.18/regulatory.bin

$ sudo make install

INSTALL  libreg
INSTALL  libreg-headers
GZIP crda.8
GZIP regdbdump.8
INSTALL  crda
INSTALL  regdbdump
INSTALL  85-regulatory.rules
INSTALL  crda.8.gz
INSTALL  regdbdump.8.gz

Reboot your system, issue the iw reg set txpower 30* to your interface and check it with iwconfig.
Enjoy!



wlanX     IEEE 802.11  ESSID:"SampleSSID"
          Mode:Managed  Frequency:2.412 GHz  Access Point: XX:XX:XX:XX:XX:XX
          Bit Rate=67 Mb/s   Tx-Power=36 dBm
          Retry short  long limit:2   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=63/70  Signal level=-43 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

References:
https://askubuntu.com/questions/597546/iwconfig-wlan0-txpower-30mw-not-working
https://null-byte.wonderhowto.com/how-to/ultimate-guide-upping-tx-power-kali-linux-2-0-0168325/

How to increase TX Power Signal Strength of WiFi