- ========================================================================
- /packages/apps/Settings/src/com/android/settings/wifi/WifiMasterSwitchPreferenceController.java
- mWifiEnabler = new WifiEnabler
- (mContext, new MasterSwitchController(mWifiPreference),mMetricsFeatureProvider);
- /packages/apps/Settings/src/com/android/settings/wifi/WifiSettings.java
- new WifiEnabler(activity, new SwitchBarController(activity.getSwitchBar()),mMetricsFeatureProvider);
- ========================================================================
- /packages/apps/Settings/src/com/android/settings/widget/MasterSwitchController.java
- public class MasterSwitchController extends SwitchWidgetController implements
- Preference.OnPreferenceChangeListener { // 【Preference对应的数据(bar开关)变化会引起 onPreferenceChange】
- private final MasterSwitchPreference mPreference;
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (mListener != null) {
- return mListener.onSwitchToggled((Boolean) newValue);// 【接口回调 通知接口实现类WifiEnabler.java】
- }
- return false;
- }
- protected OnSwitchChangeListener mListener;
- public void setListener(OnSwitchChangeListener listener) {
- mListener = listener;
- }
- } MasterSwitchController ↑
- WifiEnabler(Context context, SwitchWidgetController switchWidget,
- MetricsFeatureProvider metricsFeatureProvider,ConnectivityManagerWrapper connectivityManagerWrapper) {
- mSwitchWidget = switchWidget;
- mSwitchWidget.setListener(this);
- //【在 WifiEnabler 构造方法里面设置了SwitchWidgetController监.mListener为自己 】
- ========================================================================
- /packages/apps/Settings/src/com/android/settings/wifi/WifiEnabler.java
- public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListener { // 【实现监听接口】
- private final SwitchWidgetController mSwitchWidget; 【BAR控件】
- private final WifiManager mWifiManager;
- @Override
- public boolean onSwitchToggled(boolean isChecked) {
- //Do nothing if called as a result of a state machine event
- if (mStateMachineEvent) {
- return true;
- }
- // Show toast message if Wi-Fi is not allowed in airplane mode
- if (isChecked && !WirelessUtils.isRadioAllowed(mContext, Settings.Global.RADIO_WIFI)) {
- Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
- // Reset switch to off. No infinite check/listenenr loop.
- mSwitchWidget.setChecked(false);
- return false;
- }
- // Disable tethering if enabling Wifi
- if (mayDisableTethering(isChecked)) {
- mConnectivityManager.stopTethering(ConnectivityManager.TETHERING_WIFI);
- }
- if (isChecked) {
- mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_WIFI_ON);
- } else {
- // Log if user was connected at the time of switching off.
- mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_WIFI_OFF,
- mConnected.get());
- }
- if (!mWifiManager.setWifiEnabled(isChecked)) {
- // Error
- mSwitchWidget.setEnabled(true);
- Toast.makeText(mContext, R.string.wifi_error, Toast.LENGTH_SHORT).show();
- }
- return true;
- }
- 论述:
- 1.程序通过控件 MasterSwitchController 监听了WIFI开关数据Preference, 当这个Preference的值在on/off切换的过程中
- 会触发,监听函数onPreferenceChange 。
- 2.在MasterSwitchController中有OnSwitchChangeListener监听器接口,实现该接口的是WifiEnabler对象,他们之间的关系
- 是通过 WifiEnabler 的构造函数中的 mSwitchWidget.setListener(this); 方法设置关联关系
- 3.当switch开关切换会触发WifiEnabler的 onSwitchToggled 继而继续往下WifiManager的调用
- /frameworks/base/wifi/java/android/net/wifi/WifiManager.java
- mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
- mWifiManager.setWifiEnabled(isChecked)
- "new WifiManager"
- public class WifiManager {
- IWifiManager mService; // 来源于 WifiManager 构造函数,是提供给Client进程调用Service进程方法的桩
- public boolean setWifiEnabled(boolean enabled) {
- try {
- // 调用IWifiManager桩 的 setWifiEnabled 方法
- return mService.setWifiEnabled(mContext.getOpPackageName(), enabled);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- }
- }
- }
- =========================================================================
- /frameworks/base/core/java/android/app/SystemServiceRegistry.java
- registerService(Context.WIFI_SERVICE, WifiManager.class,new CachedServiceFetcher<WifiManager>() {
- @Override
- public WifiManager createService(ContextImpl ctx) throws ServiceNotFoundException {
- IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SERVICE 【"wifi"】);
- IWifiManager service = IWifiManager.Stub.asInterface(b);
- return new WifiManager(ctx.getOuterContext(), service,ConnectivityThread.getInstanceLooper());
- }}); //【把 WifiManager注册到系统服务 服务名为 wifi,其中IWifiManager是提供给Client进程调用的桩 】
- 【通过这些桩 最终通过Binder机制调用到Service进程对应的方法中】
- =========================================================================
- /frameworks/base/wifi/java/android/net/wifi/IWifiManager.aidl AIDL里面就是所定义的桩
- interface IWifiManager
- {
- void disconnect();
- void reconnect();
- void reassociate();
- WifiInfo getConnectionInfo();
- boolean setWifiEnabled(String packageName, boolean enable);
- ......
- }
- // 【实现桩的Service 运行于系统进程中 adb shell services list 中】
- public class WifiServiceImpl extends IWifiManager.Stub {
- @Override
- public synchronized boolean setWifiEnabled(String packageName, boolean enable)
- throws RemoteException {
- enforceChangePermission();
- Slog.d(TAG, "setWifiEnabled: " + enable + " pid=" + Binder.getCallingPid()
- + ", uid=" + Binder.getCallingUid() + ", package=" + packageName);
- mLog.trace("setWifiEnabled package=% uid=% enable=%").c(packageName)
- .c(Binder.getCallingUid()).c(enable).flush();
- // If SoftAp is enabled, only Settings is allowed to toggle wifi
- boolean apEnabled =
- mWifiStateMachine.syncGetWifiApState() != WifiManager.WIFI_AP_STATE_DISABLED;
- boolean isFromSettings = checkNetworkSettingsPermission();
- if (apEnabled && !isFromSettings) {
- mLog.trace("setWifiEnabled SoftAp not disabled: only Settings can enable wifi").flush();
- return false;
- }
- /*
- * Caller might not have WRITE_SECURE_SETTINGS,
- * only CHANGE_WIFI_STATE is enforced
- */
- long ident = Binder.clearCallingIdentity();
- try {
- if (! mSettingsStore.handleWifiToggled(enable)) {
- // Nothing to do if wifi cannot be toggled
- return true;
- }
- } finally {
- Binder.restoreCallingIdentity(ident);
- }
- if (mPermissionReviewRequired) {
- final int wiFiEnabledState = getWifiEnabledState();
- if (enable) {
- if (wiFiEnabledState == WifiManager.WIFI_STATE_DISABLING
- || wiFiEnabledState == WifiManager.WIFI_STATE_DISABLED) {
- if (startConsentUi(packageName, Binder.getCallingUid(),
- WifiManager.ACTION_REQUEST_ENABLE)) {
- return true;
- }
- }
- } else if (wiFiEnabledState == WifiManager.WIFI_STATE_ENABLING
- || wiFiEnabledState == WifiManager.WIFI_STATE_ENABLED) {
- if (startConsentUi(packageName, Binder.getCallingUid(),
- WifiManager.ACTION_REQUEST_DISABLE)) {
- return true;
- }
- }
- }
- // static final int CMD_WIFI_TOGGLED = BASE + 8; sendMessage 为mWifiController父类的方法
- mWifiController.sendMessage(CMD_WIFI_TOGGLED); // 【发送消息 BASE + 8】
- return true;
- }
- }
- =========================================================================
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiController.java
- public class WifiController extends StateMachine {
- @override sendMessage(int what); //继承父类的 sendMessage
- }
- public class StateMachine {
- private static class SmHandler extends Handler {} // SmHandler 是StateMachine 内部类
- public void sendMessage(int what) {
- // mSmHandler can be null if the state machine has quit.
- SmHandler smh = mSmHandler;
- if (smh == null) return;
- smh.sendMessage(obtainMessage(what)); // 把CMD_WIFI_TOGGLED 封装为Message发送出去
- }
- private void initStateMachine(String name, Looper looper) {
- mName = name;
- mSmHandler = new SmHandler(looper, this); // 创建 SmHandler
- }
- @Override
- public final void handleMessage(Message msg) {
- if (!mHasQuit) {
- if (mSm != null && msg.what != SM_INIT_CMD && msg.what != SM_QUIT_CMD) {
- mSm.onPreHandleMessage(msg);
- }
- if (mDbg) mSm.log("handleMessage: E msg.what=" + msg.what);
- /** Save the current message */
- mMsg = msg;
- /** State that processed the message */
- State msgProcessedState = null;
- if (mIsConstructionCompleted) {
- /** Normal path */
- msgProcessedState = processMsg(msg); //【处理消息】
- } else if (!mIsConstructionCompleted && (mMsg.what == SM_INIT_CMD)
- && (mMsg.obj == mSmHandlerObj)) {
- /** Initial one time path. */
- mIsConstructionCompleted = true;
- invokeEnterMethods(0);
- } else {
- throw new RuntimeException("StateMachine.handleMessage: "
- + "The start method not called, received msg: " + msg);
- }
- performTransitions(msgProcessedState, msg); // 【处理状态的转换 执行enter方法】
- // We need to check if mSm == null here as we could be quitting.
- if (mDbg && mSm != null) mSm.log("handleMessage: X");
- if (mSm != null && msg.what != SM_INIT_CMD && msg.what != SM_QUIT_CMD) {
- mSm.onPostHandleMessage(msg); // 【传递消息】
- }
- }
- }
- }
- private class StateInfo { // 结点 构成状态树的结点
- /** The state */
- State state;
- /** The parent of this state, null if there is no parent */
- StateInfo parentStateInfo;
- /** True when the state has been entered and on the stack */
- boolean active;
- /**
- * Convert StateInfo to string
- */
- @Override
- public String toString() {
- return "state=" + state.getName() + ",active=" + active + ",parent="
- + ((parentStateInfo == null) ? "null" : parentStateInfo.state.getName());
- }
- /**
- * Process the message. If the current state doesn't handle
- * it, call the states parent and so on. If it is never handled then
- * call the state machines unhandledMessage method.
- * @return the state that processed the message
- */
- private final State processMsg(Message msg) { //【当前状态不能处理消息参数时,调用父类状态进行处理】
- // private StateInfo mStateStack[]; mStateStack = new StateInfo[maxDepth]; 存储当前状态信息的栈
- // private int mStateStackTopIndex = -1; 栈顶索引
- StateInfo curStateInfo = mStateStack[mStateStackTopIndex];
- if (mDbg) {
- mSm.log("processMsg: " + curStateInfo.state.getName());
- }
- if (isQuit(msg)) {
- transitionTo(mQuittingState);
- } else {
- while (!curStateInfo.state.processMessage(msg)) {
- // 完成栈的状态信息类遍历 对应的processMessage 方法
- /**
- * Not processed
- */
- curStateInfo = curStateInfo.parentStateInfo; // 切换状态信息类
- if (curStateInfo == null) { // 如果到底了 那么处理不了了 退出while循环
- /**
- * No parents left so it's not handled
- */
- mSm.unhandledMessage(msg);
- break;
- }
- if (mDbg) {
- mSm.log("processMsg: " + curStateInfo.state.getName());
- }
- }
- }
- return (curStateInfo != null) ? curStateInfo.state : null; // 返回当前处理了这个事件的那个状态类
- }
- class StaDisabledWithScanState extends State {
- @Override
- public boolean processMessage(Message msg) {
- switch (msg.what) {
- case CMD_WIFI_TOGGLED:
- if (mSettingsStore.isWifiToggleEnabled()) { // 如果保存的状态是打开
- if (doDeferEnable(msg)) {
- if (mHaveDeferredEnable) {
- // have 2 toggles now, inc serial number and ignore both
- mDeferredEnableSerialNumber++;
- }
- mHaveDeferredEnable = !mHaveDeferredEnable;
- break;
- }
- if (mDeviceIdle == false) {
- transitionTo(mDeviceActiveState); //切换状态 状态切换之后会执行enter操作
- } else {
- checkLocksAndTransitionWhenDeviceIdle();
- }
- }
- }
- return HANDLED;
- }
- private final void transitionTo(IState destState) {
- if (mTransitionInProgress) {
- Log.wtf(mSm.mName, "transitionTo called while transition already in progress to " +
- mDestState + ", new target state=" + destState);
- }
- mDestState = (State) destState; // 就是把目标变量mDestState 变为当前的状态,后续执行enter方法
- if (mDbg) mSm.log("transitionTo: destState=" + mDestState.getName());
- }
- private void performTransitions(State msgProcessedState, Message msg ) {
- /** 执行原来状态的exit方法 执行当前状态的enter方法
- * If transitionTo has been called, exit and then enter
- * the appropriate states. We loop on this to allow
- * enter and exit methods to use transitionTo.
- */
- State orgState = mStateStack[mStateStackTopIndex].state; // 当前栈顶状态
- State destState = mDestState; // 切换到的目标状态
- if (destState != null) {
- while (true) {
- if (mDbg) mSm.log("handleMessage: new destination call exit/enter");
- /**
- * Determine the states to exit and enter and return the
- * common ancestor state of the enter/exit states. Then
- * invoke the exit methods then the enter methods.
- */
- // 依次遍历当前状态的父状态 直到null 这些就是 enter需要执行的状态
- StateInfo commonStateInfo = setupTempStateStackWithStatesToEnter(destState);
- // flag is cleared in invokeEnterMethods before entering the target state
- mTransitionInProgress = true;
- invokeExitMethods(commonStateInfo); // 调用 exit方法
- int stateStackEnteringIndex = moveTempStateStackToStateStack(); 从状态栈第几个索引开始enter
- invokeEnterMethods(stateStackEnteringIndex); // 调用 enter方法
- /**
- * Since we have transitioned to a new state we need to have
- * any deferred messages moved to the front of the message queue
- * so they will be processed before any other messages in the
- * message queue.
- */
- moveDeferredMessageAtFrontOfQueue();
- if (destState != mDestState) {
- // A new mDestState so continue looping
- destState = mDestState;
- } else {
- // No change in mDestState so we're done
- break; // enter exit 完成 那么while循环 就结束了
- }
- }
- mDestState = null;
- }
- 最终会调用到 class StaEnabledState extends State {} 的 enter 方法中
- class StaEnabledState extends State {
- @Override
- public void enter() {
- mWifiStateMachine.setSupplicantRunning(true); //打开WIFI 开始分析 mWifiStateMachine
- }}
- class ApStaDisabledState extends State {
- @Override
- public void enter() {
- mWifiStateMachine.setSupplicantRunning(false); //进入WIFI
- }}
- ========================================================================
- WifiController.java
- import com.android.internal.util.State;
- class DefaultState extends State {
- class ApStaDisabledState extends State {
- class StaEnabledState extends State {
- class StaDisabledWithScanState extends State {
- class ApEnabledState extends State {
- class EcmState extends State {
- class DeviceActiveState extends State {
- class DeviceInactiveState extends State {
- class ScanOnlyLockHeldState extends State {
- class FullLockHeldState extends State {
- class FullHighPerfLockHeldState extends State {
- class NoLockHeldState extends State {
- WifiController.java 组成的状态树
- 十二个状态组成的单子树
- addState(mDefaultState);
- addState(mApStaDisabledState, mDefaultState);
- addState(mStaEnabledState, mDefaultState);
- addState(mDeviceActiveState, mStaEnabledState);
- addState(mDeviceInactiveState, mStaEnabledState);
- addState(mScanOnlyLockHeldState, mDeviceInactiveState);
- addState(mFullLockHeldState, mDeviceInactiveState);
- addState(mFullHighPerfLockHeldState, mDeviceInactiveState);
- addState(mNoLockHeldState, mDeviceInactiveState);
- addState(mStaDisabledWithScanState, mDefaultState);
- addState(mApEnabledState, mDefaultState);
- addState(mEcmState, mDefaultState);
- StateMachine.java
- HaltingState extends State {
- QuittingState extends State {
- /frameworks/base/core/java/com/android/internal/util/State.java
- public class State implements IState {
- protected State() {
- }
- public void enter() { // 进入
- }
- public void exit() { // 离开
- }
- public boolean processMessage(Message msg) { // 处理消息
- return false;
- }
- }
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiStateMachine.java 组成的状态树
- addState(mDefaultState);
- addState(mInitialState, mDefaultState);
- addState(mSupplicantStartingState, mDefaultState);
- addState(mSupplicantStartedState, mDefaultState);
- addState(mScanModeState, mSupplicantStartedState);
- addState(mConnectModeState, mSupplicantStartedState);
- addState(mL2ConnectedState, mConnectModeState);
- addState(mObtainingIpState, mL2ConnectedState);
- addState(mConnectedState, mL2ConnectedState);
- addState(mRoamingState, mL2ConnectedState);
- addState(mDisconnectingState, mConnectModeState);
- addState(mDisconnectedState, mConnectModeState);
- addState(mWpsRunningState, mConnectModeState);
- addState(mWaitForP2pDisableState, mSupplicantStartedState);
- addState(mSupplicantStoppingState, mDefaultState);
- addState(mSoftApState, mDefaultState);
- ========================================================================
- public class WifiController extends StateMachine { // 自己是状态机StateMachine 又包含一个状态机WifiStateMachine
- private final WifiStateMachine mWifiStateMachine;
- class StaEnabledState extends State {
- @Override
- public void enter() {
- mWifiStateMachine.setSupplicantRunning(true); //打开WIFI 开始分析 mWifiStateMachine
- }}
- }
- frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiInjector.java
- public class WifiInjector {
- private final WifiNative mWifiNative;
- private final WifiStateMachine mWifiStateMachine;
- private final WifiController mWifiController;
- mWifiNative = new WifiNative(SystemProperties.get("wifi.interface", "wlan0"),
- mWifiVendorHal, mSupplicantStaIfaceHal, mWificondControl);
- mWifiStateMachine = new WifiStateMachine(mContext, mFrameworkFacade,
- wifiStateMachineLooper, UserManager.get(mContext),
- this, mBackupManagerProxy, mCountryCode, mWifiNative);
- mWifiController = new WifiController(mContext, mWifiStateMachine, mSettingsStore,
- mLockManager, mWifiServiceHandlerThread.getLooper(), mFrameworkFacade);
- }
- WifiStateMachine.java
- public void setSupplicantRunning(boolean enable) {
- if (enable) {
- sendMessage(CMD_START_SUPPLICANT); //开启SUPPLICANT命令 同样 继承父类StateMachine的 sendMessage
- } else {
- sendMessage(CMD_STOP_SUPPLICANT);
- }
- }
- public void sendMessage(int what) {
- // mSmHandler can be null if the state machine has quit.
- SmHandler smh = mSmHandler;
- if (smh == null) return;
- smh.sendMessage(obtainMessage(what【BASE + 11】));
- }
- // 把CMD_START_SUPPLICANT 封装为Message发送出去执行到 StateMachine的handleMessage
- // 然后processMessage 切换状态 enter exit
- @Override
- public final void handleMessage(Message msg) {
- State msgProcessedState = null;
- msgProcessedState = processMsg(msg); //【处理消息】
- performTransitions(msgProcessedState, msg); // 【处理状态的转换 执行enter方法】
- mSm.onPostHandleMessage(msg); // 【传递消息】
- }
- class InitialState extends State {
- public boolean processMessage(Message message) {
- switch (message.what) {
- case CMD_START_SUPPLICANT:
- mClientInterface = mWifiNative.setupForClientMode();
- mWifiNative.enableSupplicant();
- setSupplicantLogLevel();
- transitionTo(mSupplicantStartingState);
- //切换到从InitialState切换到状态 SupplicantStartingState
- }
- }
- WifiStateMachine.java
- /* The base for wifi message types */
- static final int BASE = Protocol.BASE_WIFI;
- static final int CMD_START_SUPPLICANT = BASE + 11;
- static final int CMD_STOP_SUPPLICANT = BASE + 12;
- static final int CMD_STATIC_IP_SUCCESS = BASE + 15;
- static final int CMD_STATIC_IP_FAILURE = BASE + 16;
- static final int CMD_DRIVER_START_TIMED_OUT = BASE + 19;
- static final int CMD_START_AP = BASE + 21;
- static final int CMD_START_AP_FAILURE = BASE + 22;
- static final int CMD_STOP_AP = BASE + 23;
- static final int CMD_AP_STOPPED = BASE + 24;
- static final int CMD_BLUETOOTH_ADAPTER_STATE_CHANGE = BASE + 31;
- WifiController.java
- private static final int BASE = Protocol.BASE_WIFI_CONTROLLER;
- static final int CMD_EMERGENCY_MODE_CHANGED = BASE + 1;
- static final int CMD_SCREEN_ON = BASE + 2;
- static final int CMD_SCREEN_OFF = BASE + 3;
- static final int CMD_BATTERY_CHANGED = BASE + 4;
- static final int CMD_DEVICE_IDLE = BASE + 5;
- static final int CMD_LOCKS_CHANGED = BASE + 6;
- static final int CMD_SCAN_ALWAYS_MODE_CHANGED = BASE + 7;
- static final int CMD_WIFI_TOGGLED = BASE + 8;
- static final int CMD_AIRPLANE_TOGGLED = BASE + 9;
- static final int CMD_SET_AP = BASE + 10;
- static final int CMD_DEFERRED_TOGGLE = BASE + 11;
- static final int CMD_USER_PRESENT = BASE + 12;
- static final int CMD_AP_START_FAILURE = BASE + 13;
- static final int CMD_EMERGENCY_CALL_STATE_CHANGED = BASE + 14;
- static final int CMD_AP_STOPPED = BASE + 15;
- static final int CMD_STA_START_FAILURE = BASE + 16;
- // Command used to trigger a wifi stack restart when in active mode
- static final int CMD_RESTART_WIFI = BASE + 17;
- // Internal command used to complete wifi stack restart
- private static final int CMD_RESTART_WIFI_CONTINUE = BASE + 18;
- ========================================================================
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative.java
- public IClientInterface setupForClientMode() {
- if (!startHalIfNecessary(true)) {
- Log.e(mTAG, "Failed to start HAL for client mode");
- return null;
- }
- return mWificondControl.setupDriverForClientMode();
- }
- /**
- * Setup driver for client mode via wificond.
- * @return An IClientInterface as wificond client interface binder handler.
- * Returns null on failure.
- */
- public IClientInterface setupDriverForClientMode() {
- Log.d(TAG, "Setting up driver for client mode");
- mWificond = mWifiInjector.makeWificond();
- if (mWificond == null) {
- Log.e(TAG, "Failed to get reference to wificond");
- return null;
- }
- IClientInterface clientInterface = null;
- try {
- clientInterface = mWificond.createClientInterface();
- } catch (RemoteException e1) {
- Log.e(TAG, "Failed to get IClientInterface due to remote exception");
- return null;
- }
- if (clientInterface == null) {
- Log.e(TAG, "Could not get IClientInterface instance from wificond");
- return null;
- }
- Binder.allowBlocking(clientInterface.asBinder());
- // Refresh Handlers
- mClientInterface = clientInterface;
- try {
- mClientInterfaceName = clientInterface.getInterfaceName();
- mWificondScanner = mClientInterface.getWifiScannerImpl();
- if (mWificondScanner == null) {
- Log.e(TAG, "Failed to get WificondScannerImpl");
- return null;
- }
- Binder.allowBlocking(mWificondScanner.asBinder());
- mScanEventHandler = new ScanEventHandler();
- mWificondScanner.subscribeScanEvents(mScanEventHandler);
- mPnoScanEventHandler = new PnoScanEventHandler();
- mWificondScanner.subscribePnoScanEvents(mPnoScanEventHandler);
- } catch (RemoteException e) {
- Log.e(TAG, "Failed to refresh wificond scanner due to remote exception");
- }
- return clientInterface;
- }
- --------------------------------------------------
- mSupplicantStaIfaceHal 这个是干啥!!!
- mWifiVendorHal 这个是干啥!!!
- JNI operations
- /********************************************************
- * JNI operations
- ********************************************************/
- /* Register native functions */
- static {
- /* Native functions are defined in libwifi-service.so */
- System.loadLibrary("wifi-service");
- registerNatives();
- }
- private static native int registerNatives();
- /* kernel logging support */
- private static native byte[] readKernelLogNative()
- /frameworks/opt/net/wifi/service/jni/com_android_server_wifi_WifiNative.cpp
- /*
- * JNI registration.
- */
- static JNINativeMethod gWifiMethods[] = {
- /* name, signature, funcPtr */
- {"readKernelLogNative", "()[B", (void*)android_net_wifi_readKernelLog},
- };
- /* User to register native functions */
- extern "C"
- jint Java_com_android_server_wifi_WifiNative_registerNatives(JNIEnv* env, jclass clazz) {
- // initialization needed for unit test APK
- JniConstants::init(env);
- return jniRegisterNativeMethods(env,
- "com/android/server/wifi/WifiNative", gWifiMethods, NELEM(gWifiMethods));
- }
- }; // namespace android
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
- private SupplicantStaNetworkHal addNetwork() {
- synchronized (mLock) {
- final String methodStr = "addNetwork";
- if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
- Mutable<ISupplicantNetwork> newNetwork = new Mutable<>();
- try {
- mISupplicantStaIface.addNetwork ((SupplicantStatus status,
- ISupplicantNetwork network) -> {
- if (checkStatusAndLogFailure(status, methodStr)) {
- newNetwork.value = network;
- } //什么语法
- }) ;
- checkSupplicantStaIfaceAndLogFailure(methodStr) ?
- checkStatusAndLogFailure?
- final String methodStr = "addNetwork"; mISupplicantStaIface.addNetwork
- final String methodStr = "removeNetwork"; mISupplicantStaIface.removeNetwork
- final String methodStr = "getNetwork"; mISupplicantStaIface.getNetwork(
- final String methodStr = "registerCallback"; mISupplicantStaIface.registerCallback
- final String methodStr = "listNetworks"; mISupplicantStaIface.listNetworks((
- final String methodStr = "setWpsDeviceName"; mISupplicantStaIface.setWpsDeviceName(name)
- final String methodStr = "setWpsDeviceType"; mISupplicantStaIface.setWpsDeviceType(type);
- final String methodStr = "setWpsManufacturer"; mISupplicantStaIface.setWpsManufacturer(manufacturer)
- final String methodStr = "setWpsModelName"; mISupplicantStaIface.setWpsModelName(modelName);
- final String methodStr = "setWpsModelNumber"; mISupplicantStaIface.setWpsModelNumber(modelNumber);
- final String methodStr = "setWpsSerialNumber"; mISupplicantStaIface.setWpsSerialNumber(serialNumber);
- final String methodStr = "setWpsConfigMethods"; mISupplicantStaIface.setWpsConfigMethods(configMethods);
- final String methodStr = "reassociate"; mISupplicantStaIface.reassociate();
- final String methodStr = "reconnect"; mISupplicantStaIface.reconnect();
- final String methodStr = "disconnect"; mISupplicantStaIface.disconnect();
- final String methodStr = "setPowerSave"; mISupplicantStaIface.setPowerSave(enable);
- final String methodStr = "initiateTdlsDiscover"; mISupplicantStaIface.initiateTdlsDiscover(macAddress);
- final String methodStr = "initiateTdlsSetup"; mISupplicantStaIface.initiateTdlsSetup(macAddress)
- final String methodStr = "initiateTdlsTeardown"; mISupplicantStaIface.initiateTdlsTeardown(macAddress);
- final String methodStr = "initiateAnqpQuery"; mISupplicantStaIface.initiateAnqpQuery(macAddress,infoElements, subTypes);
- final String methodStr = "initiateHs20IconQuery"; mISupplicantStaIface.initiateHs20IconQuery(macAddress,fileName);
- final String methodStr = "getMacAddress"; mISupplicantStaIface.getMacAddress((SupplicantStatus status,byte[/* 6 */] macAddr)
- final String methodStr = "startRxFilter"; mISupplicantStaIface.startRxFilter();
- final String methodStr = "stopRxFilter"; mISupplicantStaIface.stopRxFilter();
- final String methodStr = "addRxFilter"; mISupplicantStaIface.addRxFilter(type);
- final String methodStr = "removeRxFilter"; mISupplicantStaIface.removeRxFilter(type);
- final String methodStr = "setBtCoexistenceMode"; mISupplicantStaIface.setBtCoexistenceMode(mode);
- final String methodStr = "setBtCoexistenceScanModeEnabled"; mISupplicantStaIface.setBtCoexistenceScanModeEnabled(enable);
- final String methodStr = "setSuspendModeEnabled"; mISupplicantStaIface.setSuspendModeEnabled(enable);
- final String methodStr = "setCountryCode"; mISupplicantStaIface.setCountryCode(code);
- final String methodStr = "startWpsRegistrar"; mISupplicantStaIface.startWpsRegistrar(bssid, pin);
- final String methodStr = "startWpsPbc"; mISupplicantStaIface.startWpsPbc(bssid);
- final String methodStr = "startWpsPinKeypad"; mISupplicantStaIface.startWpsPinKeypad(pin);
- final String methodStr = "startWpsPinDisplay"; mISupplicantStaIface.startWpsPinDisplay(
- final String methodStr = "cancelWps"; mISupplicantStaIface.cancelWps();
- final String methodStr = "setExternalSim"; mISupplicantStaIface.setExternalSim(useExternalSim);
- final String methodStr = "enableAutoReconnect"; mISupplicantStaIface.enableAutoReconnect(enable);
- final String methodStr = "setDebugParams"; mISupplicant.setDebugParams(level, showTimestamp, showKeys);
- final String methodStr = "setConcurrencyPriority"; mISupplicant.setConcurrencyPriority(type);
- private ISupplicantStaIface mISupplicantStaIface;
- private ISupplicant mISupplicant;
- private boolean initSupplicantStaIface() {
- /** List all supplicant Ifaces */
- final ArrayList<ISupplicant.IfaceInfo> supplicantIfaces = new ArrayList<>();
- try {
- mISupplicant.listInterfaces((SupplicantStatus status,
- ArrayList<ISupplicant.IfaceInfo> ifaces) -> {
- if (status.code != SupplicantStatusCode.SUCCESS) {
- Log.e(TAG, "Getting Supplicant Interfaces failed: " + status.code);
- return;
- }
- supplicantIfaces.addAll(ifaces);
- });
- }
- // HIDL HAL Interface Define Lagurage
- if (supplicantIfaces.size() == 0) {
- Log.e(TAG, "Got zero HIDL supplicant ifaces. Stopping supplicant HIDL startup.");
- return false;
- }
- Mutable<ISupplicantIface> supplicantIface = new Mutable<>();
- Mutable<String> ifaceName = new Mutable<>();
- for (ISupplicant.IfaceInfo ifaceInfo : supplicantIfaces) {
- if (ifaceInfo.type == IfaceType.STA) {
- try { // mISupplicant.getInterface 很重要他得到在Client端代理Service服务端Proxy的IBinder
- mISupplicant.getInterface(ifaceInfo,
- (SupplicantStatus status, ISupplicantIface【IBinder】 iface) -> {
- if (status.code != SupplicantStatusCode.SUCCESS) {
- Log.e(TAG, "Failed to get ISupplicantIface " + status.code);
- return;
- }
- supplicantIface.value = iface【IBinder】;
- });
- } catch (RemoteException e) {
- Log.e(TAG, "ISupplicant.getInterface exception: " + e);
- return false;
- }
- ifaceName.value = ifaceInfo.name;
- break;
- }
- }
- mISupplicantStaIface = getStaIfaceMockable(supplicantIface.value);
- }
- private boolean initSupplicantService() {
- synchronized (mLock) {
- try {
- mISupplicant = getSupplicantMockable();
- }
- }
- }
- protected ISupplicantStaIface getStaIfaceMockable(ISupplicantIface iface) {
- return ISupplicantStaIface.asInterface(iface.asBinder());
- }
- protected ISupplicant getSupplicantMockable() throws RemoteException {
- return ISupplicant.getService();
- }
- ========================================================
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicant.hal
- package android.hardware.wifi.supplicant@1.0;
- import ISupplicantCallback;
- import ISupplicantIface;
- interface ISupplicant {
- enum DebugLevel : uint32_t {
- EXCESSIVE = 0,
- MSGDUMP = 1,
- DEBUG = 2,
- INFO = 3,
- WARNING = 4,
- ERROR = 5
- };
- struct IfaceInfo {
- IfaceType type;
- string name;
- };
- getInterface(IfaceInfo ifaceInfo)
- generates (SupplicantStatus status, ISupplicantIface iface);
- listInterfaces() generates (SupplicantStatus status, vec<IfaceInfo> ifaces);
- registerCallback(ISupplicantCallback callback) generates (SupplicantStatus status);
- setDebugParams(DebugLevel level, bool showTimestamp, bool showKeys) generates (SupplicantStatus status);
- getDebugLevel() generates (DebugLevel level);
- isDebugShowTimestampEnabled() generates (bool enabled);
- isDebugShowKeysEnabled() generates (bool enabled);
- setConcurrencyPriority(IfaceType type) generates (SupplicantStatus status);
- };
- ========================================================
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaIface.hal
- package android.hardware.wifi.supplicant@1.0;
- import ISupplicantIface;
- import ISupplicantStaIfaceCallback;
- interface ISupplicantStaIface extends ISupplicantIface {
- enum AnqpInfoId : uint16_t {
- VENUE_NAME = 258,
- ROAMING_CONSORTIUM = 261,
- IP_ADDR_TYPE_AVAILABILITY = 262,
- NAI_REALM = 263,
- ANQP_3GPP_CELLULAR_NETWORK = 264,
- DOMAIN_NAME = 268
- };
- enum Hs20AnqpSubtypes : uint32_t {
- OPERATOR_FRIENDLY_NAME = 3,
- WAN_METRICS = 4,
- CONNECTION_CAPABILITY = 5,
- OSU_PROVIDERS_LIST = 8,
- };
- enum RxFilterType : uint8_t {
- V4_MULTICAST = 0,
- V6_MULTICAST = 1
- };
- enum BtCoexistenceMode : uint8_t {
- ENABLED = 0,
- DISABLED = 1,
- SENSE = 2
- };
- enum ExtRadioWorkDefaults : uint32_t {
- TIMEOUT_IN_SECS = 10
- };
- registerCallback(ISupplicantStaIfaceCallback callback) generates (SupplicantStatus status);
- reassociate() generates (SupplicantStatus status);
- reconnect() generates (SupplicantStatus status);
- disconnect() generates (SupplicantStatus status);
- setPowerSave(bool enable) generates (SupplicantStatus status);
- initiateTdlsDiscover(MacAddress macAddress) generates (SupplicantStatus status);
- initiateTdlsSetup(MacAddress macAddress) generates (SupplicantStatus status);
- initiateTdlsTeardown(MacAddress macAddress)generates (SupplicantStatus status);
- initiateAnqpQuery(MacAddress macAddress,vec<AnqpInfoId> infoElements,vec<Hs20AnqpSubtypes> subTypes)
- generates (SupplicantStatus status);
- initiateHs20IconQuery(MacAddress macAddress, string fileName) generates (SupplicantStatus status);
- getMacAddress() generates (SupplicantStatus status, MacAddress macAddr);
- startRxFilter() generates (SupplicantStatus status);
- stopRxFilter() generates (SupplicantStatus status);
- addRxFilter(RxFilterType type) generates (SupplicantStatus status);
- removeRxFilter(RxFilterType type) generates (SupplicantStatus status);
- setBtCoexistenceMode(BtCoexistenceMode mode) generates (SupplicantStatus status);
- setBtCoexistenceScanModeEnabled(bool enable) generates (SupplicantStatus status);
- setSuspendModeEnabled(bool enable) generates (SupplicantStatus status);
- setCountryCode(int8_t[2] code) generates (SupplicantStatus status);
- startWpsRegistrar(Bssid bssid, string pin) generates (SupplicantStatus status);
- startWpsPbc(Bssid bssid) generates (SupplicantStatus status);
- startWpsPinKeypad(string pin) generates (SupplicantStatus status);
- startWpsPinDisplay(Bssid bssid) generates (SupplicantStatus status, string generatedPin);
- cancelWps() generates (SupplicantStatus status);
- setExternalSim(bool useExternalSim) generates (SupplicantStatus status);
- addExtRadioWork(string name, uint32_t freqInMhz, uint32_t timeoutInSec) generates (SupplicantStatus status, uint32_t id);
- removeExtRadioWork(uint32_t id) generates (SupplicantStatus status);
- enableAutoReconnect(bool enable) generates (SupplicantStatus status);
- };
- ========================================================
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantIface.hal
- package android.hardware.wifi.supplicant@1.0;
- import ISupplicantNetwork;
- /**
- * Interface exposed by the supplicant for each network interface (e.g wlan0)
- * it controls.
- */
- interface ISupplicantIface {
- enum ParamSizeLimits : uint32_t {
- WPS_DEVICE_NAME_MAX_LEN = 32,
- WPS_MANUFACTURER_MAX_LEN = 64,
- WPS_MODEL_NAME_MAX_LEN = 32,
- WPS_MODEL_NUMBER_MAX_LEN = 32,
- WPS_SERIAL_NUMBER_MAX_LEN = 32
- };
- getName() generates (SupplicantStatus status, string name);
- getType() generates (SupplicantStatus status, IfaceType type);
- addNetwork() generates (SupplicantStatus status, ISupplicantNetwork network);
- removeNetwork(SupplicantNetworkId id) generates (SupplicantStatus status);
- getNetwork(SupplicantNetworkId id) generates (SupplicantStatus status, ISupplicantNetwork network);
- listNetworks() generates (SupplicantStatus status, vec<SupplicantNetworkId> networkIds);
- setWpsDeviceName(string name) generates (SupplicantStatus status);
- setWpsDeviceType(uint8_t[8] type) generates (SupplicantStatus status);
- setWpsManufacturer(string manufacturer) generates (SupplicantStatus status);
- setWpsModelName(string modelName) generates (SupplicantStatus status);
- setWpsModelNumber(string modelNumber) generates (SupplicantStatus status);
- setWpsSerialNumber(string serialNumber) generates (SupplicantStatus status);
- setWpsConfigMethods(bitfield<WpsConfigMethods> configMethods) generates (SupplicantStatus status);
- };
- ========================================================
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h
- namespace android {
- namespace hardware {
- namespace wifi {
- namespace supplicant {
- namespace V1_0 {
- namespace implementation {
- class StaIface
- : public android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface
- { // 【实现 HIDL接口 ISupplicantStaIface的类】
- public:
- StaIface(struct wpa_global* wpa_global, const char ifname[]);
- ~StaIface() override = default;
- void invalidate();
- bool isValid();
- // Hidl methods exposed.
- Return<void> getName(getName_cb _hidl_cb) override;
- Return<void> getType(getType_cb _hidl_cb) override;
- Return<void> addNetwork(addNetwork_cb _hidl_cb) override;
- Return<void> removeNetwork(SupplicantNetworkId id, removeNetwork_cb _hidl_cb) override;
- Return<void> getNetwork(SupplicantNetworkId id, getNetwork_cb _hidl_cb) override;
- Return<void> listNetworks(listNetworks_cb _hidl_cb) override;
- Return<void> registerCallback(const sp<ISupplicantStaIfaceCallback>& callback,registerCallback_cb _hidl_cb) override;
- Return<void> reassociate(reassociate_cb _hidl_cb) override;
- Return<void> reconnect(reconnect_cb _hidl_cb) override;
- Return<void> disconnect(disconnect_cb _hidl_cb) override;
- Return<void> setPowerSave(bool enable, setPowerSave_cb _hidl_cb) override;
- Return<void> initiateTdlsDiscover(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsDiscover_cb _hidl_cb) override;
- Return<void> initiateTdlsSetup(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsSetup_cb _hidl_cb) override;
- Return<void> initiateTdlsTeardown(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsTeardown_cb _hidl_cb) override;
- Return<void> initiateAnqpQuery(const hidl_array<uint8_t, 6>& mac_address,const hidl_vec<ISupplicantStaIface::AnqpInfoId>& info_elements,const hidl_vec<ISupplicantStaIface::Hs20AnqpSubtypes>& sub_types,initiateAnqpQuery_cb _hidl_cb) override;
- Return<void> initiateHs20IconQuery(const hidl_array<uint8_t, 6>& mac_address,const hidl_string& file_name,initiateHs20IconQuery_cb _hidl_cb) override;
- Return<void> getMacAddress(getMacAddress_cb _hidl_cb) override;
- Return<void> startRxFilter(startRxFilter_cb _hidl_cb) override;
- Return<void> stopRxFilter(stopRxFilter_cb _hidl_cb) override;
- Return<void> addRxFilter(ISupplicantStaIface::RxFilterType type,addRxFilter_cb _hidl_cb) override;
- Return<void> removeRxFilter(ISupplicantStaIface::RxFilterType type,removeRxFilter_cb _hidl_cb) override;
- Return<void> setBtCoexistenceMode(ISupplicantStaIface::BtCoexistenceMode mode,setBtCoexistenceMode_cb _hidl_cb) override;
- Return<void> setBtCoexistenceScanModeEnabled(bool enable, setBtCoexistenceScanModeEnabled_cb _hidl_cb) override;
- Return<void> setSuspendModeEnabled(bool enable, setSuspendModeEnabled_cb _hidl_cb) override;
- Return<void> setCountryCode(const hidl_array<int8_t, 2>& code,setCountryCode_cb _hidl_cb) override;
- Return<void> startWpsRegistrar(const hidl_array<uint8_t, 6>& bssid, const hidl_string& pin,startWpsRegistrar_cb _hidl_cb) override;
- Return<void> startWpsPbc(const hidl_array<uint8_t, 6>& bssid,startWpsPbc_cb _hidl_cb) override;
- Return<void> startWpsPinKeypad(const hidl_string& pin, startWpsPinKeypad_cb _hidl_cb) override;
- Return<void> startWpsPinDisplay(const hidl_array<uint8_t, 6>& bssid,startWpsPinDisplay_cb _hidl_cb) override;
- Return<void> cancelWps(cancelWps_cb _hidl_cb) override;
- Return<void> setWpsDeviceName(const hidl_string& name, setWpsDeviceName_cb _hidl_cb) override;
- Return<void> setWpsDeviceType(const hidl_array<uint8_t, 8>& type,setWpsDeviceType_cb _hidl_cb) override;
- Return<void> setWpsManufacturer(const hidl_string& manufacturer,setWpsManufacturer_cb _hidl_cb) override;
- Return<void> setWpsModelName(const hidl_string& model_name,setWpsModelName_cb _hidl_cb) override;
- Return<void> setWpsModelNumber(const hidl_string& model_number,setWpsModelNumber_cb _hidl_cb) override;
- Return<void> setWpsSerialNumber(const hidl_string& serial_number,setWpsSerialNumber_cb _hidl_cb) override;
- Return<void> setWpsConfigMethods(uint16_t config_methods, setWpsConfigMethods_cb _hidl_cb) override;
- Return<void> setExternalSim(bool useExternalSim, setExternalSim_cb _hidl_cb) override;
- Return<void> addExtRadioWork(const hidl_string& name, uint32_t freq_in_mhz,uint32_t timeout_in_sec, addExtRadioWork_cb _hidl_cb) override;
- Return<void> removeExtRadioWork(uint32_t id, removeExtRadioWork_cb _hidl_cb) override;
- Return<void> enableAutoReconnect(bool enable, enableAutoReconnect_cb _hidl_cb) override;
- =============================================================================
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.c
- using hidl_return_util::validateAndCall; // HIDL函数 都是调用这个接口?
- StaIface::StaIface(struct wpa_global *wpa_global, const char ifname[])
- : wpa_global_(wpa_global), ifname_(ifname), is_valid_(true)
- {
- }
- Return<void> StaIface::getName(getName_cb _hidl_cb)
- {
- return validateAndCall(
- this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
- &StaIface::getNameInternal 【作用函数】, _hidl_cb);
- }
- Return<void> StaIface::getType(getType_cb _hidl_cb)
- {
- return validateAndCall(
- this【作用对象】, SupplicantStatusCode::FAILURE_IFACE_INVALID【无效状态码】,
- &StaIface::getTypeInternal 【WorkFuncT 调用的方法 【作用函数】】, _hidl_cb【回调】);
- }
- Return<void> StaIface::enableAutoReconnect(
- bool enable, enableAutoReconnect_cb _hidl_cb)
- {
- return validateAndCall(
- this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
- &StaIface::enableAutoReconnectInternal【作用函数】, _hidl_cb, enable);
- }
- template <typename ObjT, typename WorkFuncT, typename... Args>
- Return<void> validateAndCall(
- ObjT* obj, SupplicantStatusCode status_code_if_invalid, WorkFuncT&& work,
- const std::function<void(const SupplicantStatus&)>& hidl_cb, Args&&... args)
- {
- if (obj->isValid()) {
- //【如果ObjT 有效,那么执行方法WorkFuncT,并把WorkFuncT返回值作为参数 执行回调方法 hidl_cb】
- hidl_cb((obj->*work)(std::forward<Args>(args)...)); // 没有返回值的回调
- } else {
- //【如果ObjT 无效 执行回调方法 hidl_cb,参数为 SupplicantStatusCode::FAILURE_IFACE_INVALID【无效状态码】】
- hidl_cb({status_code_if_invalid, ""});
- }
- return Void();
- }
- template <typename ObjT, typename WorkFuncT, typename ReturnT, typename... Args>
- Return<void> validateAndCall(
- ObjT* obj, SupplicantStatusCode status_code_if_invalid, WorkFuncT&& work,
- const std::function<void(const SupplicantStatus&, ReturnT 【有一个返回值的回调】)>& hidl_cb,
- Args&&... args)
- {
- if (obj->isValid()) {
- const auto& ret_pair =
- (obj->*work)(std::forward<Args>(args)...);
- const SupplicantStatus& status = std::get<0>(ret_pair);
- const auto& ret_value = std::get<1>(ret_pair);
- hidl_cb(status, ret_value); // 【一个返回值的回调,回调需要两个参数】
- } else {
- hidl_cb(
- {status_code_if_invalid, ""},
- typename std::remove_reference<ReturnT>::type());
- }
- return Void();
- }
- Return<void> validateAndCall(
- ObjT* obj, SupplicantStatusCode status_code_if_invalid, WorkFuncT&& work,
- const std::function<void(const SupplicantStatus&, ReturnT1, ReturnT2)>&
- hidl_cb 【两个返回值的回调,回调需要三个参数】,
- Args&&... args)
- {
- if (obj->isValid()) {
- const auto& ret_tuple =
- (obj->*work)(std::forward<Args>(args)...);
- const SupplicantStatus& status = std::get<0>(ret_tuple);
- const auto& ret_value1 = std::get<1>(ret_tuple);
- const auto& ret_value2 = std::get<2>(ret_tuple);
- hidl_cb(status, ret_value1, ret_value2);
- } else {
- hidl_cb(
- {status_code_if_invalid, ""},
- typename std::remove_reference<ReturnT1>::type(),
- typename std::remove_reference<ReturnT2>::type());
- }
- return Void();
- }
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.c
- Return<void> StaIface::enableAutoReconnect(
- bool enable, enableAutoReconnect_cb _hidl_cb)
- {
- return validateAndCall(
- this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
- &StaIface::enableAutoReconnectInternal 【作用函数】, _hidl_cb, enable);
- }
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.c
- SupplicantStatus StaIface::enableAutoReconnectInternal(bool enable)
- {
- struct wpa_supplicant *wpa_s = retrieveIfacePtr();
- wpa_s->auto_reconnect_disabled = enable ? 0 : 1; // 设置了结构体 wpa_s->auto_reconnect_disabled
- return {SupplicantStatusCode::SUCCESS, ""}; // 感觉像返回了元组,这个元组进入回调
- }
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.c
- Return<void> StaIface::getMacAddress(getMacAddress_cb _hidl_cb)
- {
- return validateAndCall(
- this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
- &StaIface::getMacAddressInternal, _hidl_cb);
- }
- constexpr char kGetMacAddress[] = "MACADDR";
- StaIface::getMacAddressInternal()
- {
- struct wpa_supplicant *wpa_s = retrieveIfacePtr();
- std::vector<char> cmd(kGetMacAddress 【"MACADDR" 指针】, kGetMacAddress【初始化位置】 + sizeof(kGetMacAddress) 【字符串大小】);
- char driver_cmd_reply_buf[4096] = {};
- // 调用驱动执行命令 MACADDR 得到参数返回值 driver_cmd_reply_buf"Macaddr = XX:XX:XX:XX:XX:XX"
- //函数返回值 ret 代表 命令是否执行成功
- int ret = wpa_drv_driver_cmd(wpa_s, cmd.data(), driver_cmd_reply_buf,sizeof(driver_cmd_reply_buf));
- // Reply is of the format: "Macaddr = XX:XX:XX:XX:XX:XX"
- std::string reply_str = driver_cmd_reply_buf;
- // 如果调用失败的情况发生 那么返回 执行失败的元组
- if (ret < 0 || reply_str.empty() || reply_str.find("=") == std::string::npos) {
- return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
- }
- eply_str.erase(remove_if(reply_str.begin(), reply_str.end(), isspace),reply_str.end());
- std::string mac_addr_str =reply_str.substr(reply_str.find("=") + 1, reply_str.size()); // 截取子字符串=后的
- std::array<uint8_t, 6> mac_addr; //字节数组
- if (hwaddr_aton(mac_addr_str.c_str(), mac_addr.data())) {
- //【hwaddr_aton(const char *txt, u8 *addr)】 Convert ASCII string to MAC address
- // 0 on success, -1 on failure MAC address as a string (e.g., "00:11:22:33:44:55")
- return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
- }
- // 返回 SupplicantStatusCode 和 mac字节数组的元组
- return {{SupplicantStatusCode::SUCCESS, ""}, mac_addr};
- }
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
- /** See ISupplicant.hal for documentation */
- public boolean enableAutoReconnect(boolean enable) {
- synchronized (mLock) {
- final String methodStr = "enableAutoReconnect";
- if (!checkSupplicantAndLogFailure(methodStr)) return false;
- try { // enableAutoReconnect 不需要参数返回值 单单只需要返回状态就可以
- SupplicantStatus status = mISupplicantStaIface.enableAutoReconnect(enable);
- return checkStatusAndLogFailure(status, methodStr);
- } catch (RemoteException e) {
- handleRemoteException(e, methodStr);
- return false;
- }
- }
- }
- public String getMacAddress() {
- synchronized (mLock) {
- final String methodStr = "getMacAddress";
- if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
- Mutable<String> gotMac = new Mutable<>();
- try { // getMacAddress函数 需要参数返回值macAddr,所以需要->{}来表示回调方法,在回调方法内取得
- // 除了SupplicantStatus 之外的参数 ->{} 是对元组的操作
- mISupplicantStaIface.getMacAddress((SupplicantStatus status,
- byte[/* 6 */] macAddr) -> {
- if (checkStatusAndLogFailure(status, methodStr)) {
- // 回调函数,把{{SupplicantStatusCode::SUCCESS, ""}, mac_addr} 中的mac_addr 进行回调提取
- gotMac.value = NativeUtil.macAddressFromByteArray(macAddr);
- }
- });
- } catch (RemoteException e) {
- handleRemoteException(e, methodStr);
- }
- return gotMac.value;
- }
- }
- =============================================================================
- disconnect 从 .hal 文件开始到 与驱动交互结束分析 -------开始
- disconnect(disconnect_cb _hidl_cb)--->disconnectInternal()--->wpas_request_disconnection(wpa_s)
- --->wpa_drv_deauthenticate()--->wpa_s->driver->deauthenticate--->NL80211_CMD_DISCONNECT
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h
- Return<void> disconnect(disconnect_cb _hidl_cb) override;
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp
- Return<void> StaIface::disconnect(disconnect_cb _hidl_cb)
- {
- return validateAndCall(this, SupplicantStatusCode::FAILURE_IFACE_INVALID, &StaIface::disconnectInternal, _hidl_cb);
- }
- SupplicantStatus StaIface::disconnectInternal()
- {
- struct wpa_supplicant *wpa_s = retrieveIfacePtr();
- if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
- return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
- }
- wpas_request_disconnection(wpa_s); // 请求断开函数
- return {SupplicantStatusCode::SUCCESS, ""};
- }
- /external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.c
- void wpas_request_disconnection(struct wpa_supplicant *wpa_s)
- {
- #ifdef CONFIG_SME
- wpa_s->sme.prev_bssid_set = 0;
- #endif /* CONFIG_SME */
- wpa_s->reassociate = 0;
- wpa_s->disconnected = 1;
- wpa_supplicant_cancel_sched_scan(wpa_s);
- wpa_supplicant_cancel_scan(wpa_s);
- #define WLAN_REASON_DEAUTH_LEAVING 3
- wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
- eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
- }
- void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,int reason_code)
- {
- wpa_drv_deauthenticate(wpa_s, addr, reason_code);
- wpa_supplicant_event(wpa_s, EVENT_DEAUTH, &event);
- }
- /external/wpa_supplicant_8/wpa_supplicant/driver_i.h
- static inline int wpa_drv_deauthenticate(struct wpa_supplicant *wpa_s,const u8 *addr, int reason_code)
- {
- if (wpa_s->driver->deauthenticate) {
- return wpa_s->driver->deauthenticate(wpa_s->drv_priv, addr,reason_code); 【与驱动交互】
- }
- return -1;
- }
- /external/wpa_supplicant_8/src/drivers/driver_nl80211.c
- //【 nl80211对应的驱动提供的接口函数 wpa_s->driver 数据结构】
- const struct wpa_driver_ops wpa_driver_nl80211_ops = {
- //<span style="white-space:pre;"> </span>ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,reason_code, 0);
- .deauthenticate = driver_nl80211_deauthenticate,
- }
- disconnect 从 .hal 文件开始到 与驱动交互结束分析 -------结束
- =============================================================================
- /frameworks/opt/net/wifi/service/jni/com_android_server_wifi_WifiNative.cpp
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative.java
- doBooleanCommand("SET device_name " + name); ======= mSupplicantStaIfaceHal.setWpsDeviceName(name);
- doBooleanCommand("SET serial_number " + value); =====mSupplicantStaIfaceHal.setWpsSerialNumber(value);
- doBooleanCommand("SET ps 1"); doBooleanCommand("SET ps 0");===mSupplicantStaIfaceHal.setPowerSave(enabled);
- doBooleanCommand("DISCONNECT"); =======mSupplicantStaIfaceHal.disconnect();
- doBooleanCommand("DRIVER SETSUSPENDMODE 1"); doBooleanCommand("DRIVER SETSUSPENDMODE 0");
- ======mSupplicantStaIfaceHal.setSuspendModeEnabled(enabled);
- 变化好大好大
- 总结:
- 在安卓8.0 大规模删除了原有的JNI函数的注册 ~~~使用HIDL定义了很多 对应的接口,直接调用这些接口进行IPC交互
- 改动太大 太大~~~~
- 猜测的目的可能是为了Treable计划,使得上层Framework往下变得解耦
- 使得上下层能独立更新,用户更新系统时不依赖于硬件的限制
- disconnect(disconnect_cb _hidl_cb)--->disconnectInternal()--->wpas_request_disconnection(wpa_s)
- --->wpa_drv_deauthenticate()--->wpa_s->driver->deauthenticate--->NL80211_CMD_DISCONNECT
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h
- Return<void> disconnect(disconnect_cb _hidl_cb) override;
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp
- Return<void> StaIface::disconnect(disconnect_cb _hidl_cb)
- {
- return validateAndCall(this, SupplicantStatusCode::FAILURE_IFACE_INVALID,&StaIface::disconnectInternal, _hidl_cb);
- }
- SupplicantStatus StaIface::disconnectInternal()
- {
- struct wpa_supplicant *wpa_s = retrieveIfacePtr();
- if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
- return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
- }
- wpas_request_disconnection(wpa_s); // 请求断开函数
- return {SupplicantStatusCode::SUCCESS, ""};
- }
- /external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.c
- void wpas_request_disconnection(struct wpa_supplicant *wpa_s)
- {
- #ifdef CONFIG_SME
- wpa_s->sme.prev_bssid_set = 0;
- #endif /* CONFIG_SME */
- wpa_s->reassociate = 0;
- wpa_s->disconnected = 1;
- wpa_supplicant_cancel_sched_scan(wpa_s);
- wpa_supplicant_cancel_scan(wpa_s);
- #define WLAN_REASON_DEAUTH_LEAVING 3
- wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
- eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
- }
- void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,int reason_code)
- {
- wpa_drv_deauthenticate(wpa_s, addr, reason_code);
- wpa_supplicant_event(wpa_s, EVENT_DEAUTH, &event);
- }
- /external/wpa_supplicant_8/wpa_supplicant/driver_i.h
- static inline int wpa_drv_deauthenticate(struct wpa_supplicant *wpa_s,const u8 *addr, int reason_code)
- {
- if (wpa_s->driver->deauthenticate) {
- return wpa_s->driver->deauthenticate(wpa_s->drv_priv, addr,reason_code); 【与驱动交互】
- }
- return -1;
- }
- /external/wpa_supplicant_8/src/drivers/driver_nl80211.c
- //【 nl80211对应的驱动提供的接口函数 wpa_s->driver 数据结构】
- const struct wpa_driver_ops wpa_driver_nl80211_ops = {
- //ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,reason_code, 0);
- .deauthenticate = driver_nl80211_deauthenticate,
- }
- 【 HIDL方法 追踪 】
- // Hidl methods exposed.
- Return<void> getName(getName_cb _hidl_cb) override;
- Return<void> getType(getType_cb _hidl_cb) override;
- Return<void> addNetwork(addNetwork_cb _hidl_cb) override;
- Return<void> removeNetwork(SupplicantNetworkId id, removeNetwork_cb _hidl_cb) override;
- Return<void> getNetwork(SupplicantNetworkId id, getNetwork_cb _hidl_cb) override;
- Return<void> listNetworks(listNetworks_cb _hidl_cb) override;
- Return<void> registerCallback(const sp<ISupplicantStaIfaceCallback>& callback,registerCallback_cb _hidl_cb) override;
- Return<void> reassociate(reassociate_cb _hidl_cb) override;
- Return<void> reconnect(reconnect_cb _hidl_cb) override;
- Return<void> disconnect(disconnect_cb _hidl_cb) override; 【8 disconnect_cb】
- Return<void> setPowerSave(bool enable, setPowerSave_cb _hidl_cb) override;
- Return<void> initiateTdlsDiscover(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsDiscover_cb _hidl_cb) override;
- Return<void> initiateTdlsSetup(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsSetup_cb _hidl_cb) override;
- Return<void> initiateTdlsTeardown(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsTeardown_cb _hidl_cb) override;
- Return<void> initiateAnqpQuery(const hidl_array<uint8_t, 6>& mac_address,const hidl_vec<ISupplicantStaIface::AnqpInfoId>& info_elements,const hidl_vec<ISupplicantStaIface::Hs20AnqpSubtypes>& sub_types,initiateAnqpQuery_cb _hidl_cb) override;
- Return<void> initiateHs20IconQuery(const hidl_array<uint8_t, 6>& mac_address,const hidl_string& file_name,initiateHs20IconQuery_cb _hidl_cb) override;
- Return<void> getMacAddress(getMacAddress_cb _hidl_cb) override;
- Return<void> startRxFilter(startRxFilter_cb _hidl_cb) override;
- Return<void> stopRxFilter(stopRxFilter_cb _hidl_cb) override;
- Return<void> addRxFilter(ISupplicantStaIface::RxFilterType type,addRxFilter_cb _hidl_cb) override;
- Return<void> removeRxFilter(ISupplicantStaIface::RxFilterType type,removeRxFilter_cb _hidl_cb) override;
- Return<void> setBtCoexistenceMode(ISupplicantStaIface::BtCoexistenceMode mode,setBtCoexistenceMode_cb _hidl_cb) override;
- Return<void> setBtCoexistenceScanModeEnabled(bool enable, setBtCoexistenceScanModeEnabled_cb _hidl_cb) override;
- Return<void> setSuspendModeEnabled(bool enable, setSuspendModeEnabled_cb _hidl_cb) override;
- Return<void> setCountryCode(const hidl_array<int8_t, 2>& code,setCountryCode_cb _hidl_cb) override;
- Return<void> startWpsRegistrar(const hidl_array<uint8_t, 6>& bssid, const hidl_string& pin,startWpsRegistrar_cb _hidl_cb) override;
- Return<void> startWpsPbc(const hidl_array<uint8_t, 6>& bssid,startWpsPbc_cb _hidl_cb) override;
- Return<void> startWpsPinKeypad(const hidl_string& pin, startWpsPinKeypad_cb _hidl_cb) override;
- Return<void> startWpsPinDisplay(const hidl_array<uint8_t, 6>& bssid,startWpsPinDisplay_cb _hidl_cb) override;
- Return<void> cancelWps(cancelWps_cb _hidl_cb) override;
- Return<void> setWpsDeviceName(const hidl_string& name, setWpsDeviceName_cb _hidl_cb) override;
- Return<void> setWpsDeviceType(const hidl_array<uint8_t, 8>& type,setWpsDeviceType_cb _hidl_cb) override;
- Return<void> setWpsManufacturer(const hidl_string& manufacturer,setWpsManufacturer_cb _hidl_cb) override;
- Return<void> setWpsModelName(const hidl_string& model_name,setWpsModelName_cb _hidl_cb) override;
- Return<void> setWpsModelNumber(const hidl_string& model_number,setWpsModelNumber_cb _hidl_cb) override;
- Return<void> setWpsSerialNumber(const hidl_string& serial_number,setWpsSerialNumber_cb _hidl_cb) override;
- Return<void> setWpsConfigMethods(uint16_t config_methods, setWpsConfigMethods_cb _hidl_cb) override;
- Return<void> setExternalSim(bool useExternalSim, setExternalSim_cb _hidl_cb) override;
- Return<void> addExtRadioWork(const hidl_string& name, uint32_t freq_in_mhz,uint32_t timeout_in_sec, addExtRadioWork_cb _hidl_cb) override;
- Return<void> removeExtRadioWork(uint32_t id, removeExtRadioWork_cb _hidl_cb) override;
- Return<void> enableAutoReconnect(bool enable, enableAutoReconnect_cb _hidl_cb) override;
- =====================================【】===========================
- =======================================【1 getName_cb 】===================================
- getName(getName_cb _hidl_cb) --->getNameInternal()--->{{SupplicantStatusCode::SUCCESS, ""}, ifname_}
- Return<void> getName(getName_cb _hidl_cb) override;
- std::pair<SupplicantStatus, std::string> StaIface::getNameInternal()
- {
- return {{SupplicantStatusCode::SUCCESS, ""}, ifname_};
- }
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp
- =====================================【2 getType_cb 】==============================================
- getType(getType_cb _hidl_cb) ---> getTypeInternal()---> {{SupplicantStatusCode::SUCCESS, ""}, IfaceType::STA}
- Return<void> getType(getType_cb _hidl_cb) override;
- std::pair<SupplicantStatus, IfaceType> StaIface::getTypeInternal()
- {
- return {{SupplicantStatusCode::SUCCESS, ""}, IfaceType::STA};
- }
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp
- =====================================【3 addNetwork_cb 】===========================
- addNetwork(addNetwork_cb _hidl_cb) ---> addNetworkInternal() ---> wpa_supplicant_add_network(wpa_s)
- --->wpa_config_add_network(wpa_s->conf)--->wpa_config_add_network()
- Return<void> addNetwork(addNetwork_cb _hidl_cb) override;
- std::pair<SupplicantStatus, sp<ISupplicantNetwork>>
- StaIface::addNetworkInternal()
- {
- android::sp<ISupplicantStaNetwork> network;
- struct wpa_supplicant *wpa_s = retrieveIfacePtr();
- struct wpa_ssid *ssid = wpa_supplicant_add_network(wpa_s);
- HidlManager *hidl_manager = HidlManager::getInstance();
- hidl_manager->getStaNetworkHidlObjectByIfnameAndNetworkId(wpa_s->ifname, ssid->id, &network)
- return {{SupplicantStatusCode::SUCCESS, ""}, network};
- }
- int HidlManager::getStaNetworkHidlObjectByIfnameAndNetworkId(const std::string &ifname, int network_id,
- android::sp<ISupplicantStaNetwork> *network_object)
- {
- if (ifname.empty() || network_id < 0 || !network_object) return 1;
- // Generate the key to be used to lookup the network.
- const std::string network_key = getNetworkObjectMapKey(ifname, network_id);
- auto network_object_iter = sta_network_object_map_.find(network_key);
- if (network_object_iter == sta_network_object_map_.end()) return 1;
- *network_object = network_object_iter->second;
- return 0;
- }
- struct wpa_ssid * wpa_supplicant_add_network(struct wpa_supplicant *wpa_s)
- {
- struct wpa_ssid *ssid;
- ssid = wpa_config_add_network(wpa_s->conf);
- wpas_notify_network_added(wpa_s, ssid);
- ssid->disabled = 1;
- wpa_config_set_network_defaults(ssid);
- return ssid;
- }
- struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)
- {
- wpa_config_update_prio_list(config);
- }
- int wpa_config_update_prio_list(struct wpa_config *config)
- {
- wpa_config_add_prio_network(config, ssid)
- }
- int wpa_config_add_prio_network(struct wpa_config *config,struct wpa_ssid *ssid){
- nlist = os_realloc_array(config->pssid, config->num_prio + 1,sizeof(struct wpa_ssid *));
- nlist[prio] = ssid;<span style="white-space:pre;"> </span>
- }
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,WPAS_DBUS_NEW_IFACE_INTERFACE,sig_name)
- dbus_message_iter_init_append(msg, &iter);
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/hidl_manager.cpp
- /external/wpa_supplicant_8/wpa_supplicant/config.c
- /external/wpa_supplicant_8/wpa_supplicant/dbus/dbus_new.c
- =====================================【3 removeNetwork_cb 】===========================
- removeNetwork(removeNetwork_cb _hidl_cb) ---> removeNetworkInternal() ---> wpa_supplicant_remove_network(wpa_s)
- --->wpa_supplicant_deauthenticate(wpa_s->conf)--->wpa_drv_deauthenticate()--->NL80211_CMD_DISCONNECT
- Return<void> removeNetwork(SupplicantNetworkId id, removeNetwork_cb _hidl_cb) override;
- SupplicantStatus StaIface::removeNetworkInternal(SupplicantNetworkId id)
- {
- struct wpa_supplicant *wpa_s = retrieveIfacePtr();
- int result = wpa_supplicant_remove_network(wpa_s, id);
- }
- int wpa_supplicant_remove_network(struct wpa_supplicant *wpa_s, int id)
- {
- wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
- }
- void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,int reason_code)
- {
- wpa_drv_deauthenticate(wpa_s, addr, reason_code);
- }
- static inline int wpa_drv_deauthenticate(struct wpa_supplicant *wpa_s,const u8 *addr, int reason_code)
- {
- return wpa_s->driver->deauthenticate(wpa_s->drv_priv, addr,reason_code);
- }
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp
- /external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.c
- /external/wpa_supplicant_8/wpa_supplicant/driver_i.h
- /external/wpa_supplicant_8/src/drivers/driver_nl80211.c
- =====================================【4 getNetwork_cb 】===========================
- Return<void> getNetwork(SupplicantNetworkId id, getNetwork_cb _hidl_cb) override;
- P2pIface::getNetworkInternal(SupplicantNetworkId id)
- {
- android::sp<ISupplicantP2pNetwork> network;
- struct wpa_supplicant* wpa_s = retrieveIfacePtr();
- struct wpa_ssid* ssid = wpa_config_get_network(wpa_s->conf, id);
- }
- =====================================【5 listNetworks_cb 】===========================
- Return<void> listNetworks(listNetworks_cb _hidl_cb) override;
- StaIface::listNetworksInternal()
- {
- std::vector<SupplicantNetworkId> network_ids;
- struct wpa_supplicant *wpa_s = retrieveIfacePtr();
- for (struct wpa_ssid *wpa_ssid = wpa_s->conf->ssid; wpa_ssid;wpa_ssid = wpa_ssid->next) {
- network_ids.emplace_back(wpa_ssid->id);
- }
- return {{SupplicantStatusCode::SUCCESS, ""}, std::move(network_ids)};
- }
- =====================================【6 registerCallback_cb 】===========================
- Return<void> registerCallback(const sp<ISupplicantStaIfaceCallback>& callback,registerCallback_cb _hidl_cb) override;
- SupplicantStatus StaIface::registerCallbackInternal( const sp<ISupplicantStaIfaceCallback> &callback)
- {
- HidlManager *hidl_manager = HidlManager::getInstance();
- <span style="white-space:pre;"> </span>if (!hidl_manager || hidl_manager->addStaIfaceCallbackHidlObject(ifname_, callback)) {
- return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
- }
- return {SupplicantStatusCode::SUCCESS, ""};
- }
- =====================================【7 reassociate 】===========================
- Return<void> reassociate(reassociate_cb _hidl_cb) override;
- SupplicantStatus StaIface::reassociateInternal()
- {
- struct wpa_supplicant *wpa_s = retrieveIfacePtr();
- if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
- return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
- }
- wpas_request_connection(wpa_s);
- return {SupplicantStatusCode::SUCCESS, ""};
- }
- void wpas_request_connection(struct wpa_supplicant *wpa_s)
- {
- wpa_supplicant_fast_associate(wpa_s)
- }
- int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
- {
- wpas_select_network_from_last_scan(wpa_s, 0, 1);
- }
- wpas_select_network_from_last_scan(){
- wpa_supplicant_connect(wpa_s, selected, ssid)
- }
- wpa_supplicant_associate(wpa_s, selected, ssid);
- =====================================【7 reconnect_cb 】===========================
- Return<void> reconnect(reconnect_cb _hidl_cb) override;
- SupplicantStatus StaIface::reconnectInternal()
- {
- struct wpa_supplicant *wpa_s = retrieveIfacePtr();
- wpas_request_connection(wpa_s);
- return {SupplicantStatusCode::SUCCESS, ""};
- }
- void wpas_request_connection(struct wpa_supplicant *wpa_s)
- {
- wpa_supplicant_reinit_autoscan(wpa_s);
- wpa_supplicant_fast_associate(wpa_s)
- }
- =====================================【8 disconnect_cb】================================
- disconnect(disconnect_cb _hidl_cb)--->disconnectInternal()--->wpas_request_disconnection(wpa_s)
- --->wpa_drv_deauthenticate()--->wpa_s->driver->deauthenticate--->NL80211_CMD_DISCONNECT
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp
- /external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.c
- /external/wpa_supplicant_8/wpa_supplicant/driver_i.h
- /external/wpa_supplicant_8/src/drivers/driver_nl80211.c
- =====================================【 setPowerSave 】===========================
- Return<void> setPowerSave(bool enable, setPowerSave_cb _hidl_cb) override;
- SupplicantStatus StaIface::setPowerSaveInternal(bool enable)
- {
- struct wpa_supplicant *wpa_s = retrieveIfacePtr();
- wpa_drv_set_p2p_powersave(wpa_s, enable, -1, -1))
- return {SupplicantStatusCode::SUCCESS, ""};
- }
- static inline int wpa_drv_set_p2p_powersave(struct wpa_supplicant *wpa_s,int legacy_ps, int opp_ps,
- int ctwindow)
- {
- if (!wpa_s->driver->set_p2p_powersave) return -1;
- return wpa_s->driver->set_p2p_powersave(wpa_s->drv_priv, legacy_ps,opp_ps, ctwindow);
- }
- =====================================【 getMacAddress 】===========================
- Return<void> getMacAddress(getMacAddress_cb _hidl_cb) override;
- std::pair<SupplicantStatus, std::array<uint8_t, 6>>
- StaIface::getMacAddressInternal()
- {
- struct wpa_supplicant *wpa_s = retrieveIfacePtr();
- char driver_cmd_reply_buf[4096] = {};
- int ret = wpa_drv_driver_cmd(wpa_s, cmd.data(), driver_cmd_reply_buf,
- }
- static inline int wpa_drv_driver_cmd(struct wpa_supplicant *wpa_s,
- <span style="white-space:pre;"> </span> char *cmd, char *buf, size_t buf_len)
- {
- if (!wpa_s->driver->driver_cmd)
- return -1;
- return wpa_s->driver->driver_cmd(wpa_s->drv_priv, cmd, buf, buf_len);
- }
- =================================================================================
- 【实现HIDL接口? ISupplicantStaIface 这个HIDL接口?】
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h
- StaIface : public android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface
- 【实现HIDL接口? ISupplicant 这个HIDL接口?】
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/supplicant.h
- class Supplicant : public android::hardware::wifi::supplicant::V1_0::ISupplicant
- 【实现HIDL接口? ISupplicantP2pIface 这个HIDL接口?】
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/p2p_iface.h
- class P2pIface : public android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/p2p_network.h
- 【实现HIDL接口? ISupplicantP2pNetwork 这个HIDL接口?】
- class P2pNetwork : public ISupplicantP2pNetwork
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_network.h
- 【实现HIDL接口? ISupplicantStaNetwork 这个HIDL接口?】
- class StaNetwork : public ISupplicantStaNetwork
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaIface.hal 【ok】
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantIface.hal
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicant.hal 【ok】
- 【未找到对应的实现类 但存在#include <android/hardware/wifi/supplicant/1.0/ISupplicantCallback.h> 】
- 【应该是.bp 文件进行了转换】
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantCallback.hal
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantNetwork.hal
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantP2pIface.hal 【ok】
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantP2pIfaceCallback.hal
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantP2pNetwork.hal 【ok】
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantP2pNetworkCallback.hal
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaIface.hal
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaIfaceCallback.hal
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaNetwork.hal 【ok】
- /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaNetworkCallback.hal
- /hardware/interfaces/wifi/supplicant/1.0/types.hal
- interface ISupplicantStaIface extends ISupplicantIface { }
- interface ISupplicantIface { }
- interface ISupplicant {}
- interface ISupplicantCallback {}
- interface ISupplicantNetwork {}
- interface ISupplicantP2pIface {}
- interface ISupplicantP2pIfaceCallback {}
- interface ISupplicantP2pNetwork {}
- interface ISupplicantP2pNetworkCallback {}
- interface ISupplicantStaIface {}
- interface ISupplicantStaIfaceCallback {}
- interface ISupplicantStaNetwork {}
- interface ISupplicantStaNetworkCallback {}
- interface types {}
- =================================================================================
- 在 /hardware/interfaces/wifi/supplicant/1.0/ 定义了suplicant对应的HIDL 接口
- 在 /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/ 实现了上述supplicant对应的上述接口
- /hardware/interfaces/wifi/supplicant/1.0/ 【为supplicant定义的hidl接口】
- ISupplicant.hal 29-Aug-2017 5.1 KiB
- ISupplicantCallback.hal 29-Aug-2017 1.4 KiB
- ISupplicantIface.hal 29-Aug-2017 7.8 KiB
- ISupplicantNetwork.hal 29-Aug-2017 2.3 KiB
- ISupplicantP2pIface.hal 29-Aug-2017 25.7 KiB
- ISupplicantP2pIfaceCallback.hal 29-Aug-2017 7.9 KiB
- ISupplicantP2pNetwork.hal 29-Aug-2017 4.7 KiB
- ISupplicantP2pNetworkCallback.hal 29-Aug-2017 1 KiB
- ISupplicantStaIface.hal 29-Aug-2017 16.8 KiB
- ISupplicantStaIfaceCallback.hal 29-Aug-2017 17.4 KiB
- ISupplicantStaNetwork.hal 29-Aug-2017 36.1 KiB
- ISupplicantStaNetworkCallback.hal 29-Aug-2017 2.3 KiB
- types.hal 29-Aug-2017 3 KiB
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/
- hidl.cpp 29-Aug-2017 14.8 KiB
- hidl.h 29-Aug-2017 8.2 KiB
- hidl_constants.h 29-Aug-2017 578
- hidl_i.h 29-Aug-2017 513
- hidl_manager.cpp 29-Aug-2017 51.6 KiB
- hidl_manager.h 29-Aug-2017 24.7 KiB
- hidl_return_util.h 29-Aug-2017 3.2 KiB
- iface_config_utils.cpp 29-Aug-2017 5.7 KiB
- iface_config_utils.h 29-Aug-2017 1.8 KiB
- misc_utils.h 29-Aug-2017 1.8 KiB
- p2p_iface.cpp 29-Aug-2017 40 KiB
- p2p_iface.h 29-Aug-2017 12.8 KiB
- p2p_network.cpp 29-Aug-2017 7.3 KiB
- p2p_network.h 29-Aug-2017 3.4 KiB
- sta_iface.cpp 29-Aug-2017 30.7 KiB
- sta_iface.h 29-Aug-2017 10 KiB
- sta_network.cpp 29-Aug-2017 58.5 KiB
- sta_network.h 29-Aug-2017 14.3 KiB
- supplicant.cpp 29-Aug-2017 5.5 KiB
- supplicant.h 29-Aug-2017 2.9 KiB
- /hardware/interfaces/wifi/1.0/ 路径下定义了一些操作wifi硬件的hal接口 .hal
- /hardware/interfaces/wifi/1.0/default/ 实现了上述定义的接口 .c .h
- /hardware/interfaces/wifi/1.0/
- IWifi.hal 29-Aug-2017 4.1 KiB
- IWifiApIface.hal 29-Aug-2017 1.9 KiB
- IWifiChip.hal 29-Aug-2017 26.1 KiB
- IWifiChipEventCallback.hal 29-Aug-2017 3.6 KiB
- IWifiEventCallback.hal 29-Aug-2017 1.5 KiB
- IWifiIface.hal 29-Aug-2017 1.4 KiB
- IWifiNanIface.hal 29-Aug-2017 10.3 KiB
- IWifiNanIfaceEventCallback.hal 29-Aug-2017 12.4 KiB
- IWifiP2pIface.hal 29-Aug-2017 832
- IWifiRttController.hal 29-Aug-2017 6.4 KiB
- IWifiRttControllerEventCallback.hal 29-Aug-2017 990
- IWifiStaIface.hal 29-Aug-2017 20.9 KiB
- IWifiStaIfaceEventCallback.hal 29-Aug-2017 2.3 KiB
- types.hal 29-Aug-2017 69.4 KiB
- /hardware/interfaces/wifi/1.0/default/ //实现上述.hal 文件定义的接口
- hidl_callback_util.h 29-Aug-2017 3.6 KiB
- hidl_return_util.h 29-Aug-2017 3.8 KiB
- hidl_struct_util.cpp 29-Aug-2017 89.7 KiB
- hidl_struct_util.h 29-Aug-2017 7 KiB
- hidl_sync_util.cpp 29-Aug-2017 1.1 KiB
- hidl_sync_util.h 29-Aug-2017 1.2 KiB
- service.cpp 29-Aug-2017 1.4 KiB
- THREADING.README 29-Aug-2017 1.9 KiB
- wifi.cpp 29-Aug-2017 6.6 KiB
- wifi.h 29-Aug-2017 2.6 KiB
- wifi_ap_iface.cpp 29-Aug-2017 3.6 KiB
- wifi_ap_iface.h 29-Aug-2017 2.2 KiB
- wifi_chip.cpp 29-Aug-2017 33.1 KiB
- wifi_chip.h 29-Aug-2017 9.2 KiB
- wifi_feature_flags.h 29-Aug-2017 1.1 KiB
- wifi_legacy_hal.cpp 29-Aug-2017 49.9 KiB
- wifi_legacy_hal.h 29-Aug-2017 13.7 KiB
- wifi_legacy_hal_stubs.cpp 29-Aug-2017 6.1 KiB
- wifi_legacy_hal_stubs.h 29-Aug-2017 1.1 KiB
- wifi_mode_controller.cpp 29-Aug-2017 2.3 KiB
- wifi_mode_controller.h 29-Aug-2017 1.8 KiB
- wifi_nan_iface.cpp 29-Aug-2017 29.6 KiB
- wifi_nan_iface.h 29-Aug-2017 6.4 KiB
- wifi_p2p_iface.cpp 29-Aug-2017 2.1 KiB
- wifi_p2p_iface.h 29-Aug-2017 1.8 KiB
- wifi_rtt_controller.cpp 29-Aug-2017 11.3 KiB
- wifi_rtt_controller.h 29-Aug-2017 4.3 KiB
- wifi_sta_iface.cpp 29-Aug-2017 24.5 KiB
- wifi_sta_iface.h 29-Aug-2017 7 KiB
- wifi_status_util.cpp 29-Aug-2017 3.5 KiB
- wifi_status_util.h 29-Aug-2017 1.4 KiB
- ========================================================================================
- /hardware/interfaces/wifi/supplicant/1.0/Android.bp 里面应该写了一些.hal 文件转为 .h 文件的方法
- // This file is autogenerated by hidl-gen. Do not edit manually.
- filegroup {
- name: "[email protected]_hal",
- srcs: [
- "types.hal",
- "ISupplicant.hal",
- "ISupplicantCallback.hal",
- "ISupplicantIface.hal",
- "ISupplicantNetwork.hal",
- "ISupplicantP2pIface.hal",
- "ISupplicantP2pIfaceCallback.hal",
- "ISupplicantP2pNetwork.hal",
- "ISupplicantP2pNetworkCallback.hal",
- "ISupplicantStaIface.hal",
- "ISupplicantStaIfaceCallback.hal",
- "ISupplicantStaNetwork.hal",
- "ISupplicantStaNetworkCallback.hal",
- ],
- }
- genrule {
- name: "[email protected]_genc++",
- tools: ["hidl-gen"],
- cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport [email protected]",
- srcs: [
- ":[email protected]_hal",
- ],
- out: [
- "android/hardware/wifi/supplicant/1.0/types.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantAll.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantCallbackAll.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantIfaceAll.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantNetworkAll.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantP2pIfaceAll.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantP2pIfaceCallbackAll.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantP2pNetworkAll.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantP2pNetworkCallbackAll.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantStaIfaceAll.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantStaIfaceCallbackAll.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantStaNetworkAll.cpp",
- "android/hardware/wifi/supplicant/1.0/SupplicantStaNetworkCallbackAll.cpp",
- ],
- }
- genrule {
- name: "[email protected]_genc++_headers",
- tools: ["hidl-gen"],
- cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport [email protected]",
- srcs: [
- ":[email protected]_hal",
- ],
- out: [
- "android/hardware/wifi/supplicant/1.0/types.h",
- "android/hardware/wifi/supplicant/1.0/hwtypes.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicant.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicant.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicant.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicant.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicant.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicantCallback.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicantCallback.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicantCallback.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicantCallback.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicantCallback.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicantIface.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicantIface.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicantIface.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicantIface.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicantIface.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicantNetwork.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicantNetwork.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicantNetwork.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicantNetwork.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicantNetwork.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicantP2pIface.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicantP2pIface.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicantP2pIface.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicantP2pIface.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicantP2pIface.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicantP2pIfaceCallback.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicantP2pIfaceCallback.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicantP2pIfaceCallback.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicantP2pIfaceCallback.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicantP2pIfaceCallback.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicantP2pNetwork.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicantP2pNetwork.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicantP2pNetwork.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicantP2pNetwork.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicantP2pNetwork.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicantP2pNetworkCallback.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicantP2pNetworkCallback.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicantP2pNetworkCallback.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicantP2pNetworkCallback.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicantP2pNetworkCallback.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicantStaIface.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicantStaIface.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicantStaIface.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicantStaIface.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicantStaIface.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicantStaIfaceCallback.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicantStaIfaceCallback.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicantStaIfaceCallback.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicantStaIfaceCallback.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicantStaIfaceCallback.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicantStaNetwork.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicantStaNetwork.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicantStaNetwork.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicantStaNetwork.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicantStaNetwork.h",
- "android/hardware/wifi/supplicant/1.0/ISupplicantStaNetworkCallback.h",
- "android/hardware/wifi/supplicant/1.0/IHwSupplicantStaNetworkCallback.h",
- "android/hardware/wifi/supplicant/1.0/BnHwSupplicantStaNetworkCallback.h",
- "android/hardware/wifi/supplicant/1.0/BpHwSupplicantStaNetworkCallback.h",
- "android/hardware/wifi/supplicant/1.0/BsSupplicantStaNetworkCallback.h",
- ],
- }
- cc_library_shared {
- name: "[email protected]",
- defaults: ["hidl-module-defaults"],
- generated_sources: ["[email protected]_genc++"],
- generated_headers: ["[email protected]_genc++_headers"],
- export_generated_headers: ["[email protected]_genc++_headers"],
- vendor_available: true,
- shared_libs: [
- "libhidlbase",
- "libhidltransport",
- "libhwbinder",
- "liblog",
- "libutils",
- "libcutils",
- "[email protected]",
- ],
- export_shared_lib_headers: [
- "libhidlbase",
- "libhidltransport",
- "libhwbinder",
- "libutils",
- "[email protected]",
- ],
- }
- ========================================================================================
- /hardware/interfaces/wifi/1.0/default/[email protected]
- service wifi_hal_legacy /vendor/bin/hw/[email protected]
- class hal
- user wifi
- group wifi gps
- =================================================================================
- ##############################################
- # android8.0 安卓8.0 定义的hal的接口文件
- # Do not change this file except to add new interfaces. Changing
- # pre-existing interfaces will fail VTS and break framework-only OTAs
- # HALs released in Android O
- [email protected]::IDevice
- [email protected]::IDevicesFactory
- [email protected]::IPrimaryDevice
- [email protected]::IStream
- [email protected]::IStreamIn
- [email protected]::IStreamOut
- [email protected]::IStreamOutCallback
- [email protected]::types
- [email protected]::types
- [email protected]::IAcousticEchoCancelerEffect
- [email protected]::IAutomaticGainControlEffect
- [email protected]::IBassBoostEffect
- [email protected]::IDownmixEffect
- [email protected]::IEffect
- [email protected]::IEffectBufferProviderCallback
- [email protected]::IEffectsFactory
- [email protected]::IEnvironmentalReverbEffect
- [email protected]::IEqualizerEffect
- [email protected]::ILoudnessEnhancerEffect
- [email protected]::INoiseSuppressionEffect
- [email protected]::IPresetReverbEffect
- [email protected]::IVirtualizerEffect
- [email protected]::IVisualizerEffect
- [email protected]::types
- [email protected]::IEvsCamera
- [email protected]::IEvsCameraStream
- [email protected]::IEvsDisplay
- [email protected]::IEvsEnumerator
- [email protected]::types
- [email protected]::IVehicle
- [email protected]::IVehicleCallback
- [email protected]::types
- [email protected]::IBiometricsFingerprint
- [email protected]::IBiometricsFingerprintClientCallback
- [email protected]::types
- [email protected]::IBluetoothHci
- [email protected]::IBluetoothHciCallbacks
- [email protected]::types
- [email protected]::IBootControl
- [email protected]::types
- [email protected]::IBroadcastRadio
- [email protected]::IBroadcastRadioFactory
- [email protected]::ITuner
- [email protected]::ITunerCallback
- [email protected]::types
- [email protected]::types
- [email protected]::ICameraDevice
- [email protected]::ICameraDeviceCallback
- [email protected]::ICameraDevicePreviewCallback
- [email protected]::types
- [email protected]::ICameraDevice
- [email protected]::ICameraDeviceCallback
- [email protected]::ICameraDeviceSession
- [email protected]::types
- [email protected]::types
- [email protected]::ICameraProvider
- [email protected]::ICameraProviderCallback
- [email protected]::ISurfaceFlingerConfigs
- [email protected]::types
- [email protected]::IContexthub
- [email protected]::IContexthubCallback
- [email protected]::types
- [email protected]::ICryptoFactory
- [email protected]::ICryptoPlugin
- [email protected]::IDrmFactory
- [email protected]::IDrmPlugin
- [email protected]::IDrmPluginListener
- [email protected]::types
- [email protected]::IDumpstateDevice
- [email protected]::IGatekeeper
- [email protected]::types
- [email protected]::IAGnss
- [email protected]::IAGnssCallback
- [email protected]::IAGnssRil
- [email protected]::IAGnssRilCallback
- [email protected]::IGnss
- [email protected]::IGnssBatching
- [email protected]::IGnssBatchingCallback
- [email protected]::IGnssCallback
- [email protected]::IGnssConfiguration
- [email protected]::IGnssDebug
- [email protected]::IGnssGeofenceCallback
- [email protected]::IGnssGeofencing
- [email protected]::IGnssMeasurement
- [email protected]::IGnssMeasurementCallback
- [email protected]::IGnssNavigationMessage
- [email protected]::IGnssNavigationMessageCallback
- [email protected]::IGnssNi
- [email protected]::IGnssNiCallback
- [email protected]::IGnssXtra
- [email protected]::IGnssXtraCallback
- [email protected]::types
- [email protected]::IAllocator
- [email protected]::IGraphicBufferProducer
- [email protected]::IProducerListener
- [email protected]::types
- [email protected]::IComposer
- [email protected]::IComposerCallback
- [email protected]::IComposerClient
- [email protected]::types
- [email protected]::IMapper
- [email protected]::types
- [email protected]::IHealth
- [email protected]::types
- [email protected]::IConsumerIr
- [email protected]::types
- [email protected]::IKeymasterDevice
- [email protected]::types
- [email protected]::ILight
- [email protected]::types
- [email protected]::types
- [email protected]::IGraphicBufferSource
- [email protected]::IOmx
- [email protected]::IOmxBufferSource
- [email protected]::IOmxNode
- [email protected]::IOmxObserver
- [email protected]::IOmxStore
- [email protected]::types
- [email protected]::IMemtrack
- [email protected]::types
- [email protected]::INfc
- [email protected]::INfcClientCallback
- [email protected]::types
- [email protected]::IPower
- [email protected]::types
- [email protected]::IRadio
- [email protected]::IRadioIndication
- [email protected]::IRadioResponse
- [email protected]::ISap
- [email protected]::ISapCallback
- [email protected]::types
- android.hardware.radio.deprecated@1.0::IOemHook
- android.hardware.radio.deprecated@1.0::IOemHookIndication
- android.hardware.radio.deprecated@1.0::IOemHookResponse
- [email protected]::IContext
- [email protected]::IDevice
- [email protected]::types
- [email protected]::ISensors
- [email protected]::types
- [email protected]::ISoundTriggerHw
- [email protected]::ISoundTriggerHwCallback
- [email protected]::types
- [email protected]::IThermal
- [email protected]::types
- [email protected]::IHdmiCec
- [email protected]::IHdmiCecCallback
- [email protected]::types
- [email protected]::ITvInput
- [email protected]::ITvInputCallback
- [email protected]::types
- [email protected]::IUsb
- [email protected]::IUsbCallback
- [email protected]::types
- [email protected]::IVibrator
- [email protected]::types
- [email protected]::IVr
- [email protected]::IWifi
- [email protected]::IWifiApIface
- [email protected]::IWifiChip
- [email protected]::IWifiChipEventCallback
- [email protected]::IWifiEventCallback
- [email protected]::IWifiIface
- [email protected]::IWifiNanIface
- [email protected]::IWifiNanIfaceEventCallback
- [email protected]::IWifiP2pIface
- [email protected]::IWifiRttController
- [email protected]::IWifiRttControllerEventCallback
- [email protected]::IWifiStaIface
- [email protected]::IWifiStaIfaceEventCallback
- [email protected]::types
- [email protected]::ISupplicant
- [email protected]::ISupplicantCallback
- [email protected]::ISupplicantIface
- [email protected]::ISupplicantNetwork
- [email protected]::ISupplicantP2pIface
- [email protected]::ISupplicantP2pIfaceCallback
- [email protected]::ISupplicantP2pNetwork
- [email protected]::ISupplicantP2pNetworkCallback
- [email protected]::ISupplicantStaIface
- [email protected]::ISupplicantStaIfaceCallback
- [email protected]::ISupplicantStaNetwork
- [email protected]::ISupplicantStaNetworkCallback
- [email protected]::types
- ##############################################
- ===============================wificond的一些分析(安卓8.0才开始出现)↓======================
- //system/connectivity/wificond/aidl/android/net/wifi/IWificond.aidl
- // Service interface that exposes primitives for controlling the WiFi
- // subsystems of a device.
- interface IWificond {
- @nullable IApInterface createApInterface();
- @nullable IClientInterface createClientInterface();
- void tearDownInterfaces();
- }
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiInjector.java
- public IWificond makeWificond() {
- // We depend on being able to refresh our binder in WifiStateMachine, so don't cache it.
- IBinder binder = ServiceManager.getService(WIFICOND_SERVICE_NAME【"wificond"】);
- return IWificond.Stub.asInterface(binder);
- }
- adb shell service list | findstr wifi
- 59 wifip2p: [android.net.wifi.p2p.IWifiP2pManager]
- 60 rttmanager: [android.net.wifi.IRttManager]
- 61 wifiscanner: [android.net.wifi.IWifiScanner]
- 62 wifi: [android.net.wifi.IWifiManager]
- 125 wificond: [] // 没有具体的内容 只知道是系统的后台运行服务service
- ============================================
- /system/sepolicy/private/wificond.te
- typeattribute wificond coredomain;
- init_daemon_domain(wificond)
- hal_client_domain(wificond, hal_wifi_offload)
- ============================================
- /system/sepolicy/public/wificond.te
- # wificond
- type wificond, domain;
- type wificond_exec, exec_type, file_type;
- binder_use(wificond)
- binder_call(wificond, system_server)
- add_service(wificond, wificond_service)
- set_prop(wificond, wifi_prop)
- set_prop(wificond, ctl_default_prop)
- # create sockets to set interfaces up and down
- allow wificond self:udp_socket create_socket_perms;
- # setting interface state up/down is a privileged ioctl
- allowxperm wificond self:udp_socket ioctl { SIOCSIFFLAGS };
- allow wificond self:capability { net_admin net_raw };
- # allow wificond to speak to nl80211 in the kernel
- allow wificond self:netlink_socket create_socket_perms_no_ioctl;
- # newer kernels (e.g. 4.4 but not 4.1) have a new class for sockets
- allow wificond self:netlink_generic_socket create_socket_perms_no_ioctl;
- r_dir_file(wificond, proc_net)
- # wificond writes out configuration files for wpa_supplicant/hostapd.
- # wificond also reads pid files out of this directory
- allow wificond wifi_data_file:dir rw_dir_perms;
- allow wificond wifi_data_file:file create_file_perms;
- # allow wificond to check permission for dumping logs
- allow wificond permission_service:service_manager find;
- # dumpstate support
- allow wificond dumpstate:fd use;
- allow wificond dumpstate:fifo_file write;
- ============================================
- /system/connectivity/wificond/wificond.rc
- service wificond /system/bin/wificond
- class main
- user wifi
- group wifi net_raw net_admin
- ============================================
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WificondControl.java
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative.java
- /**
- * Disable wpa_supplicant via wificond. 关闭wpa_supplicant通过 wificond
- * @return Returns true on success.
- */
- public boolean disableSupplicant() {
- return mWificondControl.disableSupplicant();
- }
- /**
- * Enable wpa_supplicant via wificond. 打开wpa_supplicant通过 wificond
- * @return Returns true on success.
- */
- public boolean enableSupplicant() {
- return mWificondControl.enableSupplicant();
- }
- ===============================wificond的一些分析(安卓8.0才开始出现)↑======================
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative.java
- /**
- * Disable wpa_supplicant via wificond. 关闭wpa_supplicant通过 wificond
- * @return Returns true on success.
- */
- public boolean disableSupplicant() {
- return mWificondControl.disableSupplicant();
- }
- /**
- * Enable wpa_supplicant via wificond. 打开wpa_supplicant通过 wificond
- * @return Returns true on success.
- */
- public boolean enableSupplicant() {
- return mWificondControl.enableSupplicant();
- }
- =========================WifiInjector↓================================
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiInjector.java
- public class WifiInjector {
- private final WificondControl mWificondControl;
- public WifiInjector(Context context) {
- mWifiMonitor = new WifiMonitor(this);
- mHalDeviceManager = new HalDeviceManager(); // 这个类是什么?
- // IWifiVendor.Hal 文件? ISupplicantStaIface.Hal 文件
- mWifiVendorHal =new WifiVendorHal(mHalDeviceManager, mWifiStateMachineHandlerThread.getLooper());
- mSupplicantStaIfaceHal = new SupplicantStaIfaceHal(mContext, mWifiMonitor);
- mWificondControl = new WificondControl(this, mWifiMonitor);
- mWifiNative = new WifiNative(SystemProperties.get("wifi.interface", "wlan0"),mWifiVendorHal, mSupplicantStaIfaceHal, mWificondControl);
- //----------------------P2P相关--------------------------
- mWifiP2pMonitor = new WifiP2pMonitor(this);
- mSupplicantP2pIfaceHal = new SupplicantP2pIfaceHal(mWifiP2pMonitor);
- mWifiP2pNative = new WifiP2pNative(SystemProperties.get("wifi.direct.interface","p2p0"),mSupplicantP2pIfaceHal);
- //依赖 handlerThread 的对象 Now get instances of all the objects that depend on the HandlerThreads
- mTrafficPoller = new WifiTrafficPoller(mContext,mWifiServiceHandlerThread.getLooper(),mWifiNative.getInterfaceName());
- mCountryCode = new WifiCountryCode(mWifiNative,SystemProperties.get(BOOT_DEFAULT_WIFI_COUNTRY_CODE),
- mContext.getResources().getBoolean(R.bool.config_wifi_revert_country_code_on_cellular_loss));
- mWifiApConfigStore = new WifiApConfigStore(mContext, mBackupManagerProxy);
- }
- private static final String BOOT_DEFAULT_WIFI_COUNTRY_CODE = "ro.boot.wificountrycode";
- =========================WifiInjector↑================================
- =========================WifiMonitor 的作用==================
- 【 WifiMonitor 的作用:】监听来自 wpa_supplicant的事件,不请自来的事件,相当于attach函数被调用
- Listens for events from the wpa_supplicant server, and passes them on
- to the {@link StateMachine} for handling.
- 主要就是包含了两个MAP
- 一个Map mHandlerMap 保存 (key=接口名字,value=需要处理事件的handler集合)
- 一个map mMonitoringMap 用于保存当前的 ( key=接口名字,value=是否监听对应事件 Boolean )
- private final Map<String, SparseArray<Set<Handler>>> mHandlerMap = new HashMap<>();
- private final Map<String, Boolean> mMonitoringMap = new HashMap<>();
- // TODO(b/27569474) remove support for multiple handlers for the same event
- private final Map<String, SparseArray<Set<Handler>>> mHandlerMap = new HashMap<>();
- // registerHandler 是在WifiMonitor注册监听函数,需要两个key 一个 iface 和 what
- // 这样能统一找到对某一事件感兴趣的 handler集合
- public synchronized void registerHandler(String iface, int what, Handler handler) {
- SparseArray<Set<Handler>> ifaceHandlers = mHandlerMap.get(iface);
- if (ifaceHandlers == null) {
- ifaceHandlers = new SparseArray<>();
- mHandlerMap.put(iface, ifaceHandlers);
- }
- Set<Handler> ifaceWhatHandlers = ifaceHandlers.get(what);
- if (ifaceWhatHandlers == null) {
- ifaceWhatHandlers = new ArraySet<>();
- ifaceHandlers.put(what, ifaceWhatHandlers);
- }
- ifaceWhatHandlers.add(handler);
- }
- /**开始监听
- * Start Monitoring for wpa_supplicant events.
- *
- * @param iface Name of iface.
- * TODO: Add unit tests for these once we remove the legacy code.
- */
- public synchronized void startMonitoring(String iface, boolean isStaIface) {
- if (ensureConnectedLocked()) { // 从WifiNative 得到Supplicant 连接的状态
- setMonitoring(iface, true);
- broadcastSupplicantConnectionEvent(iface); // 发送连接事件
- } else {
- boolean originalMonitoring = isMonitoring(iface);
- setMonitoring(iface, true);
- broadcastSupplicantDisconnectionEvent(iface);
- setMonitoring(iface, originalMonitoring);
- Log.e(TAG, "startMonitoring(" + iface + ") failed!");
- }
- }
- /**断开监听
- * Stop Monitoring for wpa_supplicant events.
- *
- * @param iface Name of iface.
- * TODO: Add unit tests for these once we remove the legacy code.
- */
- public synchronized void stopMonitoring(String iface) {
- if (mVerboseLoggingEnabled) Log.d(TAG, "stopMonitoring(" + iface + ")");
- setMonitoring(iface, true);
- broadcastSupplicantDisconnectionEvent(iface);
- setMonitoring(iface, false);
- }
- /* Connection to supplicant established */
- private static final int BASE = Protocol.BASE_WIFI_MONITOR;//0x00024000
- public static final int SUP_CONNECTION_EVENT = BASE + 1
- public void broadcastSupplicantConnectionEvent(String iface) { // 发送给handler已经开始监听的Message
- sendMessage(iface, SUP_CONNECTION_EVENT);
- }
- private void sendMessage(String iface, int what) {
- sendMessage(iface, Message.obtain(null, what)); // 封装为Message
- }
- private void sendMessage(String iface, Message message) {
- // 通过iface拿到 那些对该接口注册了处理函数的handler集合
- SparseArray<Set<Handler>> ifaceHandlers = mHandlerMap.get(iface);
- if (iface != null && ifaceHandlers != null) {
- if (isMonitoring(iface)) {
- // 通过message.what拿到 那些对该接口注册了处理函数的handler集合 中找对message有处理函数的 handler集合
- Set<Handler> ifaceWhatHandlers = ifaceHandlers.get(message.what);
- if (ifaceWhatHandlers != null) {
- for (Handler handler : ifaceWhatHandlers) {
- if (handler != null) {
- // 往这些handler 中发送对应的这个消息
- sendMessage(handler, Message.obtain(message));
- }
- }
- }
- } else {
- if (mVerboseLoggingEnabled) {
- Log.d(TAG, "Dropping event because (" + iface + ") is stopped");
- }
- }
- } else {
- if (mVerboseLoggingEnabled) {
- Log.d(TAG, "Sending to all monitors because there's no matching iface");
- }
- for (Map.Entry<String, SparseArray<Set<Handler>>> entry : mHandlerMap.entrySet()) {
- if (isMonitoring(entry.getKey())) {
- Set<Handler> ifaceWhatHandlers = entry.getValue().get(message.what);
- for (Handler handler : ifaceWhatHandlers) {
- if (handler != null) {
- sendMessage(handler, Message.obtain(message));
- }
- }
- }
- }
- }
- message.recycle();
- }
- private void sendMessage(Handler handler, Message message) {
- message.setTarget(handler);
- message.sendToTarget(); // 发送给对应的handler 去处理 这个消息
- }
- WifiMonitor提供如下函数供 类 /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WificondControl.java 调用
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java调用
- 最终会调用到 sendMessage(String iface, Message message) sendMessage(Handler handler, Message message)
- broadcastAnqpDoneEvent(String iface, AnqpEvent anqpEvent) {
- sendMessage(iface, ANQP_DONE_EVENT, anqpEvent);
- }
- public void broadcastAssociatedBssidEvent(String iface, String bssid) {
- sendMessage(iface, WifiStateMachine.CMD_ASSOCIATED_BSSID, 0, 0, bssid);
- }
- public void broadcastAssociationRejectionEvent(String iface, int status, boolean timedOut,String bssid) {
- sendMessage(iface, ASSOCIATION_REJECTION_EVENT, timedOut ? 1 : 0, status, bssid);
- }
- public void broadcastAuthenticationFailureEvent(String iface, int reason) {
- sendMessage(iface, AUTHENTICATION_FAILURE_EVENT, 0, reason);
- }
- public void broadcastIconDoneEvent(String iface, IconEvent iconEvent) {
- sendMessage(iface, RX_HS20_ANQP_ICON_EVENT, iconEvent);
- }
- public void broadcastNetworkConnectionEvent(String iface, int networkId, String bssid) {
- sendMessage(iface, NETWORK_CONNECTION_EVENT, networkId, 0, bssid);
- }
- public void broadcastNetworkDisconnectionEvent(String iface, int local, int reason,String bssid) {
- sendMessage(iface, NETWORK_DISCONNECTION_EVENT, local, reason, bssid);
- }
- public void broadcastNetworkGsmAuthRequestEvent(String iface, int networkId, String ssid,String[] data) {
- sendMessage(iface, SUP_REQUEST_SIM_AUTH,new SimAuthRequestData(networkId, WifiEnterpriseConfig.Eap.SIM, ssid, data));
- }
- public void broadcastNetworkIdentityRequestEvent(String iface, int networkId, String ssid) {
- sendMessage(iface, SUP_REQUEST_IDENTITY, 0, networkId, ssid);
- }
- public void broadcastNetworkUmtsAuthRequestEvent(String iface, int networkId, String ssid,String[] data) {
- sendMessage(iface, SUP_REQUEST_SIM_AUTH,
- new SimAuthRequestData(networkId, WifiEnterpriseConfig.Eap.AKA, ssid, data));
- }
- public void broadcastPnoScanResultEvent(String iface) {
- sendMessage(iface, PNO_SCAN_RESULTS_EVENT);
- }
- public void broadcastScanFailedEvent(String iface) {
- sendMessage(iface, SCAN_FAILED_EVENT);
- }
- public void broadcastScanResultEvent(String iface) { // 【扫描结果】
- sendMessage(iface, SCAN_RESULTS_EVENT);
- }
- public void broadcastSupplicantConnectionEvent(String iface) {
- sendMessage(iface, SUP_CONNECTION_EVENT);
- }
- public void broadcastSupplicantDisconnectionEvent(String iface) {
- sendMessage(iface, SUP_DISCONNECTION_EVENT);
- }
- public void broadcastSupplicantStateChangeEvent(String iface, int networkId, WifiSsid wifiSsid,
- String bssid,SupplicantState newSupplicantState) {
- sendMessage(iface, SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
- new StateChangeResult(networkId, wifiSsid, bssid, newSupplicantState));
- }
- public void broadcastTargetBssidEvent(String iface, String bssid) {
- sendMessage(iface, WifiStateMachine.CMD_TARGET_BSSID, 0, 0, bssid);
- }
- public void broadcastWnmEvent(String iface, WnmData wnmData) {
- sendMessage(iface, HS20_REMEDIATION_EVENT, wnmData);
- }
- public void broadcastWpsFailEvent(String iface, int cfgError, int vendorErrorCode) {
- int reason = 0;
- switch(vendorErrorCode) {
- case REASON_TKIP_ONLY_PROHIBITED:
- sendMessage(iface, WPS_FAIL_EVENT, WifiManager.WPS_TKIP_ONLY_PROHIBITED);
- return;
- case REASON_WEP_PROHIBITED:
- sendMessage(iface, WPS_FAIL_EVENT, WifiManager.WPS_WEP_PROHIBITED);
- return;
- default:
- reason = vendorErrorCode;
- break;
- }
- switch(cfgError) {
- case CONFIG_AUTH_FAILURE:
- sendMessage(iface, WPS_FAIL_EVENT, WifiManager.WPS_AUTH_FAILURE);
- return;
- case CONFIG_MULTIPLE_PBC_DETECTED:
- sendMessage(iface, WPS_FAIL_EVENT, WifiManager.WPS_OVERLAP_ERROR);
- return;
- default:
- if (reason == 0) {
- reason = cfgError;
- }
- break;
- }
- //For all other errors, return a generic internal error
- sendMessage(iface, WPS_FAIL_EVENT, WifiManager.ERROR, reason);
- }
- public void broadcastWpsOverlapEvent(String iface) {
- sendMessage(iface, WPS_OVERLAP_EVENT);
- }
- public void broadcastWpsSuccessEvent(String iface) {
- sendMessage(iface, WPS_SUCCESS_EVENT);
- }
- public void broadcastWpsTimeoutEvent(String iface) {
- sendMessage(iface, WPS_TIMEOUT_EVENT);
- }
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WificondControl.java 调用
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java调用
- broadcastAnqpDoneEvent WificondControl.java 调用
- broadcastAssociatedBssidEvent SupplicantStaIfaceHal.java调用
- broadcastAssociationRejectionEvent SupplicantStaIfaceHal.java调用
- broadcastAuthenticationFailureEvent SupplicantStaIfaceHal.java调用
- broadcastIconDoneEvent SupplicantStaIfaceHal.java调用
- broadcastNetworkConnectionEvent SupplicantStaIfaceHal.java调用
- broadcastNetworkDisconnectionEvent SupplicantStaIfaceHal.java调用
- broadcastNetworkGsmAuthRequestEvent SupplicantStaIfaceHal.java调用
- broadcastNetworkIdentityRequestEvent SupplicantStaIfaceHal.java调用
- broadcastNetworkUmtsAuthRequestEvent SupplicantStaIfaceHal.java调用
- broadcastPnoScanResultEvent SupplicantStaIfaceHal.java调用
- broadcastScanFailedEvent SupplicantStaIfaceHal.java调用
- broadcastScanResultEvent WificondControl.java 调用
- broadcastSupplicantConnectionEvent
- broadcastSupplicantDisconnectionEvent
- broadcastSupplicantStateChangeEvent
- broadcastTargetBssidEvent
- broadcastWnmEvent
- broadcastWpsFailEvent
- broadcastWpsOverlapEvent
- broadcastWpsSuccessEvent
- broadcastWpsTimeoutEvent
- ISupplicantStaIfaceCallback.Stub 和文件 ISupplicantStaIfaceCallback.hal 关系怎样?
- /frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
- private class SupplicantStaIfaceHalCallback extends ISupplicantStaIfaceCallback.Stub {
- 定义了下列函数,下列函数应该是一些回调函数 被谁回调呢?
- onAnqpQueryDone ()
- onAssociationRejected ()
- public void onAuthenticationTimeout( byte [/* 6 */] bssid)
- onBssidChanged ()
- onDisconnected ()
- onEapFailure ()
- onExtRadioWorkStart ()
- onExtRadioWorkTimeout ()
- onHs20DeauthImminentNotice ()
- onHs20IconQueryDone ()
- onHs20SubscriptionRemediation ()
- onNetworkAdded ()
- onNetworkRemoved ()
- onStateChanged ()
- onWpsEventFail ()
- onWpsEventPbcOverlap ()
- onWpsEventSuccess ()
- }
- /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/hidl_manager.cpp
- void HidlManager::notifyAuthTimeout(struct wpa_supplicant *wpa_s)
- {
- if (!wpa_s)
- return;
- const std::string ifname(wpa_s->ifname);
- if (sta_iface_object_map_.find(ifname) == sta_iface_object_map_.end())
- return;
- const u8 *bssid = wpa_s->bssid;
- if (is_zero_ether_addr(bssid)) {
- bssid = wpa_s->pending_bssid;
- }
- callWithEachStaIfaceCallback(
- wpa_s->ifname,
- std::bind(
- &ISupplicantStaIfaceCallback::onAuthenticationTimeout, // 难道是在这里被回调?? Fuck Understand!!
- std::placeholders::_1, bssid));
- }
- callWithEachStaIfaceCallback(
- wpa_s->ifname, std::bind(
- &ISupplicantStaIfaceCallback::onAnqpQueryDone,
- std::placeholders::_1, bssid, hidl_anqp_data,
- hidl_hs20_anqp_data));
- void HidlManager::callWithEachStaIfaceCallback(
- const std::string &ifname,
- const std::function<Return<void>(android::sp<ISupplicantStaIfaceCallback>)> &method)
- {
- callWithEachIfaceCallback(ifname, method, sta_iface_callbacks_map_);
- }
- template <class CallbackType> // 把CallbackType 当做一个类 这个类是方法&method的执行类
- void callWithEachIfaceCallback(
- const std::string &ifname,
- const std::function<android::hardware::Return<void>(android::sp<CallbackType>)> &method,
- const std::map<const std::string, std::vector<android::sp<CallbackType>>> &callbacks_map)
- {
- if (ifname.empty())
- return;
- auto iface_callback_map_iter = callbacks_map.find(ifname);
- if (iface_callback_map_iter == callbacks_map.end())
- return;
- const auto &iface_callback_list = iface_callback_map_iter->second;
- for (const auto &callback : iface_callback_list) {
- if (!method(callback).isOk()) {
- wpa_printf(MSG_ERROR, "Failed to invoke HIDL iface callback");
- }
- }
- }
- sta_iface_callbacks_map_[wpa_s->ifname] =std::vector<android::sp<ISupplicantStaIfaceCallback>>();
- (removeAllIfaceCallbackHidlObjectsFromMap(wpa_s->ifname, sta_iface_callbacks_map_))
- addIfaceCallbackHidlObjectToMap(ifname, callback, on_hidl_died_fctor, sta_iface_callbacks_map_);
- template <class CallbackType>
- int addIfaceCallbackHidlObjectToMap(
- const std::string &ifname,
- const android::sp<CallbackType> &callback,
- const std::function<void(const android::sp<CallbackType> &)> &on_hidl_died_fctor,
- std::map<const std::string, std::vector<android::sp<CallbackType>>> &callbacks_map)
- {
- if (ifname.empty())
- return 1;
- auto iface_callback_map_iter = callbacks_map.find(ifname);
- if (iface_callback_map_iter == callbacks_map.end())
- return 1;
- auto &iface_callback_list = iface_callback_map_iter->second;
- // Register for death notification before we add it to our list.
- return registerForDeathAndAddCallbackHidlObjectToList<CallbackType>(
- callback, on_hidl_died_fctor, iface_callback_list);
- }
- template <class CallbackType>
- int registerForDeathAndAddCallbackHidlObjectToList(
- const android::sp<CallbackType> &callback,
- const std::function<void(const android::sp<CallbackType> &)>
- &on_hidl_died_fctor,
- std::vector<android::sp<CallbackType>> &callback_list)
- {
- #if 0 // TODO(b/31632518): HIDL object death notifications.
- auto death_notifier = new CallbackObjectDeathNotifier<CallbackType>(
- callback, on_hidl_died_fctor);
- // Use the |callback.get()| as cookie so that we don't need to
- // store a reference to this |CallbackObjectDeathNotifier| instance
- // to use in |unlinkToDeath| later.
- // NOTE: This may cause an immediate callback if the object is already
- // dead, so add it to the list before we register for callback!
- if (android::hardware::IInterface::asBinder(callback)->linkToDeath(
- death_notifier, callback.get()) != android::OK) {
- wpa_printf(
- MSG_ERROR,
- "Error registering for death notification for "
- "supplicant callback object");
- callback_list.erase(
- std::remove(
- callback_list.begin(), callback_list.end(), callback),
- callback_list.end());
- return 1;
- }
- #endif // TODO(b/31632518): HIDL object death notifications.
- callback_list.push_back(callback); // 把当前的类 CallbackType 放到 iface_callback_list
- return 0;
- }
- template <class CallbackType>
- int removeAllIfaceCallbackHidlObjectsFromMap(
- const std::string &ifname,
- std::map<const std::string, std::vector<android::sp<CallbackType>>> &callbacks_map)
- {
- auto iface_callback_map_iter = callbacks_map.find(ifname);
- if (iface_callback_map_iter == callbacks_map.end())
- return 1;
- #if 0 // TODO(b/31632518): HIDL object death notifications.
- const auto &iface_callback_list = iface_callback_map_iter->second;
- for (const auto &callback : iface_callback_list) {
- if (android::hardware::IInterface::asBinder(callback)
- ->unlinkToDeath(nullptr, callback.get()) !=
- android::OK) {
- wpa_printf(
- MSG_ERROR,
- "Error deregistering for death notification for "
- "iface callback object");
- }
- }
- #endif // TODO(b/31632518): HIDL object death notifications.
- callbacks_map.erase(iface_callback_map_iter);
- return 0;
- }
- ===============================================================
- /**
- * Register an interface to hidl manager.
- *
- * @param wpa_s |wpa_supplicant| struct corresponding to the interface.
- *
- * @return 0 on success, 1 on failure.
- */
- int HidlManager::registerInterface(struct wpa_supplicant *wpa_s)
- {
- sta_iface_callbacks_map_[wpa_s->ifname] =std::vector<android::sp<ISupplicantStaIfaceCallback>>();
- // Invoke the |onInterfaceCreated| method on all registered callbacks.
- callWithEachSupplicantCallback(std::bind(
- &ISupplicantCallback::onInterfaceCreated, std::placeholders::_1,
- wpa_s->ifname));
- }
- // 注册一个 接口 在 hidl manager? 难道就是创建一个
- //std::vector<android::sp<ISupplicantStaIfaceCallback>>() 并把它放到map中?
- /**
- * Helper function to invoke the provided callback method on all the
- * registered |ISupplicantCallback| callback hidl objects.
- *
- * @param method Pointer to the required hidl method from
- * |ISupplicantCallback|.
- */
- void HidlManager::callWithEachSupplicantCallback(
- const std::function<Return<void>(android::sp<ISupplicantCallback>)> &method)
- {
- for (const auto &callback : supplicant_callbacks_) {
- // supplicant_callbacks_ 就是一系列 定义了函数的&ISupplicantCallback::onInterfaceCreated的类
- //执行这些类的 onInterfaceCreated方法
- if (!method(callback).isOk()) {
- wpa_printf(MSG_ERROR, "Failed to invoke HIDL callback");
- }
- }
- }
- // http://blog.csdn.net/eclipser1987/article/details/24406203 C++ 新特性
- // http://coliru.stacked-crooked.com/ C++ 在线编辑
- // std::bind函数绑定 std::placeholders::_1, std::placeholders::_2 占位符 FUCK
https://blog.csdn.net/u010842019/article/details/78820831