TL-WN821N

From Gentoo-en
Jump to: navigation, search

This page is outdated.

Reason given: The code has been integrated into mainline kernel since version 2.6.37, but requires external firmware.

Please pay attention because the contents on this page are no longer up-to-date. This will mostly be because of updated ebuilds. If you encounter any changes while reading it, please edit this page according to the changes.

Introduction

The TL-WN821N is a USB dongle with Atheros chipset, that complies with IEEE 802.11n (Draft 2.0), IEEE 802.11g, and IEEE 802.11b standards. Described setup is done with 2.6.30 gentoo kernel. The configuration is a bit tricky and it not working at full speed.

Kernel Options

During build of drivers, in case you have incorrect kernel setup, it will print an error, showing what you have to change. But generally it is:

File: .config
CONFIG_CFG80211=m
CONFIG_MAC80211=m
CONFIG_NET_SCHED=y

Patch

For driver to build you need to patch a kernel with following patch:

Code: diff -urp linux-2.6.30-gentoo-r4/include/net/genetlink.h linux-2.6.30-gentoo-r4/include/net/genetlink.h
--- linux-2.6.30-gentoo-r4/include/net/genetlink.h      2009-06-10 07:05:27.000000000 +0400
+++ linux-2.6.30-gentoo-r4/include/net/genetlink.h  2009-08-18 02:33:40.466753777 +0400
@@ -27,6 +27,10 @@ struct genl_multicast_group
  * @name: name of family
  * @version: protocol version
  * @maxattr: maximum number of attributes supported
+ * @pre_doit: called before any doit op
+ * @post_doit: called after any doit op
+ * @pre_dumpit: called before any dumpit op
+ * @post_dumpit: called after any dumpit op
  * @attrbuf: buffer to store parsed attributes
  * @ops_list: list of all assigned operations
  * @family_list: family list
@@ -39,6 +43,10 @@ struct genl_family
        char                    name[GENL_NAMSIZ];
        unsigned int            version;
        unsigned int            maxattr;
+       int (*pre_doit)(struct sk_buff *skb, struct genl_info *info);
+       void (*post_doit)(void);
+       int (*pre_dumpit)(void);
+       void (*post_dumpit)(void);
        struct nlattr **        attrbuf;        /* private */
        struct list_head        ops_list;       /* private */
        struct list_head        family_list;    /* private */
Code: diff -urp linux-2.6.30-gentoo-r4/net/netlink/genetlink.c linux-2.6.30-gentoo-r4/net/netlink/genetlink.c
--- linux-2.6.30-gentoo-r4/net/netlink/genetlink.c      2009-06-10 07:05:27.000000000 +0400
+++ linux-2.6.30-gentoo-r4/net/netlink/genetlink.c  2009-08-18 02:41:51.498005864 +0400
@@ -446,8 +446,15 @@ static int genl_rcv_msg(struct sk_buff *
                        return -EOPNOTSUPP;

                genl_unlock();
-               err = netlink_dump_start(genl_sock, skb, nlh,
-                                        ops->dumpit, ops->done);
+               err = 0;
+               if (family->pre_dumpit)
+               err = family->pre_dumpit();
+               if (!err)
+                       err = netlink_dump_start(genl_sock, skb, nlh,
+                               ops->dumpit, ops->done);
+               if (family->post_dumpit)
+                       family->post_dumpit();
+
                genl_lock();
                return err;
        }
@@ -469,7 +476,15 @@ static int genl_rcv_msg(struct sk_buff *
        info.userhdr = nlmsg_data(nlh) + GENL_HDRLEN;
        info.attrs = family->attrbuf;

-       return ops->doit(skb, &info);
+       err = 0;
+       if (family->pre_doit)
+               err = family->pre_doit(skb, &info);
+       if (!err)
+               err = ops->doit(skb, &info);
+       if (family->post_doit)
+               family->post_doit();
+       return err;
+
 }

 static void genl_rcv(struct sk_buff *skb)

Install

Download

First of all you should download and untar the drivers:

Verify check sum:

md5sum Compat-Wireless_ar9170_230209.tar.gz

Untar it:

tar xvf Compat-Wireless_ar9170_230209.tar.gz

Go to directory:

cd compat-wireless-2009-02-22_AR9170_230209

The MD5 for the archive is 8dc6af49103f04fb7589408045ce311a

Patch

You have to apply some patches to the driver as well, for it to build well.

Code: diff -urp compat-wireless-2009-02-22_AR9170_230209/drivers/net/b44.c compat-wireless-2009-02-22_AR9170_230209/drivers/net/b44.c
--- compat-wireless-2009-02-22_AR9170_230209/drivers/net/b44.c     2009-02-22 08:14:13.000000000 +0300
+++ compat-wireless-2009-02-22_AR9170_230209/drivers/net/b44.c  2009-08-18 02:49:05.859159438 +0400
@@ -880,7 +880,7 @@ static int b44_poll(struct napi_struct *
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
                netif_rx_complete(netdev, napi);
 #else
-               netif_rx_complete(napi);
+               napi_complete(napi);
 #endif
                b44_enable_ints(bp);
        }
@@ -916,7 +916,7 @@ static irqreturn_t b44_interrupt(int irq
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
                if (netif_rx_schedule_prep(dev, &bp->napi)) {
 #else
-               if (netif_rx_schedule_prep(&bp->napi)) {
+               if (napi_schedule_prep(&bp->napi)) {
 #endif
                        /* NOTE: These writes are posted by the readback of
                         *       the ISTAT register below.
@@ -926,7 +926,7 @@ static irqreturn_t b44_interrupt(int irq
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
                        __netif_rx_schedule(dev, &bp->napi);
 #else
-                       __netif_rx_schedule(&bp->napi);
+                       __napi_schedule(&bp->napi);
 #endif
                } else {
                        printk(KERN_ERR PFX "%s: Error, poll already scheduled\n",
Code: diff -urp compat-wireless-2009-02-22_AR9170_230209/drivers/net/wireless/at76c50x-usb.c compat-wireless-2009-02-22_AR9170_230209/drivers/net/wireless/at76c50x-usb.c
--- compat-wireless-2009-02-22_AR9170_230209/drivers/net/wireless/at76c50x-usb.c   2009-02-22 08:14:13.000000000 +0300
+++ compat-wireless-2009-02-22_AR9170_230209/drivers/net/wireless/at76c50x-usb.c        2009-08-18 01:20:58.286740384 +0400
@@ -2248,7 +2248,7 @@ static int at76_init_new_device(struct a

        printk(KERN_INFO "%s: USB %s, MAC %s, firmware %d.%d.%d-%d\n",
               wiphy_name(priv->hw->wiphy),
-              interface->dev.bus_id, mac2str(priv->mac_addr),
+              dev_name(&(interface->dev)), mac2str(priv->mac_addr),
               priv->fw_version.major, priv->fw_version.minor,
               priv->fw_version.patch, priv->fw_version.build);
        printk(KERN_INFO "%s: regulatory domain 0x%02x: %s\n",

Build and install

Finally after all you may build and install the driver

make sudo make uninstall sudo make install

Also you should copy firmware files to /lib/firmware

sudo mkdir /lib/firmware sudo cp ar9170-*.fw /lib/firmware

After this you should reboot

Usage

Just add module to kernel and configure it with your favorite wireless tool.

modprobe ar9170

Module was tested with wpa_supplicant, to connect to WPA-PSK network. It works at N speed (300MBit) with 2.6.35 gentoo kernel (tested with Ubuntu mainline kernel on July 24, 2010)

Note: Fresh ideas how to make it better, please send feadback to dexy dot 31337 at gmail dot com

Links