# [Q] How to build Jcsullins wifi source



## bchen (Feb 10, 2014)

I've been trying to build wifi driver for touchpad. I have setup and built Android rom from source by following this link.

http://rootzwiki.com/topic/21362-guide-build-cm9-kernel-wo-building-rom

I could build the rom but this source didn't have the wifi driver I'm interested so I grabbed the wifi driver source maintained by Jcsullins at this link

https://github.com/jcsullins/backports-3.10-2

This driver works on touchpad but it didn't show how to build it. I tried several times but no luck. Does anyone know how to build the wifi module from Jcsullins' backport 3.10?

Thanks a lot!


----------



## NewbyJE (Jan 19, 2012)

bchen said:


> I've been trying to build wifi driver for touchpad. I have setup and built Android rom from source by following this link.
> 
> http://rootzwiki.com/topic/21362-guide-build-cm9-kernel-wo-building-rom
> 
> ...


bchen:

Assume your path to a local copy of hp-kernel-tenderloin is: ~/pathto/hp-kernel-tenderloin
Assume your path to a local copy of android is: ~/pathto/android
Assume your path to a local copy of jcsullins backports is: ~/pathto/backports-3.10-2

-------------------------------------------------------------------------------
Build Kernel
-------------------------------------------------------------------------------

cd ~/pathto/hp-kernel-tenderloin
git checkout ics

make ARCH=arm tenderloin_android_defconfig
make ARCH=arm -j8 CROSS_COMPILE=~/pathto/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- uImage

option for log:

make ARCH=arm -j8 CROSS_COMPILE=~/pathto/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- uImage 2>&1 | tee hp_kernel.log

-------------------------------------------------------------------------------
Build WiFi Modules
-------------------------------------------------------------------------------

cd ~/pathto/backports-3.10-2

export ARCH=arm
export CROSS_COMPILE=~/pathto/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-
export KLIB=~/pathto/hp-kernel-tenderloin
export KLIB_BUILD=${KLIB}
make defconfig-ath6kl
make -j8

Modules will be here:


backports-3.10-2/compat/compat.ko
backports-3.10-2/drivers/net/wireless/ath/ath6kl/ath6kl.ko
backports-3.10-2/net/wireless/cfg80211.ko


Note: You can add "CPTCFG_ATH6KL_DEBUG=y" in ~/pathto/backports-3.10-2/defconfig/ath6kl to compile in debugging support (which can be enabled via sysfs entries if needed)


----------



## NewbyJE (Jan 19, 2012)

bchen:

You can also build inline by adding to local_manifest.xml:

<project name="jcsullins/backports-3.10-2" path="external/backports-wireless" remote="github" revision="master"/>

Then add the following in BoardConfig.mk:

# Define kernel config for inline building
TARGET_KERNEL_CONFIG := tenderloin_android_defconfig

KERNEL_WIFI_MODULES:
$(MAKE) -C external/backports-wireless defconfig-ath6kl
export CROSS_COMPILE=$(ARM_EABI_TOOLCHAIN)/arm-eabi-; $(MAKE) -C external/backports-wireless KLIB=$(KERNEL_SRC) KLIB_BUILD=$(KERNEL_OUT) ARCH=$(TARGET_ARCH) $(ARM_CROSS_COMPILE)
cp `find external/backports-wireless -name *.ko` $(KERNEL_MODULES_OUT)/
arm-eabi-strip --strip-debug `find $(KERNEL_MODULES_OUT) -name *.ko`
$(MAKE) -C external/backports-wireless clean

TARGET_KERNEL_MODULES := KERNEL_WIFI_MODULES

Remember to remove older libs from device/hp/tenderloin/prebuilt/wifi and remove the following from device_tenderloin.mk:

# Wifi Modules
PRODUCT_COPY_FILES += \
device/hp/tenderloin/prebuilt/wifi/ath.ko:system/lib/modules/ath.ko \
device/hp/tenderloin/prebuilt/wifi/ath6kl.ko:system/lib/modules/ath6kl.ko \
device/hp/tenderloin/prebuilt/wifi/cfg80211.ko:system/lib/modules/cfg80211.ko \
device/hp/tenderloin/prebuilt/wifi/compat.ko:system/lib/modules/compat.ko \
device/hp/tenderloin/prebuilt/wifi/mac80211.ko:system/lib/modules/mac80211.ko \
device/hp/tenderloin/prebuilt/wifi/sch_codel.ko:system/lib/modules/sch_codel.ko \
device/hp/tenderloin/prebuilt/wifi/sch_fq_codel.ko:system/lib/modules/sch_fw_codel.ko


----------



## NewbyJE (Jan 19, 2012)

You can find a lot of information in Red Flea's SkyDrive: Guide - Build Android ROMS: http://goo.gl/Zpht8


----------



## bchen (Feb 10, 2014)

Great!!! I'll try it out today, and come back to update this post.


----------



## NewbyJE (Jan 19, 2012)

While you are at it, you may also want to change hardware/libhardware_legacy/wifi/wifi.c so that WiFi will start up much faster.

For CM10 (jellybean branch), at Line 625 under wifi_start_supplicant, change the code from 'ar6000' to "ath6kl", as follows:

#ifdef WIFI_DRIVER_MODULE_PATH
/* The ath6kl driver needs the interface up in order to scan! */
if (!strncmp(DRIVER_MODULE_NAME, "ath6kl", 6)) {
ifc_init();
ifc_up("wlan0");
sleep(2);
}
#endif

Sleep (1) may also work, but does not make it that much faster.

Note: This entire code fix for the ath6kl driver has not been picked up in later CyanogenMod branches and needs to be added.


----------



## bchen (Feb 10, 2014)

Now, I'm following the steps at http://goo.gl/Zpht8 to setup another pc dedicated for android, and will check and change code at line 625 when I build it.


----------



## bchen (Feb 10, 2014)

I finished the original code build and it worked! I'll build mine tomorrow. Thanks a lot!


----------



## nevertells (Oct 29, 2011)

bchen said:


> I finished the original code build and it worked! I'll build mine tomorrow. Thanks a lot!


So what is it exactly that you have accomplished? What is it that is different in the way you built in the wifi driver and how is it different from all the other Android builds that are around?


----------



## bchen (Feb 10, 2014)

We are working with a Japanese lab on a VoIP over wifi project. One of features is conference-like call among 5 android devices (touchpad for now). To minimize the frequency interference, we want to utilize all of the 14 channels when we test the feature in the Japanese lab. But no matter how I tried, the CM9 based Touchpads can't see any channels beyond 11. I tried

1. Add wifi_country_code in /data/data/com.android.providers.settings/databases/settings.db

2. Change mcc code in the telephony under /data/data/com.android.providers.settings/databases/

3. Edit any related entries in build.prop

4. I even loaded CM10 because CM10 seemingly can change wifi scan range via "System settings > WiFi > Advanced > WiFi region code"

None of the above ways worked!

So I started thinking about hacking the driver. I looked at the file "backports-3.10-2/drivers/net/wireless/ath/ath6kl/cfg80211.c" and hard coded "request->n_channels" to 14 in the function ath6kl_cfg80211_scan().

As I expected, it didn't work. The driver may be able to scan for them but the higher level code probably care only from 1 to 11. I haven't found the caller to that function. I guess the caller is out of the scope of driver code. It make more sense to hack the value from a higher level but I'm not familiar with the code so I'm still working on it.

NewbyJE and nevertells

I believe that you know much more than me on this issue. Any suggestions?

Thanks a lot


----------



## NewbyJE (Jan 19, 2012)

bchen:

I do not know enough to help much. I have seen that some devices will see 12 and 13 if you set: ro.wifi.country=EU in build.prop. I am not sure is this will work with the CM10 tenderloin builds.

Also, have you tried using 5GHz channels? Dual band support is turned off in default Android setups (in frameworks/base/core/res/res/values/config.xml). You can override by adding the following in device/hp/tenderloin/overlay/frameworks/base/core/res/res/values/config.xml:


<bool translatable="false" name="config_wifi_dual_band_support">true</bool>


----------



## nevertells (Oct 29, 2011)

@bchen,

As NewbyJE mentions, I was aware that users in the EU see 14 channels, so I suspect that the drivers written for the TouchPad were written for users in the U.S., so that could be part of the issue.

Unfortunately, I'm a user not a coder. The guy you need to discuss this with is J.C. Sullins. He is the one who wrote the WiFi drivers for the TouchPad. He hangs out on IRC and if you can get him to talk to you, he might be able to help you out. Keep in mind too that the TouchPad is in it's third year as a orphaned, discontinued piece of hardware, so interest in spending a lot of time trying to figure out your problem is not going to be high. And why would you pick a tablet that has had Android shoehorned onto it instead of a newer one that Android is installed natively?

Good luck


----------



## NewbyJE (Jan 19, 2012)

bchen:

Try this in backports-wireless:

1. Get the most recent wireless registration database from: https://www.kernel.org/pub/software/network/wireless-regdb/

2. Replace the placeholder database (/net/wireless/db.txt) with the full registration database.

2. Add this to your defconfig file (/defconfigs/ath6kl): CPTCFG_CFG80211_INTERNAL_REGDB=y


----------



## bchen (Feb 10, 2014)

NewbyJE said:


> bchen:
> 
> Try this in backports-wireless:
> 
> ...


1. I extracted db.txt from https://www.kernel.org/pub/software/network/wireless-regdb/wireless-regdb-2013.11.27.tar.gz

2. Replaced /net/wireless/db.txt with the one in the 1st step.

3. Added CPTCFG_CFG80211_INTERNAL_REGDB=y to /defconfigs/ath6kl

4. rebuilt it

It still couldn't see channels beyond 11...

Really appreciate the time you have spent!


----------



## NewbyJE (Jan 19, 2012)

bchen:

I am not sure where the county code that is used by ath6kl is set, it could be ro.product.locale.region=JP ...

Is 'ro.product.locale.region=JP' in your /system/build.prop?

If not, change the following in device_tenderloin.mk (language=English_region=Japan):

PRODUCT_LOCALES += en_US mdpi ---> PRODUCT_LOCALES += en_JP mdpi

Rebuild and see what happens.


----------



## bchen (Feb 10, 2014)

NewbyJE said:


> bchen:
> 
> I am not sure where the county code that is used by ath6kl is set, it could be ro.product.locale.region=JP ...
> 
> ...


I edited build.prop as you said before. Tried again just now. nothing's changed. I guess I have tried all of tricks other than changing code.

Under the folder jcsullins-backports-3.10-2, I didn't find device_tenderloin.mk...


----------



## NewbyJE (Jan 19, 2012)

bchen:

device_tenderloin.mk is in /dev/hp/tenderloin/. The change in this file will change the county code to "JP" in the user space (device level).

However, I think the problem is that everything we are trying is setting the country code in user space, but this does not override the regulatory domain programmed in the WiFi chip firmware. The kernel reads this from the firmware. The following expanation from http://wireless.kernel.org/en/developers/Regulatory explains why changing the country code in user space will not enable 12 to 14:


Linux allows changing regulatory domains in compliance with regulatory restrictions world wide, including the US FCC. In order to achieve this devices always respect their programmed regulatory domain and a country code selection will only enhance regulatory restrictions. This is in accordance with the FCC part 15 country code selection knowledge base publication number 594280. As an example if your device was programmed for operation in the US which allows operation on channels 1-11 on the 2.4 GHz band and you visit Japan which allows operation on channels 1-14 and you change your regulatory domain to JP you will not be able to use channel 12, 13 or 14 (CCK). But if you have a device programmed for operation in Japan and visit the US and you select US as your regulatory domain you will have channel 12-14 disabled.

Atheros devices share the same regulatory implementation. All devices have a regulatory domain code programmed into their EEPROM.

Overriding this would requires hacking the backports-wireless code to 'hardwire' the regulatory domain such that it replaces that read from the firmware. This would not be in compliance with FCC regulations. I will take a look this evening and see if I can figure out how to override the firmware regulatory domain. If it works, I will send you a PM.


----------

