Hostapd ACS 开关控制
在Android上ACS模式是打开的,ACS打开后会自动选择信道,如果驱动那边不支持可能导致hostapd无法初始化成功。所以可以关闭ACS,使用固定的信道。
public HostapdHal(Context context) {
mEnableAcs = context.getResources().getBoolean(R.bool.config_wifi_softap_acs_supported);
mEnableIeee80211AC =
context.getResources().getBoolean(R.bool.config_wifi_softap_ieee80211ac_supported);
}
采用了overlay,覆盖了aosp中设置的值。
// aosp
./frameworks/base/core/res/res/values/config.xml: <bool translatable="false" name="config_wifi_softap_acs_supported">false</bool>
./frameworks/base/core/res/res/values/symbols.xml: <java-symbol type="bool" name="config_wifi_softap_acs_supported" />
// overlay
./device/qcom/common/device/overlay/frameworks/base/core/res/res/values/config.xml: <bool translatable="false" name="config_wifi_softap_acs_supported">true</bool>
./device/qcom/common/automotive/device/overlay/frameworks/base/core/res/res/values/config.xml: <bool translatable="false" name="config_wifi_softap_acs_supported">true</bool>
./vendor/qcom/proprietary/resource-overlay/common/Frameworks/res/values/config.xml: <bool translatable="false" name="config_wifi_softap_acs_supported">true</bool>
其中device, automotive 代表手机和车机平台。选择哪个是根据宏定义TARGET_BOARD_AUTO决定的。
//file path: device/qcom/common/base.mk
# enable overlays to use our version of
# source/resources etc.
ifneq ($(strip $(TARGET_BOARD_AUTO)),true)
DEVICE_PACKAGE_OVERLAYS += device/qcom/common/device/overlay
PRODUCT_PACKAGE_OVERLAYS += device/qcom/common/product/overlay
else
DEVICE_PACKAGE_OVERLAYS += device/qcom/common/automotive/device/overlay
PRODUCT_PACKAGE_OVERLAYS += device/qcom/common/automotive/product/overlay
endif
endif
//file path device/qcom/msmnile_gvmq/msmnile_gvmq.mk
TARGET_BOARD_AUTO := true
hotspot 开关流程
两个步骤。
- 1 hotspot 开关不是直接操作WifiManage的 startSoftAp()打开的。
- 2 ap 相关的设置是通过WifiManage 更新的。不是随着startSoftAp传进的。
//Setting WifiTetherSettings.java
@Override
public void onTetherConfigUpdated() {
final WifiConfiguration config = buildNewConfig();
mPasswordPreferenceController.updateVisibility(config.getAuthType());
/**
* if soft AP is stopped, bring up
* else restart with new config
* TODO: update config on a running access point when framework support is added
*/
if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED) {
Log.d("TetheringSettings",
"Wifi AP config changed while enabled, stop and restart");
mRestartWifiApAfterConfigChange = true;
mSwitchBarController.stopTether();
}
mWifiManager.setWifiApConfiguration(config);
}
//system_server WifiServiceImpl.java 需要权限
private boolean checkNetworkSettingsPermission(int pid, int uid) {
return mContext.checkPermission(android.Manifest.permission.NETWORK_SETTINGS, pid, uid)
== PackageManager.PERMISSION_GRANTED;
}
//Setting WifiTetherSwitchBarController.java
void stopTether() {
mSwitchBar.setEnabled(false);
mConnectivityManager.stopTethering(TETHERING_WIFI);
}
void startTether() {
mSwitchBar.setEnabled(false);
mConnectivityManager.startTethering(TETHERING_WIFI, true /* showProvisioningUi */,
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
}
Wireshark 802.11 相关标签
例如过滤 Beacon / Probe response / association repsone
wlan.fc.type_subtype == 0x8 or wlan.fc.type_subtype == 0x5 or wlan.fc.type_subtype == 0x02
帧类型 | 过滤器语法 |
---|---|
Management frame | wlan.fc.type == 0 |
Control frame | wlan.fc.type == 1 |
Data frame | wlan.fc.type == 2 |
Association request | wlan.fc.type_subtype == 0x00 |
Association response | wlan.fc.type_subtype == 0x01 |
Reassociation request | wlan.fc.type_subtype == 0x02 |
Reassociation response | wlan.fc.type_subtype == 0x03 |
Probe request | wlan.fc.type_subtype == 0x04 |
Probe response | wlan.fc.type_subtype == 0x05 |
Beacon | wlan.fc.type_subtype == 0x08 |
Disassociate | wlan.fc.type_subtype == 0x0A |
Authentication | wlan.fc.type_subtype == 0x0B |
Deauthentication | wlan.fc.type_subtype == 0x0C |
Action frame | wlan.fc.type_subtype == 0x0D |
Block ACK requests | wlan.fc.type_subtype == 0x18 |
Block ACK | wlan.fc.type_subtype == 0x19 |
Power save poll | wlan.fc.type_subtype == 0x1A |
Request to send | wlan.fc.type_subtype == 0x1B |
Clear to send | wlan.fc.type_subtype == 0x1C |
ACK | wlan.fc.type_subtype == 0x1D |
Contention free period end | wlan.fc.type_subtype == 0x1E |
NULL data | wlan.fc.type_subtype == 0x24 |
QoS data | wlan.fc.type_subtype == 0x28 |
Null QoS data | wlan.fc.type_subtype == 0x2C |
Wifi Carplay hostapd.conf 配置
参考:
CarPlay wireless(蓝牙+WiFi)连接方案(Wi-Fi部分)
需要配置两部分: Interworking IE & Apple Device IE
- 1 IEEE802.11 Interworking IE.
该IE要求车载设备(AP)支持。该IE中的Access NetWork Option字段用来提供是否CarPlay的车载设备(AP)提供Internet共享服务;Venue info字段用来告知该网络是由车载的设备提供,其Group code值为10(车载的设备)。
在hostapd.conf中相关配置如下:
##### IEEE 802.11u-2011 #######################################################
# Enable Interworking service
interworking=1
# Access Network Type
# 0 = Private network
# 1 = Private network with guest access
# 2 = Chargeable public network
# 3 = Free public network
# 4 = Personal device network
# 5 = Emergency services only network
# 14 = Test or experimental
# 15 = Wildcard
access_network_type=3
# Whether the network provides connectivity to the Internet
# 0 = Unspecified
# 1 = Network provides connectivity to the Internet
internet=1
# Additional Step Required for Access
# Note: This is only used with open network, i.e., ASRA shall ne set to 0 if
# RSN is used.
asra=0
# Emergency services reachable
esr=0
# Unauthenticated emergency service accessible
uesa=0
# Venue Info (optional)
# The available values are defined in IEEE Std 802.11u-2011, 7.3.1.34.
# Example values (group,type):
# 0,0 = Unspecified
# 1,7 = Convention Center
# 1,13 = Coffee Shop
# 2,0 = Unspecified Business
# 7,1 Private Residence
venue_group=10
venue_type=1
- 2 Apple Device IE.
该IE是Vendor IE,由Vendor自定义(ID:221(0xDD),Apple的OUI:0x00-0xA0-0x40,Sub_type:0x00),该IE需要添加在车载设备(AP)的Beacon,Probe Response和Association Response帧中。而该IE中最重要的就是其payload部分,由苹果公司自定义,有Flags,Name,Manufacture,dWds,Bluetooth MAC,Device ID等信息,细节可以查看Apple的CarPlay协议中的定义。
在hostapd.conf中相关配置如下:
这个有格式的要求:
id | len | payload |
---|---|---|
1 byte | 1byte |
长度一定要和payload长度对应上,否则无法设置成功。
0xDD 代表苹果
# Additional vendor specific elements for Beacon and Probe Response frames
# This parameter can be used to add additional vendor specific element(s) into
# the end of the Beacon and Probe Response frames. The format for these
# element(s) is a hexdump of the raw information elements (id+len+payload for
# one or more elements)
vendor_elements=dd0411223301
# Additional vendor specific elements for (Re)Association Response frames
# This parameter can be used to add additional vendor specific element(s) into
# the end of the (Re)Association Response frames. The format for these
# element(s) is a hexdump of the raw information elements (id+len+payload for
# one or more elements)
assocresp_elements=dd0411223301
使用 wpa_cli 连接一个AP
//在wpa_supplicant 成功运行后,运行wpa_cli,进行交互式命令行
wpa_cli
//执行扫描操作
scan
//获取扫描的结果
scan_result
//先添加一个网络,wpa_supplicant 会返回一个数值,表示第几个槽位。如果之前没有添加过网络则是0。
add_network
//然后设置0 的ssid
set_network 0 ssid "Leo's iPhone"
//设置0的 password
set_network 0 psk "lsw123456"
//使能 0
enable_network 0
//选择 0
select_network 0
//然后,等待ap连接成功。
//----- 另起一个窗口 或者退出当前命令行
//此时执行ifconfig 查看 interface节点信息,发现是没有配置ip的
ifconfig
// 需要执行 dhcp-6.8.2 执行dhcp来分配ip
dhcp-6.8.2 -iwlan0
//ping 网关地址
ping -Iwlan0 172.20.10.1