
12 minute read
Create an Android-friendly Hotspot in Linux
by Hiba Dweib
This article walks readers through the process of setting up an Android-friendly hotspot.
Let’s suppose you have a laptop and a phone, and you want to share your laptop's Internet connection with the phone (reverse tethering). You might think it's as simple as going to a network connection and creating a wireless connection. Unfortunately, it's not, because the hotspot created by laptops generally supports only two modes—Ad-Hoc and Infrastructure (which can be seen in Figure 1). Both these modes are not supported by most of the Android and Windows phones in the market. So let us go about creating an Android-friendly or a ‘phone-friendly’ hotspot. For this article, I’ll be using Ubuntu 12.04 LTS.
Advertisement
Installation
Let’s first install Hostapd from the Ubuntu software centre.
If you prefer the command line, then just type the following command:
sudo apt-get install hostapd
You can also download and compile Hostapd from source, from its site http://w1.fi/hostapd/.
For other distributions, search for the package named hostapd in your repository.
As explained in http://acx100.erley.org/git.html, Hostapd has the following levels in managing Wi-Fi and each level is explained as follows:
“Wireless card: Should be self-explanatory... handles sending/receiving wireless packets
Linux kernel: The Linux kernel contains the driver for the wireless card, and the nl80211 sub-system, which handles the configuring of wireless interfaces for user space libnl: libnl is the transport layer used to communicate with the kernel via netlink udev: udev is the facility the kernel uses to pass events/calls to crda iw: iw is a userspace utility that we can use to test that libnl is working correctly, as well as to create additional virtual wireless interfaces on the wireless card crda: crda is a userspace program that the kernel queries (through udev) to find what channels/frequencies are usable, and at what powers. This moves the information out of static tables maintained in the kernel to userspace, which allows them to be updated without reloading drivers or rebooting
Wireless regulatory database: This is the database of allowable frequencies and transmit power levels used by crda
Hostapd: This is the daemon that handles the generation of beacons and other wireless packets, as well as wpa-psk, wpa2, etc, encryptions.”
Checking your Wi-Fi card
Hostapd supports the following drivers: mac80211-based drivers with support for master mode [linux] Linux drivers that support nl80211/cfg80211 in AP mode
Host AP driver for Prism2/2.5/3 [linux] Driver interface for FreeBSD net80211 layer [kfreebsd] Any wired Ethernet driver for wired IEEE 802.1X authentication
Now let’s check whether your Wi-Fi card is supported by Hostapd. Most commonly used Wi-Fi cards are supported in Hostapd, but just to be sure, we could check. First, check which kernel driver is used for your card, then type the following command:
lspci -k | grep -A 3 -i "network"
Network controller: Ralink corp. RT3290 Wireless 802.11n 1T/1R PCIe Subsystem: Hewlett-Packard Company Device 18ec Kernel driver in use: rt2800pci Kernel modules: rt2800pci
The driver used by the kernel is rt2800pci. This will vary depending on your kernel and your Wi-Fi card. Now, let’s check the interface part, which will tell us whether our card is supported or not. Next, type the following command:
modinfo rt2800pci | grep ‘depends’
…replacing driver with your appropriate one, which in my case is rt2800pci.
This will vary depending on your Wi-Fi card. In my case, it is:
rt2x00lib,rt2800lib,rt2x00pci,compat,eeprom_93cx6
Check each interface with the compatibility list either by checking if your interface satisfies one of the conditions required by Hostapd or by ‘googling’ with the keyword ‘interface_name hostapd’. You might get some clue if one or more interfaces match with the list needed by Hostapd—then you are good to go. Otherwise, cross your fingers and give it a try by configuring it as explained below.
Configuration
Now, let’s create a configuration file named test.conf with your favourite text editor in your home directory. Lines starting with # are just comments to explain the configuration; you can skip them while writing the configuration file:
# sets the wifi interface to use, is wlan0 in most case interface=wlan0 # driver to use, nl80211 works in most cases driver=nl80211 # Choose suitable name for SSID, or simply the name of your wifi as visible on list of networks ssid=Put_your_desried_name_here # sets the mode of wifi, depends upon the device used, can be Figure 1: Types of wireless networks


Figure 2: Creating a New Wireless Connection
a,b,g,n. g ensures backward #compatibility. hw_mode=g # sets the channel for your wifi , 11 will work fine for most of the people channel=11 #####Sets WPA and WPA2 authentication , they are stronger than WEP##### #wpa option sets which wpa implementation to use #1 - wpa only #2 - wpa2 only #3 - both wpa=3 # sets password for the access point, choose a strong one :) wpa_passphrase=Put_here_your_desired_password # sets wpa key management wpa_key_mgmt=WPA-PSK #sets encryption used wpa_pairwise=TKIP CCMP # Rekeys after 10 minutes,if there is interference, the wifi

Figure 3: Preferences of New Network

Figure 4: Hostapd running
connection between AP and laptop will #break. For CCMP, during rekeying, there is a break of approximately 10 seconds which may #be the time for random key generation and reconnection. #If you face any error you can skip the last option, but will work in most cases flawlessly wpa_ptk_rekey=600 # For more options refer to manual pages or Hostapd Website http://w1.fi/hostapd/
Testing
We are now almost done but we need to create some arrangements. Using the command line would take a long time. The easy way would be to create a normal Ad-Hoc Wi-Fi hotspot (SSID not mandatory) to be the same as for Hostapd. Creating an Ad-Hoc hotspot is as easy as going to Network Connections, and then creating a New Wireless Connection.
Choose the SSID and key of your choice, because it doesn’t matter, as this will be overridden by the WPA security of Hostapd.
In my case, the key is named Hotspot. After getting the notification that a successful connection has been established, fire up the terminal and type the following command:
sudo hostapd test.conf Figure 5: Connection details of your device shown by Hostapd

This command will invoke Hostapd with options specified by the configuration file named test.conf (which we created earlier). It will make a hotspot on the specified interface, wlan0, at the MAC address of your Wi-Fi card, as shown in Figure 4.
Now, try to connect your phone by specifying the necessary arguments. As soon as your phone tries to connect, you will see your device’s MAC address along with its status, which would be something like what’s shown in Figure 5.
Note: 1. Users have to first create an Ad-Hoc network, before issuing the Hostapd command.
Run the Hostapd command with sudo or with root privileges. 2. It would also help you to track who is connected to your network. MAC address filtering can be set up by just adding the following line:
#macaddr_acl sets options for mac address filtering. 0 means "accept unless in deny list" macaddr_acl=0
References
[1] http://acx100.erley.org/git.html—for an explanation of how
Hostapd manages Wi-Fi and an understanding of each component in the level. [2] httpnims11.wordpress.com/2012/04/27/hostapd-the-linux-wayto-create-virtual-wifi-access-point/—For an understanding of the rest of the process [3] http://w1.fi/hostapd/ [4] https://bugs.archlinux.org/task/27406 —for an explanation of the errors associated with wpa_ptk_rekey=600
By Jatin Dhankhar
The author is crazy about computers and loves to learn anything that is related to them. Besides computers, he loves science and cartoons. He can be reached at dhankhar.jatin@gmail.com
Open Gurus Let's Try
Why Doesn't MIDI Work On My PC?
MIDI stands for Musical Instrument Digital Interface, a standard adopted by the electronic music industry for controlling devices such as synthesisers and sound cards that emit music. This article helps readers to solve the problem of MIDI files not playing on a PC.

MIDI is a wonderful standard that defines the protocols and interfaces for electronic musical instruments and computers. Nowadays, it is possible to create even large-scale orchestral pieces using just a personal computer. This article covers only standard MIDI files (.smf or .midi or .mid), which contain details like notations for different instruments and act like an audio file when played using a MIDI player. You are probably familiar with MIDI files, since many ring tones and Web music clips come in that format.
What makes MIDI files distinguishable is that their sound is not pre-recorded. The file contains just some notations for different instruments used in that particular piece of music. It is played with the help of a soundfont, which contains pre-recorded sounds for those instruments. This makes MIDI files extremely small. Another advantage of MIDI files is that you can study a piece of music and modify it. There are many programs like Musescore, which can convert a given MIDI file to a score sheet and vice versa.
GNU/Linux users do run into difficulties with MIDI files and programs. But many users live with them, believing that the problems can never be solved until a new version is released. Actually, they can be solved in a few very simple steps. You should try them so you can experience a lot of wonderful MIDI applications in GNU/Linux.
Programs and ports
MIDI is a built-in facility with almost all GNU/Linux distros. But do ensure that you have the TiMidity++ MIDI Sequencer installed in your system (we are not considering other sequencers now). So let us solve some MIDI problems.
Playback
Most users find it difficult to open a MIDI files. Some players don't support them. For example, VLC needs an additional FluidSynth plugin to read them. You can solve this problem by installing appropriate plugins using the Synaptic Package Manager, the apt-get install command or any other package manager.
Some players won't play MIDI files properly. For example, Totem plays MIDI files in a discrete manner. TiMidity++ is a better option. Always right click on a MIDI file and select TiMidity++ from the Open With sub-menu options.
The command line program timidity also offers many features. See the command below, which plays a MIDI file with 200 per cent volume and 150 per cent tempo.
-----CMD----timidity Fanfare.mid --volume 200 -T 150 ----/CMD-----
Ports and connections
When programs like virtual pianos and music creators do not produce sound, you have to change their connection by choosing the appropriate MIDI port. It has been observed that the Midi Through port doesn't play sound while Timidity ports work well. As an example, take the VMPK virtual piano. When it doesn't play sounds, you have to change its connections at Edit→Connections.
You can use connection programs like the Jack Audio Connection Kit to handle advanced audio connections including that of MIDI. They offer many complex facilities.
Sometimes the program shows that ‘…an instrument is not found.’ This is not a problem of the program, but of the soundfont.
Soundfonts
We are familiar with text fonts. The text of a document is always the same, but the appearance depends on the fonts used while rendering (displaying). You might have noticed that the text of some websites appears differently in different browsers/devices. This is because they render those websites differently even though the content remains the same. As I mentioned earlier, MIDI files contain notations only. They might sound different in different platforms since the soundfonts used for rendering may be different.
Another problem with text fonts is that some regional language/special characters in documents cannot be displayed since the current font doesn't contain those characters. The same issue exists for soundfonts also. Some instruments are not available in some soundfonts, so a MIDI file containing parts for those instruments can't be played properly. Just as we solve the text font problem by using fonts with maximum languages/characters, we can use heavy soundfonts like Fluid, or combinations of different soundfonts to solve this MIDI problem.
By default, FreePats comes with TiMidity++ as the soundfont. Unfortunately, it is currently incomplete. So we have to install some other soundfont to enjoy MIDI files in clarity. Let us learn more about the installation and configuration.
Installation
Soundfonts come with the extension .sf2. They can be stored in any directory and used with suitable programs. But in order to use them with TiMidity++ (i.e., usual MIDI playback), we should have their configuration files in /etc/ timidity. Fortunately, we have got ready-to-install packages of some famous soundfonts. You may use a package manager to install them. The packages are fluid-soundfont-gm, fluidsoundfont-gs and musescore-soundfont-gm. The first two are very large, while the second one is lightweight.
Configuration
Even after installing a new soundfont, TiMidity++ uses the older one. We have to edit its configuration file to enable the new soundfont. Let us look at the Fluid GM soundfont as an example. First ensure that its configuration file is in /etc/timidity.
For this, try the following command at the terminal:
ls /etc/timidity
fluidr3_gm.cfg freepats.cfg timidity_a.cfg fluidr3_gs.cfg timgm6mb.cfg timidity.cfg
The output shows we have fluid3_gm.cfg, which is the configuration file of the Fluid GM soundfont. Now we have to add this into timidity.cfg, which is the configuration file of TiMidity++. Before doing that, keep a back-up copy of it in your home folder:
sudo cp /etc/timidity/timidity.cfg ~/timidity.cfg
Try the command given below to open the file:
sudo gedit /etc/timidity/timidity.cfg
Note: You can use other text editors like gvim instead of gedit, depending on your distro.
We have to add this line at the end of the file:
source /etc/timidity/fluidr3_gm.cfg
But the file probably contains that line already, in a commented state. All you have to do is uncomment it (by removing the hash (#) in front of it). Now you may comment the line of the current soundfont by adding a # before it.
The configuration is complete and TiMidity++ starts to use the new soundfont.
Note: You can use multiple soundfonts at a time by keeping their configuration lines uncommented. When both soundfonts contain the same instrument, the last soundfont is used. For advanced mixing of soundfonts, you have to edit their configuration files (e.g., /etc/timidity/fluidr3_gm.cfg) or create a new soundfont using programs like Swami.
By: Nandakumar Edamana
The author is a free software user, developer, hacker and activist, now in higher secondary school. He is the creator of packages like Chalanam (animation software), Sammaty (to conduct computer-aided election, now used in more than a 1000 schools in Kerala),Gopanam (file encryption), etc. These packages are, of course, free software and available for download from launchpad. net for free. The author can be contacted at nandakumar96@ gmail.com, nandakumar@nandakumar.co.in