Android hostapd

提供: KiyomiWiki
移動: 案内検索

Hostadpの設定方法について記述します。

device.mk

overlay/frameworks/base/core/res/res/values/config.xml

   <string-array translatable="false" name="config_tether_wifi_regexs">
       <item>"wlan0"</item>
   </string-array>
   <integer-array translatable="false" name="config_tether_upstream_types">
       <item>0</item>
       <item>1</item>
       <item>5</item>
       <item>7</item>
   </integer-array>

init.hardware.rc

  • Register hostap service for SoftAP/hotspot:
service hostapd_bin /system/bin/hostapd -d /data/misc/wifi/hostapd.conf
   socket wpa_wlan0 dgram 660 wifi wifi
   disabled
   oneshot


hotspotで開けない場合は、NULLチェックのコードを追加

  • /packages/apps/Settings/src/src/com/android/settings/Users/UserSettings.java
   private void addUserNow(final int userType) {
       synchronized (mUserLock) {
           mAddingUser = true;
           //updateUserList();
           new Thread() {
               public void run() {
                   UserInfo user = null;
                   // Could take a few seconds
                   if (userType == USER_TYPE_USER) {
                       user = createTrustedUser();
                   } else {
                       user = createLimitedUser();
                   }
                   synchronized (mUserLock) {
                       mAddingUser = false;
                       if (userType == USER_TYPE_USER) {
                           mHandler.sendEmptyMessage(MESSAGE_UPDATE_LIST);
                           if (user != null) {
                               mHandler.sendMessage(mHandler.obtainMessage(
                                   MESSAGE_SETUP_USER, user.id, user.serialNumber));
                           }
                       } else {
                           if (user != null) {
                               mHandler.sendMessage(mHandler.obtainMessage(
                                   MESSAGE_CONFIG_USER, user.id, user.serialNumber));
                           }
                       }
                   }
               }
           }.start();
       }
   }


  • /packages/apps/Settings/src/src/com/android/settings/Users/TetherSettings.java
   private void updateBluetoothState(String[] available, String[] tethered,
           String[] errored) {
       boolean bluetoothErrored = false;
       for (String s: errored) {
           for (String regex : mBluetoothRegexs) {
               if (s.matches(regex)) bluetoothErrored = true;
           }
       }
       BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
       if (adapter == null)
           return;
       int btState = adapter.getState();
       if (btState == BluetoothAdapter.STATE_TURNING_OFF) {
           mBluetoothTether.setEnabled(false);
           mBluetoothTether.setSummary(R.string.bluetooth_turning_off);
       } else if (btState == BluetoothAdapter.STATE_TURNING_ON) {
           mBluetoothTether.setEnabled(false);
           mBluetoothTether.setSummary(R.string.bluetooth_turning_on);
       } else {
           BluetoothPan bluetoothPan = mBluetoothPan.get();
           if (btState == BluetoothAdapter.STATE_ON && bluetoothPan != null &&
                   bluetoothPan.isTetheringOn()) {
               mBluetoothTether.setChecked(true);
               mBluetoothTether.setEnabled(true);
               int bluetoothTethered = bluetoothPan.getConnectedDevices().size();
               if (bluetoothTethered > 1) {
                   String summary = getString(
                           R.string.bluetooth_tethering_devices_connected_subtext,
                           bluetoothTethered);
                   mBluetoothTether.setSummary(summary);
               } else if (bluetoothTethered == 1) {
                   mBluetoothTether.setSummary(
                           R.string.bluetooth_tethering_device_connected_subtext);
               } else if (bluetoothErrored) {
                   mBluetoothTether.setSummary(R.string.bluetooth_tethering_errored_subtext);
               } else {
                   mBluetoothTether.setSummary(R.string.bluetooth_tethering_available_subtext);
               }
           } else {
               mBluetoothTether.setEnabled(true);
               mBluetoothTether.setChecked(false);
               mBluetoothTether.setSummary(R.string.bluetooth_tethering_off_subtext);
           }
       }
   }

コンソールでの確認

  • hostapd起動
# hostapd /data/misc/wifi/hostapd.conf
  • AP IP ADDRESS設定
# ifconfig wlan0 192.168.43.1
  • DHCP Servierの起動
# dnsmasq --dhcp-range=192.168.43.2,192.168.43.100,12h --pid-file=/data/misc/wifi/dnsmasq.pid

* /data/misc/wifi/dnsmasq.pidのダミーファイルを作成する。
  • hostapd.conf設定例
interface=wlan0
ctrl_interface=/data/misc/wifi/sockets
ssid=AndroidAP
hw_mode=g
wpa_passphrase=123456789012
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
ht_capab=[SHORT-GI-20][TX-STBC][HT40-][RX-STBC1]
channel=1
rts_threshold=2346
fragm_threshold=2346
beacon_int=100
wpa=2
ieee80211n=1
wmm_enabled=1
wpa_group_rekey=0
wps_state=1