Tehthering wireless DSL through the same wifi adapter

2

I have started using Ubuntu 16.04 LTS. I am missing the functionality of being able to share my wifi connection or my wireless broadband to my android phone through the same wifi interface.

I searched the internet a lot and read about kde-nm-connection-editor and hostapd. But none seem to work for me.

I landed on this page where the author of the question had quite a simple way for a workaround in order to do this. This is the link to the superuser page of the previous question.

I have followed all steps very carefully but I get stuck.

I did everything u told but I am still unable to start the AP when I run hostapd -B /etc/hostapd.conf

I am getting the error

$ sudo hostapd -B /etc/hostapd.conf
Configuration file: /etc/hostapd.conf
Could not set interface ap0 flags (UP): Name not unique on network
nl80211: Could not set interface 'ap0' UP
nl80211: deinit ifname=ap0 disabled_11b_rates=0
nl80211 driver initialization failed.
ap0: interface state UNINITIALIZED->DISABLED
ap0: AP-DISABLED 
hostapd_free_hapd_data: Interface ap0 wasn't started

I tried changing the name of the access point from new 1 to other names like ap0 here but it still doesnt work. Please help.

I have attached the /etc/hostapd.conf file for reference.

interface=ap0
driver=nl80211
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
ssid=wtf
country_code=us
hw_mode=g
channel=10
macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
eap_server=0
wpa=2
wpa_passphrase=12345678
wpa_pairwise=TKIP CCMP
rsn_pairwise=TKIP CCMP

EDIT 1: ON running the following commands, the outputs were as follows:

**iwconfig**
wlp3s0    IEEE 802.11bgn  ESSID:"ABESIT 1"  
          Mode:Managed  Frequency:2.462 GHz  Access Point: 00:04:56:AC:CB:90   
          Bit Rate=43.3 Mb/s   Tx-Power=15 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=56/70  Signal level=-54 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:43   Missed beacon:0

enp2s0    no wireless extensions.

lo        no wireless extensions.

ppp0      no wireless extensions.

**ip link show**
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp2s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 20:89:84:ea:88:84 brd ff:ff:ff:ff:ff:ff
3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether 48:d2:24:4c:15:1d brd ff:ff:ff:ff:ff:ff
5: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1492 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 3
    link/ppp 

 **iw list**  
Wiphy phy0  
    max # scan SSIDs: 4  
    max scan IEs length: 2257 bytes  
    Retry short limit: 7  
    Retry long limit: 4  
    Coverage class: 0 (up to 0m)  
    Device supports RSN-IBSS.  
    Device supports AP-side u-APSD.  
    Device supports T-DLS.  
    Supported Ciphers:  
        * WEP40 (00-0f-ac:1)  
        * WEP104 (00-0f-ac:5)  
        * TKIP (00-0f-ac:2)  
        * CCMP (00-0f-ac:4)  
        * 00-0f-ac:10  
        * GCMP (00-0f-ac:8)  
        * 00-0f-ac:9  
        * CMAC (00-0f-ac:6)  
        * 00-0f-ac:13  
        * 00-0f-ac:11  
        * 00-0f-ac:12  
    Available Antennas: TX 0x1 RX 0x1  
    Configured Antennas: TX 0x1 RX 0x1  
    Supported interface modes:  
         * IBSS  
         * managed  
         * AP  
         * AP/VLAN  
         * WDS  
         * monitor  
         * mesh point  
         * P2P-client  
         * P2P-GO  
         * Unknown mode (11)  
    Band 1:  
        Capabilities: 0x116e  
            HT20/HT40  
            SM Power Save disabled  
            RX HT20 SGI  
            RX HT40 SGI  
            RX STBC 1-stream  
            Max AMSDU length: 3839 bytes  
            DSSS/CCK HT40  
        Maximum RX AMPDU length 65535 bytes (exponent: 0x003)  
        Minimum RX AMPDU time spacing: 8 usec (0x06)  
        HT TX/RX MCS rate indexes supported: 0-7  
        Bitrates (non-HT):  
            * 1.0 Mbps  
            * 2.0 Mbps (short preamble supported)   
            * 5.5 Mbps (short preamble supported)  
            * 11.0 Mbps (short preamble supported)  
            * 6.0 Mbps  
            * 9.0 Mbps  
            * 12.0 Mbps  
            * 18.0 Mbps  
            * 24.0 Mbps  
            * 36.0 Mbps  
            * 48.0 Mbps  
            * 54.0 Mbps  
        Frequencies:  
            * 2412 MHz [1] (20.0 dBm)  
            * 2417 MHz [2] (20.0 dBm)  
            * 2422 MHz [3] (20.0 dBm)  
            * 2427 MHz [4] (20.0 dBm)  
            * 2432 MHz [5] (20.0 dBm)  
            * 2437 MHz [6] (20.0 dBm)  
            * 2442 MHz [7] (20.0 dBm)  
            * 2447 MHz [8] (20.0 dBm)  
            * 2452 MHz [9] (20.0 dBm)  
            * 2457 MHz [10] (20.0 dBm)  
            * 2462 MHz [11] (20.0 dBm)  
            * 2467 MHz [12] (20.0 dBm) (no IR)  
            * 2472 MHz [13] (20.0 dBm) (no IR)  
            * 2484 MHz [14] (disabled)  
    Supported commands:  
         * new_interface  
         * set_interface  
         * new_key  
         * start_ap  
         * new_station  
         * new_mpath  
         * set_mesh_config  
         * set_bss  
         * authenticate  
         * associate  
         * deauthenticate  
         * disassociate  
         * join_ibss  
         * join_mesh  
         * remain_on_channel  
         * set_tx_bitrate_mask  
         * frame  
         * frame_wait_cancel  
         * set_wiphy_netns  
         * set_channel  
         * set_wds_peer  
         * tdls_mgmt  
         * tdls_oper  
         * probe_client  
         * set_noack_map  
         * register_beacons  
         * start_p2p_device  
         * set_mcast_rate  
         * channel_switch  
         * Unknown command (104)  
         * connect  
         * disconnect  
    Supported TX frame types:  
         * IBSS: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * managed: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * AP: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * AP/VLAN: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * mesh point: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * P2P-client: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * P2P-GO: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
         * P2P-device: 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0  
    Supported RX frame types:  
         * IBSS: 0x40 0xb0 0xc0 0xd0  
         * managed: 0x40 0xd0  
         * AP: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0  
         * AP/VLAN: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0  
         * mesh point: 0xb0 0xc0 0xd0  
         * P2P-client: 0x40 0xd0  
         * P2P-GO: 0x00 0x20 0x40 0xa0 0xb0 0xc0 0xd0  
         * P2P-device: 0x40 0xd0  
    software interface modes (can always be added):  
         * AP/VLAN  
         * monitor  
    valid interface combinations:  
         * #{ managed } <= 2048, #{ AP, mesh point } <= 8, #{ P2P-client, P2P-GO } <= 1,  
           total <= 2048, #channels <= 1, STA/AP BI must match  
         * #{ WDS } <= 2048,  
           total <= 2048, #channels <= 1, STA/AP BI must match  
    HT Capability overrides:  
         * MCS: ff ff ff ff ff ff ff ff ff ff  
         * maximum A-MSDU length  
         * supported channel width  
         * short GI for 40 MHz  
         * max A-MPDU length exponent  
         * min MPDU start spacing  
    Device supports TX status socket option.  
    Device supports HT-IBSS.  
    Device supports SAE with AUTHENTICATE command  
    Device supports low priority scan.  
    Device supports scan flush.  
    Device supports AP scan.  
    Device supports per-vif TX power setting  
    P2P GO supports CT window setting  
    Driver supports a userspace MPM  
    Device supports active monitor (which will ACK incoming frames)  
    Driver/device bandwidth changes during BSS lifetime (AP/GO mode)  

Ayush Pratap Singh

Posted 2016-10-04T13:20:54.250

Reputation: 21

1As I read it, you're using this adaptor to receive your wireless internet and then you want to share it via the same adaptor? I very much doubt you can do this. Why can't your phone just connect to the wifi directly? – djsmiley2k TMW – 2016-10-04T13:33:58.320

That is because the network I am trying to connect to uses wireless broadband (PPPOE). I have a rooted phone but it still doesnt connect using the WIFI PPPOE application available. – Ayush Pratap Singh – 2016-10-04T16:16:42.087

And I am pretty sure this can be done, there is this link I have posted... the author did it. I s there any way I can direct his attention to my questin ? Sorry, I am new to this site... – Ayush Pratap Singh – 2016-10-04T16:17:40.420

Output of iw list posted. Sorry for the misunderstanding. @MariusMatutiae – Ayush Pratap Singh – 2016-10-05T12:39:01.073

Pls see my edited answer – MariusMatutiae – 2016-10-05T13:27:24.627

Answers

0

valid interface combinations:  
     * #{ managed } <= 2048, #{ AP, mesh point } <= 8, #{ P2P-client, P2P-GO } <= 1,  
       total <= 2048, #channels <= 1, STA/AP BI must match  
     * #{ WDS } <= 2048,  
       total <= 2048, #channels <= 1, STA/AP BI must match  

The output above shows that the AP and the station channels must coincide: either

#channels <= 1

or

STA/AP BI must match

mean the same thing, that the Station and the AP channel must match. So you are not free to specify any channel in the hostapd.conf file, you must make sure that the channel in the file is the same you are already linked to via your managed (or station, same thing) interface.

As for the interfaces names, for some reason I am now unable to make hostapd work with names such as new0 and new1, but if I use wlan0 and wlan1 everything works fine, as per my post.

Below you find a simple bash script that will do this for you:

#!/bin/bash

#      If you need to debug, uncomment the following statement
#set -x
#      and comment out the "exec" statement.

[ "$USER" != "root" ] && exec sudo $0 "$@"
exec 2>/var/log/$(basename $0).log

if [ $# != 2 ]; then
    echo "Usage $0 interface action"
    echo "where interface is the name of the wireless interface to be used"
    echo "and action is one of start/stop "
    exit 1
fi 


MY_IF=$1
HPID=/tmp/host$USER.pid
DPID=/tmp/dnsm$USER.pid
WPID=/tmp/wpas$USER.pid

[ -x /usr/bin/srm ] && RM=/usr/bin/srm || RM="/bin/rm -f"

stop() {

        kill -9 $(cat $HPID)
        kill -9 $(cat $DPID)
        dhclient -r
        kill -9 $(cat $WPID)
        rm /tmp/*.my_conf
        rm /tmp/*$USER.pid
        iw dev wlan1 del
        ip link set dev $MY_IF down
        ip addr flush dev $MY_IF
        ip link set dev $MY_IF up
        iptables -t nat -D POSTROUTING -o $MY_IF -j MASQUERADE
        service network-manager start
}


my_exit() {

case $1 in
    2)
        echo "wpa_supplicant failed" >>&2 
        ;;
    3)
        echo "dhclient failed" >>&2 
        ;;
    4)
        echo "hostapd failed" >>&2 
        ;;
    5)
        echo "dnsmasq failed" >>&2 
            ;;
esac
    stop >>&2
    exit $1

}



start() {
    service network-manager stop
    iw phy phy0 interface add wlan1 type __ap

    ip addr flush dev $MY_IF
    ip link set dev $MY_IF up
    ip link set dev wlan1 up

    pkill -9 wpa_supplicant
    MYSECRET=$(mktemp /tmp/XXXXXX.my_conf)

    echo -e "Please enter BSSID and Password of the Wifi network which\n"
    echo -e "you wish to connect to:"
    read BSSID PASSWORD
    wpa_passphrase $BSSID $PASSWORD > $MYSECRET 
    wpa_supplicant -B -i $MY_IF -c $MYSECRET -Dnl80211 -P $WPID 1> /dev/null 
    EXIT_CODE=$?
    $RM $MYSECRET
    [[ $EXIT_CODE == 0 ]] && : || my_exit 2 


    pkill -9 dhclient
    dhclient $MY_IF
    [[ $EXIT_CODE == 0 ]] && : || my_exit 3 

    MYTEMPH=$(mktemp /tmp/XXXXXX.my_conf)
    MYTEMPD=$(mktemp /tmp/XXXXXX.my_conf)

    cat > $MYTEMPH <<EOF
interface=wlan1
driver=nl80211
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
ssid=wtf
hw_mode=g
channel=3
macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
eap_server=0
wpa=2
wpa_passphrase=12345678
wpa_pairwise=TKIP CCMP
rsn_pairwise=TKIP CCMP
EOF
    pkill -9 hostapd
    /usr/sbin/hostapd -B -P $HPID $MYTEMPH 1> /dev/null
    sleep  3
    ps ax | grep hostapd | grep -v grep >/dev/null
    if [[ ! $? == 0  ]]; then 
        /usr/sbin/hostapd -B -P $HPID $MYTEMPH 1> /dev/null
    fi
    [[ $? == 0 ]] && : || my_exit 4


    echo 1 >/proc/sys/net/ipv4/ip_forward


    ip addr add 10.111.113.1/24 dev wlan1
    cat > $MYTEMPD <<EOF
domain-needed
bogus-priv
dhcp-authoritative
no-dhcp-interface=$MY_IF
no-dhcp-interface=lo
interface=wlan1
server=8.8.8.8
server=8.8.4.4
expand-hosts
dhcp-range=10.111.113.2,10.111.113.100,12h
EOF
    pkill -9 dnsmasq
    dnsmasq  -C $MYTEMPD -x $DPID
    [[ $? == 0 ]] && : || my_exit 5
    iptables -t nat -A POSTROUTING -o $MY_IF -j MASQUERADE

}



case $2 in
        start)
            stop >>&2
            start
            ;;
        stop)
            stop
            ;;
        *) 
            echo "Usage $0 interface action"
            echo "where interface is the name of the wireless interface to be used"
            echo "and action is one of start/stop "
            ;;

esac

make sure that the channel of hostapd.conf inside the script above (the line channel=3) matches that of the AP you want to connect to. I have not left, in the above, set -x, which allows you to see errors, if any, as the script progresses: if you need to do some debugging, you can uncomment it. I have been unable to make hostapd, when called from a script as above, work with anything but country_code=us, but you may be luckier. Also, my version of hostapd fails every other time, so that I have added a condition that tests whether hostapd is running or not, and tries exactly once more to make it start.

MariusMatutiae

Posted 2016-10-04T13:20:54.250

Reputation: 41 321

OK I will get back to you with the outputs of these... But I am sure I used different names. I set the name for station to new0 like u explained in your configuration and set the AP name to new1 first. When it didnt work I also tried ap0 but still didnt work... – Ayush Pratap Singh – 2016-10-05T09:19:39.040

The O/P is as follows iwlist: wlp3s0 IEEE 802.11bgn ESSID:"ABESIT 1"
Mode:Managed Frequency:2.462 GHz Access Point: 00:04:56:AC:CB:90
Bit Rate=43.3 Mb/s Tx-Power=15 dBm
Retry short limit:7 RTS thr:off Fragment thr:off Power Management:off Link Quality=56/70 Signal level=-54 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:0 Invalid misc:43 Missed beacon:0 enp2s0 no wireless extensions. lo no wireless extensions. ppp0 no wireless extensions.
– Ayush Pratap Singh – 2016-10-05T10:07:11.027

I have posted the output above... – Ayush Pratap Singh – 2016-10-05T10:18:25.543