Android Wifi小记 (2)

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 framewlan.fc.type == 0
Control framewlan.fc.type == 1
Data framewlan.fc.type == 2
Association requestwlan.fc.type_subtype == 0x00
Association responsewlan.fc.type_subtype == 0x01
Reassociation requestwlan.fc.type_subtype == 0x02
Reassociation responsewlan.fc.type_subtype == 0x03
Probe requestwlan.fc.type_subtype == 0x04
Probe responsewlan.fc.type_subtype == 0x05
Beaconwlan.fc.type_subtype == 0x08
Disassociatewlan.fc.type_subtype == 0x0A
Authenticationwlan.fc.type_subtype == 0x0B
Deauthenticationwlan.fc.type_subtype == 0x0C
Action framewlan.fc.type_subtype == 0x0D
Block ACK requestswlan.fc.type_subtype == 0x18
Block ACKwlan.fc.type_subtype == 0x19
Power save pollwlan.fc.type_subtype == 0x1A
Request to sendwlan.fc.type_subtype == 0x1B
Clear to sendwlan.fc.type_subtype == 0x1C
ACKwlan.fc.type_subtype == 0x1D
Contention free period endwlan.fc.type_subtype == 0x1E
NULL datawlan.fc.type_subtype == 0x24
QoS datawlan.fc.type_subtype == 0x28
Null QoS datawlan.fc.type_subtype == 0x2C

Wifi Carplay hostapd.conf 配置

参考:
CarPlay wireless(蓝牙+WiFi)连接方案(Wi-Fi部分)

hostapd.conf 详解

需要配置两部分: 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中相关配置如下:
这个有格式的要求:

idlenpayload
1 byte1byte

长度一定要和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 
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Protobuf是一种高效的序列化协议,可以用于数据交换和数据存储。它的主要优势是大小小,速度快,可扩展性强。下面是使用Protobuf的一些小记: 1. 定义消息格式 首先,需要定义消息格式,以便Protobuf可以将数据序列化和反序列化。消息格式定义在.proto文件中,使用protobuf语言编写。例如,下面是一个简单的消息格式定义: ``` syntax = "proto3"; message Person { string name = 1; int32 age = 2; } ``` 这个消息格式定义了一个名为Person的消息,包含两个字段:name和age。 2. 生成代码 一旦消息格式定义好,就可以使用Protobuf编译器生成代码。编译器将根据消息格式定义生成相应的代码,包括消息类、序列化和反序列化方法等。可以使用以下命令生成代码: ``` protoc --java_out=. message.proto ``` 这将生成一个名为message.pb.java的Java类,该类包含Person消息的定义以及相关方法。 3. 序列化和反序列化 一旦生成了代码,就可以使用Protobuf序列化和反序列化数据。例如,下面是一个示例代码,将一个Person对象序列化为字节数组,并将其反序列化为另一个Person对象: ``` Person person = Person.newBuilder() .setName("Alice") .setAge(25) .build(); byte[] bytes = person.toByteArray(); Person deserializedPerson = Person.parseFrom(bytes); ``` 这个示例代码创建了一个Person对象,将其序列化为字节数组,然后将其反序列化为另一个Person对象。在这个过程中,Protobuf使用生成的代码执行序列化和反序列化操作。 以上是使用Protobuf的一些基本步骤和注意事项,希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值