Introdução aos Sistemas Operacionais/Exemplo de Drivers USB em Linux: Adaptador Wireless

Objetivo geral editar

Realizar um estudo de caso, analisando o funcionamento do driver usb para Linux.

Objetivos específicos editar

Produzir um artigo sobre o driver para Linux do adaptador wireless ENUWI-N3 para o curso de Ciência da Computação da UFG (Universidade Federal de Goiás) através de um trabalho da disciplina de Sistemas Operacionais 2, ministrado pelo Professor Marcelo Akira Inuzuka.

Informações gerais editar

  • Grupo
    • Luíla Moraes de Oliveira
    • Arthur Henrique Guimarães de Oliveira
    • Paulo Júnior do Nascimento Lima
    • Danilo Inácio Souza Resende
  • Sistema Operacional Linux testado: Debian/Ubuntu
  • Identificação do driver analisado:
    • ModelName: RT2870 Wireless Lan Linux Driver
    • Driver lName: rt2870.o/rt2870.ko
    • Supporting Kernel: linux kernel 2.4 and 2.6 series.
    • Tested in: Redhat 7.3 or later.
    • Ralink Hardware: Ralink 802.11n Wireless LAN Card.
    • Descrição: A linux device driver for Ralink RT2870 USB ABGN WLAN Card.
  • filename: rt2870sta.ko
  • version: 2.4.0.0
  • license: GPL
  • author: Paul Lin <paul_lin@ralinktech.com>
  • Em distribuições como Ubuntu, esse módulo já vem nativo no sistema porém é uma versão anterior, versão 2.0.1.0

Configuração do Driver editar

O driver RT2870 pode ser configurado via as seguintes interfaces, i.e. o comando (i)"iwconfig", o comando (ii)"iwpriv", e pelo arquivo de configuração (iii).

  • i) iwconfig acompanha o Kernel Linux.
  • ii) iwpriv possui uma descrição completa no arquivo "iwpriv_usage.txt" que acompanha o driver RT2870.
  • iii) é possível modificar o arquivo de configuração "RT2870STA.dat" em /etc/Wireless/RT2870STA/RT2870STA.dat.

Conteúdo editar

Carga (load ou init) editar

  • Processo de carga do módulo

Depois de compilado, o código gera um módulo: rt2870sta.ko

Para carregar digite no terminal como super-usuário:

 # insmod rt2870sta.ko

A carga do módulo acontece nas seguintes funções: (usb_main_dev.c linha:394)

// Init driver module
// Init driver module
INT __init rtusb_init(void)
{
	printk("rtusb init --->\n");   
	return usb_register(&rtusb_driver);
}

// Deinit driver module
VOID __exit rtusb_exit(void)
{
	usb_deregister(&rtusb_driver);	
	printk("<--- rtusb exit\n");
}

module_init(rtusb_init);
module_exit(rtusb_exit);

//Onde também ocorre o "registro" dessa struct: rtusb_driver

struct usb_driver rtusb_driver = {
                name:"rt2870",
                probe:rtusb_probe,
                disconnect:rtusb_disconnect,
                id_table:rtusb_dev_id,
        };
  • Parâmetros que podem ser passados na carga do módulo:
    • É possível passar como parâmetro para o modulo na sua carga o endereço MAC.
  • Como passar uma parâmetro para o módulo:
    • Para passar um parâmetro para o módulo basta seguir o exemplo:
       # insmod rt2870sta.ko mac=<XX:XX:XX:XX:XX:XX>
      



Reconhecimento ou detecção (probe) editar

  • Quais dispositivos podem ser reconhecidos?
    • USB: 0411:00E8 MelCo., Inc. Buffalo WLI-UC-G300N Wireless LAN Adapter
    • USB: 0471:200F Philips (or NXP) 802.11n Wireless Adapter
    • USB: 04BB:0945 I-O Data Device, Inc. WN-GDN/US3 Wireless LAN Adapter
    • USB: 04BB:0947 I-O Data Device, Inc. WN-G150U Wireless LAN Adapter
    • USB: 04BB:0948 I-O Data Device, Inc. WN-G300U Wireless LAN Adapter
    • USB: 04E8:2018 Samsung Electronics Co., Ltd WIS09ABGN LinkStick Wireless LAN Adapter
    • USB: 050D:8053 Belkin Components F5D8053 N Wireless USB Adapter v1000/v4000 [Ralink RT2870]
    • USB: 050D:805C Belkin Components F5D8053 N Wireless Adapter v3000 [Ralink RT2870]
    • USB: 050D:815C Belkin Components F5D8053 N Wireless USB Adapter v3000 [Ralink RT2870]
    • ** USB: 050D:825B Belkin Components F5D8055 N+ Wireless Adapter v2000 [Ralink RT3070]
    • USB: 050D:935B Belkin Components F6D4050 N150 Enhanced Wireless Network Adapter v2000 [Ralink RT3070]
    • USB: 0586:3416 ZyXEL Communications Corp. NWD-210N 802.11b/g/n-draft wireless adapter
    • USB: 0789:0162 Logitec Corp. LAN-WN22/U2 Wireless LAN Adapter
    • USB: 0789:0163 Logitec Corp. LAN-WN12/U2 Wireless LAN Adapter
    • USB: 0789:0164 Logitec Corp. LAN-W150/U2M Wireless LAN Adapter
    • USB: 0789:0166 Logitec Corp. LAN-W300N/U2 Wireless LAN Adapter
    • USB: 07AA:002F Corega K.K. CG-WLUSB2GNL
    • USB: 07AA:003C Corega K.K. CG-WLUSB2GNL
    • USB: 07AA:003F Corega K.K. CG-WLUSB300AGN
    • USB: 07B8:2770 D-Link Corp. 802.11n/b/g Mini Wireless LAN USB2.0 Adapter
    • USB: 07B8:2870 D-Link Corp. 802.11n/b/g Wireless LAN USB2.0 Adapter
    • USB: 07B8:3070 D-Link Corp. 802.11n/b/g Mini Wireless LAN USB2.0 Adapter
    • USB: 07B8:3071 D-Link Corp. 802.11n/b/g Mini Wireless LAN USB2.0 Adapter
    • USB: 07B8:3072 D-Link Corp. 802.11n/b/g Mini Wireless LAN USB2.0 Adapter
    • USB: 07D1:3C09 D-Link System DWA-140 RangeBooster N Adapter(rev.B1) [Ralink RT2870]
    • USB: 07D1:3C0A D-Link System DWA-140 RangeBooster N Adapter(rev.B2) [Ralink RT2870]
    • USB: 07D1:3C0D D-Link System DWA-125 Wireless N 150 Adapter(rev.A1) [Ralink RT2870]
    • USB: 07D1:3C0E D-Link System WUA-2340 USB Adapter(rev.B)
    • USB: 07D1:3C0F D-Link System AirPlus G DWL-G122 Wireless Adapter(rev.E) [Ralink RT2870]
    • USB: 07D1:3C11 D-Link System DWA-160 Xtreme N Dual Band USB Adapter(rev.B) [Ralink RT2870]
    • USB: 07D1:3C16 D-Link System DWA-125 Wireless N 150 Adapter(rev.A2) [Ralink RT2870]
    • USB: 07D1:3C17 D-Link System (Device name unknown)
    • USB: 07FA:7712 Draytek (Device name unknown)
    • USB: 083A:6618 Accton Technology Corp. 802.11n Wireless Adapter
    • USB: 083A:7511 Accton Technology Corp. Arcadyan 802.11N Wireless Adapter
    • USB: 083A:7512 Accton Technology Corp. Arcadyan 802.11N Wireless Adapter
    • USB: 083A:7522 Accton Technology Corp. Arcadyan 802.11N Wireless Adapter
    • USB: 083A:8522 Accton Technology Corp. Arcadyan 802.11N Wireless Adapter
    • USB: 083A:A618 Accton Technology Corp. SMCWUSBS-N EZ Connect N Draft 11n Wireless Adapter [Ralink RT2870]
    • USB: 083A:A701 Accton Technology Corp. SMCWUSBS-N3 EZ Connect N Wireless Adapter [Ralink RT3070]
    • USB: 083A:A702 Accton Technology Corp. (Device name unknown)
    • USB: 083A:A703 Accton Technology Corp. (Device name unknown)
    • USB: 083A:B522 Accton Technology Corp. SMCWUSBS-N2 EZ Connect N Wireless Adapter [Ralink RT2870]
    • USB: 0B05:1731 ASUSTek Computer, Inc. 802.11n Network Adapter
    • USB: 0B05:1732 ASUSTek Computer, Inc. 802.11n Network Adapter
    • USB: 0B05:1742 ASUSTek Computer, Inc. 802.11n Network Adapter
    • USB: 0B05:1784 ASUSTek Computer, Inc. USB-N13 802.11n Network Adapter [Ralink RT2870]
    • USB: 0CDE:0022 Z-Com 802.11b/g/n Wireless Network Adapter
    • USB: 0CDE:0025 Z-Com 802.11b/g/n USB Wireless Network Adapter
    • USB: 0DB0:3820 Micro Star International (Device name unknown)
    • USB: 0DB0:3821 Micro Star International (Device name unknown)
    • USB: 0DB0:3822 Micro Star International (Device name unknown)
    • USB: 0DB0:3870 Micro Star International (Device name unknown)
    • USB: 0DB0:3871 Micro Star International (Device name unknown)
    • USB: 0DB0:6899 Micro Star International 802.11bgn 1T1R Mini Card Wireless Adapter
    • USB: 0DB0:821A Micro Star International (Device name unknown)
    • USB: 0DB0:822A Micro Star International (Device name unknown)
    • USB: 0DB0:822B Micro Star International (Device name unknown)
    • USB: 0DB0:822C Micro Star International (Device name unknown)
    • USB: 0DB0:870A Micro Star International (Device name unknown)
    • USB: 0DB0:871A Micro Star International (Device name unknown)
    • USB: 0DB0:871B Micro Star International (Device name unknown)
    • USB: 0DB0:871C Micro Star International (Device name unknown)
    • USB: 0DB0:899A Micro Star International (Device name unknown)
    • USB: 0DF6:0017 Sitecom Europe B.V. WL-182 Wireless-N Network USB Card
    • USB: 0DF6:002B Sitecom Europe B.V. WL-188 Wireless Network 300N USB Adapter
    • USB: 0DF6:002C Sitecom Europe B.V. WL-301 Wireless Network 300N USB Adapter
    • USB: 0DF6:002D Sitecom Europe B.V. WL-302 Wireless Network 300N USB dongle
    • USB: 0DF6:0039 Sitecom Europe B.V. WL-315 Wireless-N USB Adapter
    • USB: 0DF6:003E Sitecom Europe B.V. WL-343 Wireless USB Adapter 150N X1
    • USB: 0DF6:003F Sitecom Europe B.V. WL-608 Wireless USB Adapter 54g
    • USB: 0DF6:0042 Sitecom Europe B.V. WL-345 Wireless USB adapter 300N X3
    • USB: 0DF6:0047 Sitecom Europe B.V. WL-352v1 Wireless USB Adapter 300N 002
    • USB: 0DF6:0048 Sitecom Europe B.V. WL-349v1 Wireless USB Adapter 150N 002
    • USB: 0E66:0001 Hawking Technologies HWUN1 Hi-Gain Wireless-300N Adapter w/ Upgradable Antenna [Ralink RT2870]
    • USB: 0E66:0003 Hawking Technologies HWDN1 Hi-Gain Wireless-300N Dish Adapter [Ralink RT2870]
    • USB: 100D:9031 Netopia, Inc. Motorola 802.11n Dualband USB Wireless Adapter
    • USB: 1044:800B Chu Yuen Enterprise Co., Ltd GN-WB30N 802.11n WLAN Card
    • USB: 1044:800D Chu Yuen Enterprise Co., Ltd GN-WB32L 802.11n USB WLAN Card
    • USB: 129B:1828 CyberTAN Technology Gigaset USB Adapter 300
    • USB: 13D3:3247 IMC Networks 802.11 n/g/b Wireless LAN Adapter
    • USB: 13D3:3273 IMC Networks 802.11 n/g/b Wireless LAN USB Mini-Card
    • USB: 13D3:3305 IMC Networks (Device name unknown)
    • USB: 13D3:3307 IMC Networks (Device name unknown)
    • USB: 13D3:3321 IMC Networks (Device name unknown)
    • USB: 1482:3C09 (Vendor name unknown) (Device name unknown)
    • USB: 148F:2070 Ralink Technology, Corp. RT2070 Wireless Adapter
    • USB: 148F:2770 Ralink Technology, Corp. RT2770 Wireless Adapter
    • USB: 148F:2870 Ralink Technology, Corp. RT2870 Wireless Adapter
    • USB: 148F:3070 Ralink Technology, Corp. RT2870/RT3070 Wireless Adapter
    • USB: 148F:3071 Ralink Technology, Corp. RT3071 Wireless Adapter
    • USB: 148F:3072 Ralink Technology, Corp. RT3072 Wireless Adapter
    • USB: 14B2:3C06 Ralink Technology, Corp. 802.11n adapter (V1)
    • USB: 14B2:3C07 Ralink Technology, Corp. 802.11n adapter
    • USB: 14B2:3C09 Ralink Technology, Corp. 802.11n adapter
    • USB: 14B2:3C12 Ralink Technology, Corp. (Device name unknown)
    • USB: 14B2:3C23 Ralink Technology, Corp. 802.11n adapter
    • USB: 14B2:3C25 Ralink Technology, Corp. 802.11n adapter
    • USB: 14B2:3C27 Ralink Technology, Corp. rt2870 802.11n WLAN
    • USB: 14B2:3C28 Ralink Technology, Corp. 802.11n adapter (V2)
    • USB: 157E:300E TRENDnet (Device name unknown)
    • USB: 15A9:0006 Gemtek Wireless 11n USB Adapter
    • USB: 15C5:0008 Advance Multimedia Internet Technology Inc. (AMIT) WL532U 802.11g Adapter
    • USB: 1690:0740 Askey Computer Corp. [hex] 802.11n Wireless LAN Card
    • USB: 1737:0070 Linksys WUSB100 RangePlus Wireless USB Adapter
    • USB: 1737:0071 Linksys WUSB600N v1 Dual-Band Wireless-N Network Adapter [Ralink RT2870]
    • USB: 1737:0077 Linksys WUSB54GC v3 802.11g Adapter [Ralink RT2870]
    • USB: 1740:9701 Senao EnGenius 802.11n Wireless USB Adapter
    • USB: 1740:9702 Senao EnGenius 802.11n Wireless USB Adapter
    • USB: 1740:9703 Senao EnGenius 802.11n Wireless USB Adapter
    • USB: 1740:9705 Senao EnGenius 802.11n Wireless USB Adapter
    • USB: 1740:9706 Senao EnGenius 802.11n Wireless USB Adapter
    • USB: 1740:9707 Senao (Device name unknown)
    • USB: 1740:9708 Senao (Device name unknown)
    • USB: 1740:9709 Senao (Device name unknown)
    • USB: 177F:0302 Sweex (Device name unknown)
    • USB: 18C5:0012 AMIT Technology, Inc. CG-WLUSB10 Corega Wireless USB Adapter
    • USB: 1A32:0304 Quanta Microsystems, Inc. 802.11n Wireless LAN Card
    • USB: 1D4D:000C PEGATRON CORPORATION Ralink RT3070 802.11b/g/n Wireless Lan USB Device
    • USB: 1D4D:000E PEGATRON CORPORATION Ralink RT3070 802.11b/g/n Wireless Lan USB Device
    • USB: 1EDA:2310 AirTies Wireless Networks 802.11n USB Wireless LAN Card
    • USB: 2001:3C09 D-Link Corp. (Device name unknown)
    • USB: 2001:3C0A D-Link Corp. (Device name unknown)
    • USB: 2019:AB25 PLANEX 150N Wireless LAN USB Adapter
    • USB: 2019:ED06 PLANEX 802.11n Wireless LAN Adapter
    • USB: 2019:ED14 PLANEX GW-USMicroN
    • USB: 203D:1480 (Vendor name unknown) (Device name unknown)
    • USB: 203D:14A9 (Vendor name unknown) (Device name unknown)
    • USB: 20B8:8888 (Vendor name unknown) (Device name unknown)
    • USB: 5A57:0280 Zinwell 802.11a/b/g/n USB Wireless LAN Card
    • USB: 5A57:0282 Zinwell 802.11b/g/n USB Wireless LAN Card
    • USB: 5A57:0283 Zinwell 802.11b/g/n USB Wireless LAN Card
    • USB: 5A57:5257 Zinwell Metronic 495257 wifi 802.11ng
    • USB: 7392:7711 Edimax Technology Co., Ltd EW-7711UTn nLite Wireless Adapter [Ralink RT2870]
    • USB: 7392:7717 Edimax Technology Co., Ltd EW-7717UN 802.11n Wireless Adapter [Ralink RT2870]
    • USB: 7392:7718 Edimax Technology Co., Ltd EW-7718UN 802.11n Wireless Adapter [Ralink RT2870]
  • Como se processa a identificação do dispositivo?
    • A identificação do dispositivo é processada da seguinte forma: ...
  • O que ocorre quando o driver não é reconhecido?
    • Quando o driver não é reconhecido .....



Inicialização de estruturas editar

  • Struct usb_driver

Identifica o driver da interface USB para o usbcore (Ele habilita o suporte básico e cria a pasta /proc/bus/usb, onde os periféricos USB ficam acessíveis).

struct usb_driver rtusb_driver = {
                name:"rt2870",
                probe:rtusb_probe,
                disconnect:rtusb_disconnect,
                id_table:rtusb_dev_id,
        };
  • Membros
    • name: O campo name deve ser único entre drivers USB, e deve normalmente ser o mesmo nome do modulo.
    • probe: Chamado para checar se o driver deseja manipular uma interface particular de um dispositivo. Caso esteja, probe retorna zero e usa usb_set_intfdata para associar dados específicos do driver com a interface. Do contrário retorna -ENODEV.
    • disconnect: Chamado quando a interface não está mais acessível. Geralmente isso ocorre quando o dispositivo está sendo desconectado ou o modulo do drive é descarregado.
//chamado quando a interface não está acessível
static void rtusb_disconnect(struct usb_device *dev, void *ptr)
{
	rt2870_disconnect(dev, ((PRTMP_ADAPTER)ptr));
}

//chamado pelo  rtusb_disconnect
static void rt2870_disconnect(struct usb_device *dev, PRTMP_ADAPTER pAd)
{
	DBGPRINT(RT_DEBUG_ERROR, ("rtusb_disconnect: unregister usbnet usb-%s-%s\n",
				dev->bus->bus_name, dev->devpath));
	if (!pAd)
	{
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)	/* kernel 2.4 series */
		while(MOD_IN_USE > 0)
		{
			MOD_DEC_USE_COUNT;
		}
#else
		usb_put_dev(dev);
#endif // LINUX_VERSION_CODE //

		printk("rtusb_disconnect: pAd == NULL!\n");
		return;
	}
	RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);

	// for debug, wait to show some messages to /proc system
	udelay(1);


	RtmpPhyNetDevExit(pAd, pAd->net_dev);

	// FIXME: Shall we need following delay and flush the schedule??
	udelay(1);
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)	/* kernel 2.4 series */
#else
	flush_scheduled_work();
#endif // LINUX_VERSION_CODE //
	udelay(1);

	// free the root net_device
	RtmpOSNetDevFree(pAd->net_dev);

#ifdef RT_CFG80211_SUPPORT
	CFG80211_UnRegister(pAd, pAd->net_dev);
#endif // RT_CFG80211_SUPPORT //

	RtmpRaDevCtrlExit(pAd);

	// libera o uso de uma estrutura do dispositivo USB
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)	/* kernel 2.4 series */
	while(MOD_IN_USE > 0)
	{
		MOD_DEC_USE_COUNT;
	}
#else
	usb_put_dev(dev);
#endif // LINUX_VERSION_CODE //
	udelay(1);

	DBGPRINT(RT_DEBUG_ERROR, (" RTUSB disconnect successfully\n"));
}
    • id_table: Drivers USB usam o ID table para dar suporte ao hotplugging.



Registro do driver (register) editar

O comand lsusb pode ser usado para verificar se o dispositivo foi reconhecido pelo sistema.

# lsusb

O comando dmesg, serve para ver as mensagens que o carregamento do módulo produziu de mensagem.

# dmesg

Assim como o lsmod para saber se o módulo foi carregado corretamente.

# lsmod|grep rt2870sta



Comunicação editar



Finalização editar

Mensagem de remoção: 
[25172.116569] usbcore: deregistering interface driver rt2870
[25172.116682] <--- rtusb exit



Considerações finais editar



Bibliografia/Referências editar