Riding the micro wave signal (wpa_supplicant)
¿En alguna ocasión han necesitado unirse a una red wireless desde linea de comandos y pensaron que era algo imposible?
Hace unos días tuve la necesidad de asociar mi dispositivo wireless con una red inalámbrica desde linea de comandos, hace mucho tiempo lo había hecho pero no recordaba exactamente como, el problema aquí fue que la instalación de NanoBSD que tengo en mi maquina Alix no tenia las paginas del manual instaladas, (tengo otra memoria CF de 2G disponible pero no he tenido tiempo de crear la imagen), así es que me instale el FreeBSD en una maquina virtual en la laptop y leyendo y leyendo lo hice de la siguiente forma:
Editamos el archivo /etc/wpa_supplicant.conf
NanoBSD# ee /etc/wpa_supplicant.conf
network={
ssid=”MyHappyNet”
scan_ssid=0
mode=0
auth_alg=OPEN
key_mgmt=NONE
wep_tx_keyidx=0
wep_key0=2218972080
}
Donde:
- ssid es el nombre de la red
- scan_ssid es la técnica con la que wpa_supplicant escaneara las señales para buscar la red inalámbrica, 0 quiere decir scan mediante broadcast.
- mode con este parámetro indicamos: 0 = modo infraestructura (nos conectaremos a un AP), 1 = adhoc
- auth_alg algoritmo utilizado para el intercambio de claves, usaremos OPEN pero podría ser SHARED
- key_mgmt lo ponemos a NONE para indicar que nos autentificaremos mediante una clave wep
- wep_key0 especificamos la clave wep
Teniendo todo esto configurado guardamos el archivo y ejecutamos:
NanoBSD# wpa_supplicant -i ath0 -d -c /etc/wpa_supplicant.conf Initializing interface 'ath0' conf '/etc/wpa_supplicant.conf' driver 'default' ctrl_interface 'N/A' bridge 'N/A' Configuration file '/etc/wpa_supplicant.conf' -> '/etc/wpa_supplicant.conf' Reading configuration file '/etc/wpa_supplicant.conf' ctrl_interface='/var/run/wpa_supplicant' ctrl_interface_group='wheel' (DEPRECATED) Priority group 0 id=0 ssid='MyHappyNet' Initializing interface (2) 'ath0' EAPOL: SUPP_PAE entering state DISCONNECTED EAPOL: KEY_RX entering state NO_KEY_RECEIVE EAPOL: SUPP_BE entering state INITIALIZE EAP: EAP entering state DISABLED EAPOL: External notification - portEnabled=0 EAPOL: External notification - portValid=0 Own MAC address: 00:0c:6d:da:aa:70 wpa_driver_bsd_set_wpa: enabled=1 wpa_driver_bsd_set_wpa_internal: wpa=3 privacy=1 wpa_driver_bsd_del_key: keyidx=0 wpa_driver_bsd_del_key: keyidx=1 wpa_driver_bsd_del_key: keyidx=2 wpa_driver_bsd_del_key: keyidx=3 wpa_driver_bsd_set_countermeasures: enabled=0 wpa_driver_bsd_set_drop_unencrypted: enabled=1 Setting scan request: 0 sec 100000 usec ctrl_interface_group=0 (from group name 'wheel') Added interface ath0 State: DISCONNECTED -> SCANNING Starting AP scan (broadcast SSID) Trying to get current scan results first without requesting a new scan to speed up initial association Received 0 bytes of scan results (0 BSSes) Scan results: 0 Selecting BSS from priority group 0 Try to find WPA-enabled AP Try to find non-WPA AP . . . . Automatic auth_alg selection: 0x1 Overriding auth_alg selection: 0x1 wpa_driver_bsd_set_auth_alg alg 0x1 authmode 1 WPA: clearing AP WPA IE WPA: clearing AP RSN IE WPA: clearing own WPA/RSN IE No keys have been configured - skip key clearing wpa_driver_bsd_set_key: alg=WEP addr=ff:ff:ff:ff:ff:ff key_idx=0 set_tx=1 seq_len=0 key_len=5 wpa_driver_bsd_set_drop_unencrypted: enabled=1 State: SCANNING -> ASSOCIATING wpa_driver_bsd_associate: ssid 'MyHappyNet' wpa ie len 0 pairwise 1 group 1 key mgmt 2 wpa_driver_bsd_associate: set PRIVACY 1 Setting authentication timeout: 10 sec 0 usec EAPOL: External notification - portControl=ForceAuthorized State: ASSOCIATING -> ASSOCIATED Associated to a new BSS: BSSID=01:13:84:92:44:69 Associated with 01:13:84:92:44:69 WPA: Association event - clear replay counter EAPOL: External notification - portEnabled=0 EAPOL: External notification - portValid=0 EAPOL: External notification - portEnabled=1 EAPOL: SUPP_PAE entering state S_FORCE_AUTH EAPOL: SUPP_BE entering state IDLE Cancelling authentication timeout State: ASSOCIATED -> COMPLETED CTRL-EVENT-CONNECTED - Connection to 01:13:84:92:44:69 completed (auth) [id=0 id_str=] Cancelling scan request
donde:
- -i especifica la interfaz de red a usar.
- -d Ejecuta wpa_supplicant en modo debug para que podamos ver los mensajes.
- -c Especifica el archivo de conflagración que tendrá que utilizar wpa_supplicant.
Si todo sale bien veremos el mensjae State: ASSOCIATED -> COMPLETED en la salida del comando wpa_supplicant que ejecutamos, y ya podremos obtener una ip del dhcpd que ejecuta el AP ejecutando el siguiente comando:
NanoBSD# dhclient ath0 DHCPDISCOVER on ath0 to 255.255.255.255 port 67 interval 4 DHCPOFFER from 192.168.1.254 DHCPREQUEST on ath0 to 255.255.255.255 port 67 DHCPACK from 192.168.1.254 bound to 192.168.1.74 -- renewal in 43200 seconds. myipod# ping www.google.com PING www.l.google.com (74.125.65.103): 56 data bytes 64 bytes from 74.125.65.103: icmp_seq=0 ttl=53 time=78.176 ms 64 bytes from 74.125.65.103: icmp_seq=1 ttl=53 time=76.772 ms 64 bytes from 74.125.65.103: icmp_seq=2 ttl=53 time=70.170 ms 64 bytes from 74.125.65.103: icmp_seq=3 ttl=53 time=77.684 ms ^C --- www.l.google.com ping statistics --- 4 packets transmitted, 4 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 70.170/75.701/78.176/3.233 ms NanoBSD#
para que todo esto funcione a momento de reiniciar lo agregamos al archivo /etc/rc.conf de la siguiente forma:
ifconfig_ath0=”WPA DHCP”
Reiniciamos los dispositivos de red para ver que todo este correcto:
NanoBSD# /etc/rc.d/netif restart Stopping network:Stopping wpa_supplicant. lo0 vr0 vr1 vr2 ath0 enc0 pfsync0 pflog0. Starting wpa_supplicant. ath0: no link ........ got link DHCPREQUEST on ath0 to 255.255.255.255 port 67 DHCPACK from 192.168.1.254 bound to 192.168.1.64 -- renewal in 43200 seconds.NanoBSD#
En este momento tenemos todo listo y nuestra tarjeta de red wireless asociada al AP