How to access wireless network on Raspberry Pi

Configure wireless network on Raspberry Pi 4.

Inspect ISO 3166 alpha-2 country codes.

$ cat /usr/share/zoneinfo/
# ISO 3166 alpha-2 country codes
# This file is in the public domain, so clarified as of
# 2009-05-17 by Arthur David Olson.
# From Paul Eggert (2015-05-02):
# This file contains a table of two-letter country codes.  Columns are
# separated by a single tab.  Lines beginning with '#' are comments.
# All text uses UTF-8 encoding.  The columns of the table are as follows:
# 1.  ISO 3166-1 alpha-2 country code, current as of
#     ISO 3166-1 N976 (2018-11-06).  See: Updates on ISO 3166-1
# 2.  The usual English name for the coded region,
#     chosen so that alphabetic sorting of subsets produces helpful lists.
#     This is not the same as the English name in the ISO 3166 tables.
# The table is sorted by country code.
# This table is intended as an aid for users, to help them select time
# zone data appropriate for their practical needs.  It is not intended
# to take or endorse any position on legal or territorial claims.
#code	name of country, territory, area, or subdivision
AD	Andorra
AE	United Arab Emirates
AF	Afghanistan
AG	Antigua & Barbuda
AI	Anguilla
AL	Albania
AM	Armenia
AO	Angola
AQ	Antarctica
AR	Argentina
AS	Samoa (American)
AT	Austria
AU	Australia
AW	Aruba
AX	Åland Islands
AZ	Azerbaijan
BA	Bosnia & Herzegovina
BB	Barbados
BD	Bangladesh
BE	Belgium
BF	Burkina Faso
BG	Bulgaria
BH	Bahrain
BI	Burundi
BJ	Benin
BL	St Barthelemy
BM	Bermuda
BN	Brunei
BO	Bolivia
BQ	Caribbean NL
BR	Brazil
BS	Bahamas
BT	Bhutan
BV	Bouvet Island
BW	Botswana
BY	Belarus
BZ	Belize
CA	Canada
CC	Cocos (Keeling) Islands
CD	Congo (Dem. Rep.)
CF	Central African Rep.
CG	Congo (Rep.)
CH	Switzerland
CI	Côte d'Ivoire
CK	Cook Islands
CL	Chile
CM	Cameroon
CN	China
CO	Colombia
CR	Costa Rica
CU	Cuba
CV	Cape Verde
CW	Curaçao
CX	Christmas Island
CY	Cyprus
CZ	Czech Republic
DE	Germany
DJ	Djibouti
DK	Denmark
DM	Dominica
DO	Dominican Republic
DZ	Algeria
EC	Ecuador
EE	Estonia
EG	Egypt
EH	Western Sahara
ER	Eritrea
ES	Spain
ET	Ethiopia
FI	Finland
FJ	Fiji
FK	Falkland Islands
FM	Micronesia
FO	Faroe Islands
FR	France
GA	Gabon
GB	Britain (UK)
GD	Grenada
GE	Georgia
GF	French Guiana
GG	Guernsey
GH	Ghana
GI	Gibraltar
GL	Greenland
GM	Gambia
GN	Guinea
GP	Guadeloupe
GQ	Equatorial Guinea
GR	Greece
GS	South Georgia & the South Sandwich Islands
GT	Guatemala
GU	Guam
GW	Guinea-Bissau
GY	Guyana
HK	Hong Kong
HM	Heard Island & McDonald Islands
HN	Honduras
HR	Croatia
HT	Haiti
HU	Hungary
ID	Indonesia
IE	Ireland
IL	Israel
IM	Isle of Man
IN	India
IO	British Indian Ocean Territory
IQ	Iraq
IR	Iran
IS	Iceland
IT	Italy
JE	Jersey
JM	Jamaica
JO	Jordan
JP	Japan
KE	Kenya
KG	Kyrgyzstan
KH	Cambodia
KI	Kiribati
KM	Comoros
KN	St Kitts & Nevis
KP	Korea (North)
KR	Korea (South)
KW	Kuwait
KY	Cayman Islands
KZ	Kazakhstan
LA	Laos
LB	Lebanon
LC	St Lucia
LI	Liechtenstein
LK	Sri Lanka
LR	Liberia
LS	Lesotho
LT	Lithuania
LU	Luxembourg
LV	Latvia
LY	Libya
MA	Morocco
MC	Monaco
MD	Moldova
ME	Montenegro
MF	St Martin (French)
MG	Madagascar
MH	Marshall Islands
MK	North Macedonia
ML	Mali
MM	Myanmar (Burma)
MN	Mongolia
MO	Macau
MP	Northern Mariana Islands
MQ	Martinique
MR	Mauritania
MS	Montserrat
MT	Malta
MU	Mauritius
MV	Maldives
MW	Malawi
MX	Mexico
MY	Malaysia
MZ	Mozambique
NA	Namibia
NC	New Caledonia
NE	Niger
NF	Norfolk Island
NG	Nigeria
NI	Nicaragua
NL	Netherlands
NO	Norway
NP	Nepal
NR	Nauru
NU	Niue
NZ	New Zealand
OM	Oman
PA	Panama
PE	Peru
PF	French Polynesia
PG	Papua New Guinea
PH	Philippines
PK	Pakistan
PL	Poland
PM	St Pierre & Miquelon
PN	Pitcairn
PR	Puerto Rico
PS	Palestine
PT	Portugal
PW	Palau
PY	Paraguay
QA	Qatar
RE	Réunion
RO	Romania
RS	Serbia
RU	Russia
RW	Rwanda
SA	Saudi Arabia
SB	Solomon Islands
SC	Seychelles
SD	Sudan
SE	Sweden
SG	Singapore
SH	St Helena
SI	Slovenia
SJ	Svalbard & Jan Mayen
SK	Slovakia
SL	Sierra Leone
SM	San Marino
SN	Senegal
SO	Somalia
SR	Suriname
SS	South Sudan
ST	Sao Tome & Principe
SV	El Salvador
SX	St Maarten (Dutch)
SY	Syria
SZ	Eswatini (Swaziland)
TC	Turks & Caicos Is
TD	Chad
TF	French Southern & Antarctic Lands
TG	Togo
TH	Thailand
TJ	Tajikistan
TK	Tokelau
TL	East Timor
TM	Turkmenistan
TN	Tunisia
TO	Tonga
TR	Turkey
TT	Trinidad & Tobago
TV	Tuvalu
TW	Taiwan
TZ	Tanzania
UA	Ukraine
UG	Uganda
UM	US minor outlying islands
US	United States
UY	Uruguay
UZ	Uzbekistan
VA	Vatican City
VC	St Vincent
VE	Venezuela
VG	Virgin Islands (UK)
VI	Virgin Islands (US)
VN	Vietnam
VU	Vanuatu
WF	Wallis & Futuna
WS	Samoa (western)
YE	Yemen
YT	Mayotte
ZA	South Africa
ZM	Zambia
ZW	Zimbabwe

Find your regulatory country code.

$ grep Poland  /usr/share/zoneinfo/
PL	Poland

Ensure that regulatory country code is defined.

$ cat /etc/default/crda 
# Set REGDOMAIN to a ISO/IEC 3166-1 alpha2 country code so that iw(8) may set
# the initial regulatory domain setting for IEEE 802.11 devices which operate
# on this system.
# Governments assert the right to regulate usage of radio spectrum within
# their respective territories so make sure you select a ISO/IEC 3166-1 alpha2
# country code suitable for your location or you may infringe on local
# legislature. See `/usr/share/zoneinfo/' for a table of timezone
# descriptions containing ISO/IEC 3166-1 alpha2 country codes.


Verify regulatory domain.

$ iw reg get
country PL: DFS-ETSI
	(2400 - 2483 @ 40), (N/A, 20), (N/A)
	(5150 - 5250 @ 80), (N/A, 23), (N/A), NO-OUTDOOR, AUTO-BW
	(5250 - 5350 @ 80), (N/A, 20), (0 ms), NO-OUTDOOR, DFS, AUTO-BW
	(5470 - 5725 @ 160), (N/A, 26), (0 ms), DFS
	(5725 - 5875 @ 80), (N/A, 13), (N/A)
	(57000 - 66000 @ 2160), (N/A, 40), (N/A)

country 99: DFS-UNSET
	(2402 - 2482 @ 40), (6, 20), (N/A)
	(2474 - 2494 @ 20), (6, 20), (N/A)
	(5140 - 5360 @ 160), (6, 20), (N/A)
	(5460 - 5860 @ 160), (6, 20), (N/A)

Inspect configuration for Wi-Fi Protected Access client and IEEE 802.1X supplicant.

$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf 
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

Pre-compute PSK entry for network configuration block.

$ wpa_passphrase laboratory.password

Update configuration for Wi-Fi Protected Access client and IEEE 802.1X supplicant.

$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf 
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


Alter SSID scan technique to connect to the hidden network.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


Wireless device can be disabled by the software.

$ sudo rfkill list
0: phy0: Wireless LAN
	Soft blocked: yes
	Hard blocked: no
1: hci0: Bluetooth
	Soft blocked: no
	Hard blocked: no

Enable wireless device.

$ rfkill unblock 0

Ensure that wireless device is enabled.

$ rfkill list
0: phy0: Wireless LAN
	Soft blocked: no
	Hard blocked: no
1: hci0: Bluetooth
	Soft blocked: no
	Hard blocked: no

Restart Wi-Fi Protected Access client and IEEE 802.1X supplicant.

$ systemctl restart wpa_supplicant.service 

Display wireless device status.

$ iw dev wlan0 link
Connected to c1:d2:e3:30:5f:19 (on wlan0)
	freq: 2447
	RX: 3756 bytes (34 packets)
	TX: 7570 bytes (39 packets)
	signal: -42 dBm
	rx bitrate: 2.0 MBit/s
	tx bitrate: 6.0 MBit/s

	bss flags:	short-preamble short-slot-time
	dtim period:	1
	beacon int:	100
$ iwconfig wlan0
wlan0     IEEE 802.11  ESSID:""  
          Mode:Managed  Frequency:2.447 GHz  Access Point: C1:D2:E3:30:5F:19   
          Bit Rate=6 Mb/s   Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:on
          Link Quality=70/70  Signal level=-40 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

Display IP addresses.

$ ip -br a
lo               UNKNOWN ::1/128 
eth0             UP    fe80::b239:d979:3daf:2849/64 
wlan0            UP    fe80::9b63:3d58:e21:aacf/64