安卓8.0 WIFI差异分析

[java]  view plain  copy
  1. ========================================================================  
  2. /packages/apps/Settings/src/com/android/settings/wifi/WifiMasterSwitchPreferenceController.java  
  3. mWifiEnabler = new WifiEnabler  
  4. (mContext, new MasterSwitchController(mWifiPreference),mMetricsFeatureProvider);  
  5.   
  6.   
  7.   
  8.   
  9. /packages/apps/Settings/src/com/android/settings/wifi/WifiSettings.java  
  10. new WifiEnabler(activity, new SwitchBarController(activity.getSwitchBar()),mMetricsFeatureProvider);  
  11. ========================================================================  
  12. /packages/apps/Settings/src/com/android/settings/widget/MasterSwitchController.java  
  13.   
  14.   
  15. public class MasterSwitchController extends SwitchWidgetController implements  
  16.  Preference.OnPreferenceChangeListener {  // 【Preference对应的数据(bar开关)变化会引起 onPreferenceChange】  
  17.     private final MasterSwitchPreference mPreference;  
  18.   
  19.   
  20.     @Override  
  21.     public boolean onPreferenceChange(Preference preference, Object newValue) {  
  22.         if (mListener != null) {  
  23.        return mListener.onSwitchToggled((Boolean) newValue);// 【接口回调  通知接口实现类WifiEnabler.java】  
  24.         }  
  25.         return false;  
  26.     }  
  27.   
  28.   
  29.       
  30.       protected OnSwitchChangeListener mListener;  
  31.         
  32.       public void setListener(OnSwitchChangeListener listener) {  
  33.       mListener = listener;  
  34.    }  
  35.  }  MasterSwitchController ↑  
  36.   
  37.   
  38.   
  39.   
  40. WifiEnabler(Context context, SwitchWidgetController switchWidget,  
  41.      MetricsFeatureProvider metricsFeatureProvider,ConnectivityManagerWrapper connectivityManagerWrapper) {  
  42.     mSwitchWidget = switchWidget;  
  43.     mSwitchWidget.setListener(this);   
  44.     //【在 WifiEnabler 构造方法里面设置了SwitchWidgetController监.mListener为自己 】  
  45.       
  46.           
  47. ========================================================================  
  48. /packages/apps/Settings/src/com/android/settings/wifi/WifiEnabler.java  
  49.   
  50.   
  51. public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListener  { // 【实现监听接口】  
  52.   
  53.   
  54.     private final SwitchWidgetController mSwitchWidget;  【BAR控件】  
  55.     private final WifiManager mWifiManager;  
  56.       
  57.     @Override  
  58.     public boolean onSwitchToggled(boolean isChecked) {  
  59.         //Do nothing if called as a result of a state machine event  
  60.         if (mStateMachineEvent) {  
  61.             return true;  
  62.         }  
  63.         // Show toast message if Wi-Fi is not allowed in airplane mode  
  64.         if (isChecked && !WirelessUtils.isRadioAllowed(mContext, Settings.Global.RADIO_WIFI)) {  
  65.             Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();  
  66.             // Reset switch to off. No infinite check/listenenr loop.  
  67.             mSwitchWidget.setChecked(false);  
  68.             return false;  
  69.         }  
  70.   
  71.   
  72.         // Disable tethering if enabling Wifi  
  73.         if (mayDisableTethering(isChecked)) {  
  74.             mConnectivityManager.stopTethering(ConnectivityManager.TETHERING_WIFI);  
  75.         }  
  76.         if (isChecked) {  
  77.             mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_WIFI_ON);  
  78.         } else {  
  79.             // Log if user was connected at the time of switching off.  
  80.             mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_WIFI_OFF,  
  81.                     mConnected.get());  
  82.         }  
  83.         if (!mWifiManager.setWifiEnabled(isChecked)) {  
  84.             // Error  
  85.             mSwitchWidget.setEnabled(true);  
  86.             Toast.makeText(mContext, R.string.wifi_error, Toast.LENGTH_SHORT).show();  
  87.         }  
  88.         return true;  
  89.     }  
  90.       
  91.       
  92. 论述:   
  93. 1.程序通过控件 MasterSwitchController 监听了WIFI开关数据Preference, 当这个Preference的值在on/off切换的过程中  
  94.   会触发,监听函数onPreferenceChange 。  
  95. 2.在MasterSwitchController中有OnSwitchChangeListener监听器接口,实现该接口的是WifiEnabler对象,他们之间的关系  
  96.   是通过 WifiEnabler 的构造函数中的 mSwitchWidget.setListener(this); 方法设置关联关系  
  97. 3.当switch开关切换会触发WifiEnabler的 onSwitchToggled 继而继续往下WifiManager的调用  
  98.   
  99.   
  100.   
  101.   
  102.   
  103.   
  104.   
  105.   
  106.   
  107.   
  108.   
  109.   
  110. /frameworks/base/wifi/java/android/net/wifi/WifiManager.java  
  111. mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);  
  112. mWifiManager.setWifiEnabled(isChecked)  
  113.   
  114.   
  115.   
  116.   
  117. "new WifiManager"  
  118. public class WifiManager {  
  119.   
  120.   
  121. IWifiManager mService;  // 来源于 WifiManager 构造函数,是提供给Client进程调用Service进程方法的桩  
  122.   
  123.   
  124.     public boolean setWifiEnabled(boolean enabled) {  
  125.         try {  
  126.          // 调用IWifiManager桩 的 setWifiEnabled 方法   
  127.             return mService.setWifiEnabled(mContext.getOpPackageName(), enabled);  
  128.         } catch (RemoteException e) {  
  129.             throw e.rethrowFromSystemServer();  
  130.         }  
  131.     }  
  132.   
  133.   
  134. }  
  135.   
  136.   
  137.   
  138.   
  139. =========================================================================  
  140. /frameworks/base/core/java/android/app/SystemServiceRegistry.java  
  141. registerService(Context.WIFI_SERVICE, WifiManager.class,new CachedServiceFetcher<WifiManager>() {  
  142.     @Override  
  143.     public WifiManager createService(ContextImpl ctx) throws ServiceNotFoundException {  
  144.         IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SERVICE 【"wifi"】);  
  145.         IWifiManager service = IWifiManager.Stub.asInterface(b);  
  146.         return new WifiManager(ctx.getOuterContext(), service,ConnectivityThread.getInstanceLooper());  
  147.     }}); //【把 WifiManager注册到系统服务 服务名为 wifi,其中IWifiManager是提供给Client进程调用的桩 】  
  148.         【通过这些桩 最终通过Binder机制调用到Service进程对应的方法中】  
  149.   
  150.   
  151. =========================================================================  
  152.   
  153.   
  154.   
  155.   
  156.   
  157.   
  158. /frameworks/base/wifi/java/android/net/wifi/IWifiManager.aidl    AIDL里面就是所定义的桩  
  159. interface IWifiManager  
  160. {  
  161.     void disconnect();  
  162.     void reconnect();  
  163.     void reassociate();  
  164.     WifiInfo getConnectionInfo();  
  165.     boolean setWifiEnabled(String packageName, boolean enable);  
  166.     ......  
  167. }  
  168.   
  169.   
  170. // 【实现桩的Service  运行于系统进程中 adb shell services list 中】  
  171. public class WifiServiceImpl extends IWifiManager.Stub {   
  172.   
  173.   
  174.   
  175.   
  176.     @Override  
  177.     public synchronized boolean setWifiEnabled(String packageName, boolean enable)  
  178.             throws RemoteException {  
  179.         enforceChangePermission();  
  180.         Slog.d(TAG, "setWifiEnabled: " + enable + " pid=" + Binder.getCallingPid()  
  181.                     + ", uid=" + Binder.getCallingUid() + ", package=" + packageName);  
  182.         mLog.trace("setWifiEnabled package=% uid=% enable=%").c(packageName)  
  183.                 .c(Binder.getCallingUid()).c(enable).flush();  
  184.   
  185.   
  186.         // If SoftAp is enabled, only Settings is allowed to toggle wifi  
  187.         boolean apEnabled =  
  188.                 mWifiStateMachine.syncGetWifiApState() != WifiManager.WIFI_AP_STATE_DISABLED;  
  189.         boolean isFromSettings = checkNetworkSettingsPermission();  
  190.         if (apEnabled && !isFromSettings) {  
  191.             mLog.trace("setWifiEnabled SoftAp not disabled: only Settings can enable wifi").flush();  
  192.             return false;  
  193.         }  
  194.   
  195.   
  196.         /* 
  197.         * Caller might not have WRITE_SECURE_SETTINGS, 
  198.         * only CHANGE_WIFI_STATE is enforced 
  199.         */  
  200.         long ident = Binder.clearCallingIdentity();  
  201.         try {  
  202.             if (! mSettingsStore.handleWifiToggled(enable)) {  
  203.                 // Nothing to do if wifi cannot be toggled  
  204.                 return true;  
  205.             }  
  206.         } finally {  
  207.             Binder.restoreCallingIdentity(ident);  
  208.         }  
  209.   
  210.   
  211.   
  212.   
  213.         if (mPermissionReviewRequired) {  
  214.             final int wiFiEnabledState = getWifiEnabledState();  
  215.             if (enable) {  
  216.                 if (wiFiEnabledState == WifiManager.WIFI_STATE_DISABLING  
  217.                         || wiFiEnabledState == WifiManager.WIFI_STATE_DISABLED) {  
  218.                     if (startConsentUi(packageName, Binder.getCallingUid(),  
  219.                             WifiManager.ACTION_REQUEST_ENABLE)) {  
  220.                         return true;  
  221.                     }  
  222.                 }  
  223.             } else if (wiFiEnabledState == WifiManager.WIFI_STATE_ENABLING  
  224.                     || wiFiEnabledState == WifiManager.WIFI_STATE_ENABLED) {  
  225.                 if (startConsentUi(packageName, Binder.getCallingUid(),  
  226.                         WifiManager.ACTION_REQUEST_DISABLE)) {  
  227.                     return true;  
  228.                 }  
  229.             }  
  230.         }  
  231.         // static final int CMD_WIFI_TOGGLED = BASE + 8; sendMessage 为mWifiController父类的方法  
  232.         mWifiController.sendMessage(CMD_WIFI_TOGGLED); // 【发送消息 BASE + 8】  
  233.         return true;  
  234.     }  
  235.       
  236. }  
  237.   
  238.   
  239. =========================================================================  
  240.   
  241.   
  242. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiController.java  
  243.   
  244.   
  245. public class WifiController extends StateMachine {  
  246. @override sendMessage(int what); //继承父类的 sendMessage  
  247. }  
  248.   
  249.   
  250. public class StateMachine {  
  251.   
  252.   
  253.  private static class SmHandler extends Handler {}  // SmHandler 是StateMachine 内部类  
  254.    
  255.     public void sendMessage(int what) {  
  256.         // mSmHandler can be null if the state machine has quit.  
  257.         SmHandler smh = mSmHandler;  
  258.         if (smh == nullreturn;  
  259.   
  260.   
  261.         smh.sendMessage(obtainMessage(what));  //  把CMD_WIFI_TOGGLED 封装为Message发送出去  
  262.     }  
  263.       
  264.     private void initStateMachine(String name, Looper looper) {  
  265.         mName = name;  
  266.         mSmHandler = new SmHandler(looper, this); // 创建 SmHandler  
  267.     }  
  268.       
  269.       
  270.        @Override  
  271.         public final void handleMessage(Message msg) {  
  272.             if (!mHasQuit) {  
  273.                 if (mSm != null && msg.what != SM_INIT_CMD && msg.what != SM_QUIT_CMD) {  
  274.                     mSm.onPreHandleMessage(msg);  
  275.                 }  
  276.   
  277.   
  278.                 if (mDbg) mSm.log("handleMessage: E msg.what=" + msg.what);  
  279.   
  280.   
  281.                 /** Save the current message */  
  282.                 mMsg = msg;  
  283.   
  284.   
  285.                 /** State that processed the message */  
  286.                 State msgProcessedState = null;  
  287.                 if (mIsConstructionCompleted) {  
  288.                     /** Normal path */  
  289.                     msgProcessedState = processMsg(msg);  //【处理消息】  
  290.                 } else if (!mIsConstructionCompleted && (mMsg.what == SM_INIT_CMD)  
  291.                         && (mMsg.obj == mSmHandlerObj)) {  
  292.                     /** Initial one time path. */  
  293.                     mIsConstructionCompleted = true;  
  294.                     invokeEnterMethods(0);  
  295.                 } else {  
  296.                     throw new RuntimeException("StateMachine.handleMessage: "  
  297.                             + "The start method not called, received msg: " + msg);  
  298.                 }  
  299.                 performTransitions(msgProcessedState, msg); // 【处理状态的转换 执行enter方法】  
  300.   
  301.   
  302.                 // We need to check if mSm == null here as we could be quitting.  
  303.                 if (mDbg && mSm != null) mSm.log("handleMessage: X");  
  304.   
  305.   
  306.                 if (mSm != null && msg.what != SM_INIT_CMD && msg.what != SM_QUIT_CMD) {  
  307.                     mSm.onPostHandleMessage(msg); // 【传递消息】  
  308.                 }  
  309.             }  
  310.         }  
  311.   
  312.   
  313. }     
  314.   
  315.   
  316.   
  317.   
  318.   
  319.   
  320.         private class StateInfo {  // 结点  构成状态树的结点  
  321.             /** The state */  
  322.             State state;  
  323.   
  324.   
  325.             /** The parent of this state, null if there is no parent */  
  326.             StateInfo parentStateInfo;  
  327.   
  328.   
  329.             /** True when the state has been entered and on the stack */  
  330.             boolean active;  
  331.   
  332.   
  333.             /** 
  334.              * Convert StateInfo to string 
  335.              */  
  336.             @Override  
  337.             public String toString() {  
  338.                 return "state=" + state.getName() + ",active=" + active + ",parent="  
  339.                         + ((parentStateInfo == null) ? "null" : parentStateInfo.state.getName());  
  340.             }  
  341.           
  342.           
  343.           
  344.         /** 
  345.          * Process the message. If the current state doesn't handle 
  346.          * it, call the states parent and so on. If it is never handled then 
  347.          * call the state machines unhandledMessage method. 
  348.          * @return the state that processed the message 
  349.          */  
  350.         private final State processMsg(Message msg) { //【当前状态不能处理消息参数时,调用父类状态进行处理】  
  351.         // private StateInfo mStateStack[]; mStateStack = new StateInfo[maxDepth];  存储当前状态信息的栈       
  352.         // private int mStateStackTopIndex = -1;  栈顶索引  
  353.           
  354.             StateInfo curStateInfo = mStateStack[mStateStackTopIndex];  
  355.             if (mDbg) {  
  356.                 mSm.log("processMsg: " + curStateInfo.state.getName());  
  357.             }  
  358.   
  359.   
  360.             if (isQuit(msg)) {  
  361.                 transitionTo(mQuittingState);  
  362.             } else {  
  363.                 while (!curStateInfo.state.processMessage(msg)) {   
  364.                 // 完成栈的状态信息类遍历 对应的processMessage 方法  
  365.                     /** 
  366.                      * Not processed 
  367.                      */  
  368.                     curStateInfo = curStateInfo.parentStateInfo;  // 切换状态信息类  
  369.                     if (curStateInfo == null) { // 如果到底了 那么处理不了了  退出while循环  
  370.                         /** 
  371.                          * No parents left so it's not handled 
  372.                          */  
  373.                         mSm.unhandledMessage(msg);  
  374.                         break;  
  375.                     }  
  376.                     if (mDbg) {  
  377.                         mSm.log("processMsg: " + curStateInfo.state.getName());  
  378.                     }  
  379.                 }  
  380.             }  
  381.             return (curStateInfo != null) ? curStateInfo.state : null;  // 返回当前处理了这个事件的那个状态类  
  382.         }  
  383.           
  384.           
  385.           
  386.           
  387.           
  388.         class StaDisabledWithScanState extends State {  
  389.           
  390.                 @Override  
  391.         public boolean processMessage(Message msg) {  
  392.             switch (msg.what) {  
  393.                 case CMD_WIFI_TOGGLED:  
  394.                     if (mSettingsStore.isWifiToggleEnabled()) { // 如果保存的状态是打开  
  395.                         if (doDeferEnable(msg)) {  
  396.                             if (mHaveDeferredEnable) {  
  397.                                 // have 2 toggles now, inc serial number and ignore both  
  398.                                 mDeferredEnableSerialNumber++;  
  399.                             }  
  400.                             mHaveDeferredEnable = !mHaveDeferredEnable;  
  401.                             break;  
  402.                         }  
  403.                         if (mDeviceIdle == false) {  
  404.                             transitionTo(mDeviceActiveState); //切换状态   状态切换之后会执行enter操作  
  405.                         } else {  
  406.                             checkLocksAndTransitionWhenDeviceIdle();  
  407.                         }  
  408.                     }  
  409.       
  410.             }  
  411.             return HANDLED;  
  412.         }  
  413.           
  414.           
  415.   
  416.   
  417.         private final void transitionTo(IState destState) {  
  418.             if (mTransitionInProgress) {  
  419.                 Log.wtf(mSm.mName, "transitionTo called while transition already in progress to " +  
  420.                         mDestState + ", new target state=" + destState);  
  421.             }  
  422.             mDestState = (State) destState;  // 就是把目标变量mDestState  变为当前的状态,后续执行enter方法  
  423.             if (mDbg) mSm.log("transitionTo: destState=" + mDestState.getName());  
  424.         }  
  425.           
  426.           
  427.           
  428.           
  429.           
  430.         private void performTransitions(State msgProcessedState, Message msg ) {  
  431.             /**  执行原来状态的exit方法 执行当前状态的enter方法 
  432.              * If transitionTo has been called, exit and then enter 
  433.              * the appropriate states. We loop on this to allow 
  434.              * enter and exit methods to use transitionTo. 
  435.              */  
  436.             State orgState = mStateStack[mStateStackTopIndex].state; // 当前栈顶状态  
  437.             State destState = mDestState; // 切换到的目标状态  
  438.             if (destState != null) {  
  439.                 while (true) {  
  440.                     if (mDbg) mSm.log("handleMessage: new destination call exit/enter");  
  441.   
  442.   
  443.                     /** 
  444.                      * Determine the states to exit and enter and return the 
  445.                      * common ancestor state of the enter/exit states. Then 
  446.                      * invoke the exit methods then the enter methods. 
  447.                      */  
  448.                     // 依次遍历当前状态的父状态  直到null 这些就是 enter需要执行的状态  
  449.                     StateInfo commonStateInfo = setupTempStateStackWithStatesToEnter(destState);  
  450.                     // flag is cleared in invokeEnterMethods before entering the target state  
  451.                     mTransitionInProgress = true;  
  452.                     invokeExitMethods(commonStateInfo); // 调用 exit方法  
  453.                     int stateStackEnteringIndex = moveTempStateStackToStateStack(); 从状态栈第几个索引开始enter  
  454.                     invokeEnterMethods(stateStackEnteringIndex); // 调用 enter方法  
  455.   
  456.   
  457.                     /** 
  458.                      * Since we have transitioned to a new state we need to have 
  459.                      * any deferred messages moved to the front of the message queue 
  460.                      * so they will be processed before any other messages in the 
  461.                      * message queue. 
  462.                      */  
  463.                     moveDeferredMessageAtFrontOfQueue();  
  464.   
  465.   
  466.                     if (destState != mDestState) {  
  467.                         // A new mDestState so continue looping  
  468.                         destState = mDestState;  
  469.                     } else {  
  470.                         // No change in mDestState so we're done  
  471.                         break;  // enter  exit 完成  那么while循环 就结束了  
  472.                     }  
  473.                 }  
  474.                 mDestState = null;  
  475.             }  
  476.               
  477.             最终会调用到  class StaEnabledState extends State {} 的 enter 方法中  
  478.               
  479.     class StaEnabledState extends State {  
  480.         @Override  
  481.         public void enter() {  
  482.             mWifiStateMachine.setSupplicantRunning(true); //打开WIFI 开始分析 mWifiStateMachine  
  483.         }}  
  484.           
  485.     class ApStaDisabledState extends State {  
  486.   
  487.   
  488.         @Override  
  489.         public void enter() {  
  490.             mWifiStateMachine.setSupplicantRunning(false); //进入WIFI   
  491.             }}  
  492.               
  493. ========================================================================  
  494. WifiController.java  
  495. import com.android.internal.util.State;  
  496. class DefaultState extends State {  
  497. class ApStaDisabledState extends State {  
  498. class StaEnabledState extends State {  
  499. class StaDisabledWithScanState extends State {  
  500. class ApEnabledState extends State {  
  501. class EcmState extends State {  
  502. class DeviceActiveState extends State {  
  503. class DeviceInactiveState extends State {  
  504. class ScanOnlyLockHeldState extends State {  
  505. class FullLockHeldState extends State {  
  506. class FullHighPerfLockHeldState extends State {  
  507. class NoLockHeldState extends State {  
  508.   
  509.   
  510. WifiController.java 组成的状态树  
  511. 十二个状态组成的单子树  
  512.         addState(mDefaultState);  
  513.             addState(mApStaDisabledState, mDefaultState);  
  514.             addState(mStaEnabledState, mDefaultState);  
  515.                 addState(mDeviceActiveState, mStaEnabledState);  
  516.                 addState(mDeviceInactiveState, mStaEnabledState);  
  517.                     addState(mScanOnlyLockHeldState, mDeviceInactiveState);  
  518.                     addState(mFullLockHeldState, mDeviceInactiveState);  
  519.                     addState(mFullHighPerfLockHeldState, mDeviceInactiveState);  
  520.                     addState(mNoLockHeldState, mDeviceInactiveState);  
  521.             addState(mStaDisabledWithScanState, mDefaultState);  
  522.             addState(mApEnabledState, mDefaultState);  
  523.             addState(mEcmState, mDefaultState);  
  524.   
  525.   
  526. StateMachine.java  
  527. HaltingState extends State {  
  528. QuittingState extends State {  
  529.   
  530.   
  531.   
  532.   
  533. /frameworks/base/core/java/com/android/internal/util/State.java  
  534. public class State implements IState {  
  535.   
  536.   
  537.     protected State() {  
  538.     }  
  539.   
  540.   
  541.     public void enter() {  // 进入  
  542.     }  
  543.   
  544.   
  545.     public void exit() {  // 离开  
  546.     }  
  547.   
  548.   
  549.     public boolean processMessage(Message msg) {  // 处理消息  
  550.         return false;  
  551.     }  
  552. }  
  553.   
  554.   
  555.   
  556.   
  557. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiStateMachine.java 组成的状态树  
  558. addState(mDefaultState);  
  559.     addState(mInitialState, mDefaultState);  
  560.     addState(mSupplicantStartingState, mDefaultState);  
  561.     addState(mSupplicantStartedState, mDefaultState);  
  562.             addState(mScanModeState, mSupplicantStartedState);  
  563.             addState(mConnectModeState, mSupplicantStartedState);  
  564.                 addState(mL2ConnectedState, mConnectModeState);  
  565.                     addState(mObtainingIpState, mL2ConnectedState);  
  566.                     addState(mConnectedState, mL2ConnectedState);  
  567.                     addState(mRoamingState, mL2ConnectedState);  
  568.                 addState(mDisconnectingState, mConnectModeState);  
  569.                 addState(mDisconnectedState, mConnectModeState);  
  570.                 addState(mWpsRunningState, mConnectModeState);  
  571.         addState(mWaitForP2pDisableState, mSupplicantStartedState);  
  572.     addState(mSupplicantStoppingState, mDefaultState);  
  573.     addState(mSoftApState, mDefaultState);  
  574.   
  575.   
  576. ========================================================================  
  577.   
  578.   
  579.   
  580.   
  581. public class WifiController extends StateMachine { // 自己是状态机StateMachine  又包含一个状态机WifiStateMachine  
  582.   
  583.   
  584. private final WifiStateMachine mWifiStateMachine;  
  585.   
  586.   
  587.     class StaEnabledState extends State {  
  588.         @Override  
  589.         public void enter() {  
  590.             mWifiStateMachine.setSupplicantRunning(true); //打开WIFI 开始分析 mWifiStateMachine  
  591.         }}  
  592.   
  593.   
  594. }  
  595.   
  596.   
  597. frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiInjector.java  
  598. public class WifiInjector {  
  599.   
  600.   
  601. private final WifiNative mWifiNative;  
  602. private final WifiStateMachine mWifiStateMachine;  
  603. private final WifiController mWifiController;  
  604.   
  605.   
  606.         mWifiNative = new WifiNative(SystemProperties.get("wifi.interface""wlan0"),  
  607.                 mWifiVendorHal, mSupplicantStaIfaceHal, mWificondControl);  
  608.                   
  609.         mWifiStateMachine = new WifiStateMachine(mContext, mFrameworkFacade,  
  610.                 wifiStateMachineLooper, UserManager.get(mContext),  
  611.                 this, mBackupManagerProxy, mCountryCode, mWifiNative);  
  612.                   
  613.         mWifiController = new WifiController(mContext, mWifiStateMachine, mSettingsStore,  
  614.                 mLockManager, mWifiServiceHandlerThread.getLooper(), mFrameworkFacade);  
  615. }         
  616.   
  617.   
  618.   
  619.   
  620. WifiStateMachine.java  
  621.     public void setSupplicantRunning(boolean enable) {  
  622.         if (enable) {  
  623.             sendMessage(CMD_START_SUPPLICANT);  //开启SUPPLICANT命令  同样 继承父类StateMachine的 sendMessage  
  624.         } else {  
  625.             sendMessage(CMD_STOP_SUPPLICANT);  
  626.         }  
  627.     }  
  628.   
  629.   
  630.         public void sendMessage(int what) {  
  631.         // mSmHandler can be null if the state machine has quit.  
  632.         SmHandler smh = mSmHandler;  
  633.         if (smh == nullreturn;  
  634.   
  635.   
  636.         smh.sendMessage(obtainMessage(what【BASE + 11】));    
  637.     }  
  638. //  把CMD_START_SUPPLICANT 封装为Message发送出去执行到 StateMachine的handleMessage   
  639. //  然后processMessage   切换状态 enter exit         
  640.   
  641.   
  642.  @Override  
  643.         public final void handleMessage(Message msg) {  
  644.                     State msgProcessedState = null;  
  645.                     msgProcessedState = processMsg(msg);  //【处理消息】  
  646.                     performTransitions(msgProcessedState, msg); // 【处理状态的转换 执行enter方法】  
  647.                     mSm.onPostHandleMessage(msg); // 【传递消息】  
  648.     }  
  649.       
  650.       class InitialState extends State {  
  651.         
  652.         public boolean processMessage(Message message) {  
  653.             switch (message.what) {  
  654.                 case CMD_START_SUPPLICANT:  
  655.                 mClientInterface = mWifiNative.setupForClientMode();  
  656.                 mWifiNative.enableSupplicant();  
  657.                 setSupplicantLogLevel();  
  658.                 transitionTo(mSupplicantStartingState);   
  659.                 //切换到从InitialState切换到状态 SupplicantStartingState  
  660.                 }  
  661.         }  
  662.           
  663.   
  664.   
  665. WifiStateMachine.java  
  666.     /* The base for wifi message types */  
  667.     static final int BASE = Protocol.BASE_WIFI;  
  668.     static final int CMD_START_SUPPLICANT                               = BASE + 11;  
  669.     static final int CMD_STOP_SUPPLICANT                                = BASE + 12;  
  670.     static final int CMD_STATIC_IP_SUCCESS                              = BASE + 15;  
  671.     static final int CMD_STATIC_IP_FAILURE                              = BASE + 16;  
  672.     static final int CMD_DRIVER_START_TIMED_OUT                         = BASE + 19;  
  673.     static final int CMD_START_AP                                       = BASE + 21;  
  674.     static final int CMD_START_AP_FAILURE                               = BASE + 22;  
  675.     static final int CMD_STOP_AP                                        = BASE + 23;  
  676.     static final int CMD_AP_STOPPED                                     = BASE + 24;  
  677.     static final int CMD_BLUETOOTH_ADAPTER_STATE_CHANGE                 = BASE + 31;  
  678.       
  679.       
  680.       
  681. WifiController.java  
  682. private static final int BASE = Protocol.BASE_WIFI_CONTROLLER;  
  683.     static final int CMD_EMERGENCY_MODE_CHANGED        = BASE + 1;  
  684.     static final int CMD_SCREEN_ON                     = BASE + 2;  
  685.     static final int CMD_SCREEN_OFF                    = BASE + 3;  
  686.     static final int CMD_BATTERY_CHANGED               = BASE + 4;  
  687.     static final int CMD_DEVICE_IDLE                   = BASE + 5;  
  688.     static final int CMD_LOCKS_CHANGED                 = BASE + 6;  
  689.     static final int CMD_SCAN_ALWAYS_MODE_CHANGED      = BASE + 7;  
  690.     static final int CMD_WIFI_TOGGLED                  = BASE + 8;  
  691.     static final int CMD_AIRPLANE_TOGGLED              = BASE + 9;  
  692.     static final int CMD_SET_AP                        = BASE + 10;  
  693.     static final int CMD_DEFERRED_TOGGLE               = BASE + 11;  
  694.     static final int CMD_USER_PRESENT                  = BASE + 12;  
  695.     static final int CMD_AP_START_FAILURE              = BASE + 13;  
  696.     static final int CMD_EMERGENCY_CALL_STATE_CHANGED  = BASE + 14;  
  697.     static final int CMD_AP_STOPPED                    = BASE + 15;  
  698.     static final int CMD_STA_START_FAILURE             = BASE + 16;  
  699.     // Command used to trigger a wifi stack restart when in active mode  
  700.     static final int CMD_RESTART_WIFI                  = BASE + 17;  
  701.     // Internal command used to complete wifi stack restart  
  702.     private static final int CMD_RESTART_WIFI_CONTINUE = BASE + 18;  
  703.       
  704.       
  705.       
  706.       
  707.   
  708.   
  709. ========================================================================  
  710. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative.java  
  711.   
  712.   
  713.         public IClientInterface setupForClientMode() {  
  714.         if (!startHalIfNecessary(true)) {  
  715.             Log.e(mTAG, "Failed to start HAL for client mode");  
  716.             return null;  
  717.         }  
  718.         return mWificondControl.setupDriverForClientMode();  
  719.     }  
  720.       
  721.       
  722.       
  723.        /** 
  724.     * Setup driver for client mode via wificond. 
  725.     * @return An IClientInterface as wificond client interface binder handler. 
  726.     * Returns null on failure. 
  727.     */  
  728.     public IClientInterface setupDriverForClientMode() {  
  729.         Log.d(TAG, "Setting up driver for client mode");  
  730.         mWificond = mWifiInjector.makeWificond();  
  731.         if (mWificond == null) {  
  732.             Log.e(TAG, "Failed to get reference to wificond");  
  733.             return null;  
  734.         }  
  735.   
  736.   
  737.         IClientInterface clientInterface = null;  
  738.         try {  
  739.             clientInterface = mWificond.createClientInterface();  
  740.         } catch (RemoteException e1) {  
  741.             Log.e(TAG, "Failed to get IClientInterface due to remote exception");  
  742.             return null;  
  743.         }  
  744.   
  745.   
  746.         if (clientInterface == null) {  
  747.             Log.e(TAG, "Could not get IClientInterface instance from wificond");  
  748.             return null;  
  749.         }  
  750.         Binder.allowBlocking(clientInterface.asBinder());  
  751.   
  752.   
  753.         // Refresh Handlers  
  754.         mClientInterface = clientInterface;  
  755.         try {  
  756.             mClientInterfaceName = clientInterface.getInterfaceName();  
  757.             mWificondScanner = mClientInterface.getWifiScannerImpl();  
  758.             if (mWificondScanner == null) {  
  759.                 Log.e(TAG, "Failed to get WificondScannerImpl");  
  760.                 return null;  
  761.             }  
  762.             Binder.allowBlocking(mWificondScanner.asBinder());  
  763.             mScanEventHandler = new ScanEventHandler();  
  764.             mWificondScanner.subscribeScanEvents(mScanEventHandler);  
  765.             mPnoScanEventHandler = new PnoScanEventHandler();  
  766.             mWificondScanner.subscribePnoScanEvents(mPnoScanEventHandler);  
  767.         } catch (RemoteException e) {  
  768.             Log.e(TAG, "Failed to refresh wificond scanner due to remote exception");  
  769.         }  
  770.   
  771.   
  772.         return clientInterface;  
  773.     }  
  774.       
  775.       
  776.     --------------------------------------------------  
  777.     mSupplicantStaIfaceHal  这个是干啥!!!  
  778.     mWifiVendorHal  这个是干啥!!!  
  779.       
  780.     JNI operations  
  781.       
  782.       
  783.      /******************************************************** 
  784.      * JNI operations 
  785.      ********************************************************/  
  786.     /* Register native functions */  
  787.     static {  
  788.         /* Native functions are defined in libwifi-service.so */  
  789.         System.loadLibrary("wifi-service");  
  790.         registerNatives();  
  791.     }  
  792.   
  793.   
  794.     private static native int registerNatives();  
  795.     /* kernel logging support */  
  796.     private static native byte[] readKernelLogNative()  
  797.       
  798.       
  799.       
  800.     /frameworks/opt/net/wifi/service/jni/com_android_server_wifi_WifiNative.cpp  
  801.       
  802. /* 
  803.  * JNI registration. 
  804.  */  
  805. static JNINativeMethod gWifiMethods[] = {  
  806.     /* name, signature, funcPtr */  
  807.     {"readKernelLogNative""()[B", (void*)android_net_wifi_readKernelLog},  
  808. };  
  809.   
  810.   
  811. /* User to register native functions */  
  812. extern "C"  
  813. jint Java_com_android_server_wifi_WifiNative_registerNatives(JNIEnv* env, jclass clazz) {  
  814.     // initialization needed for unit test APK  
  815.     JniConstants::init(env);  
  816.   
  817.   
  818.     return jniRegisterNativeMethods(env,  
  819.             "com/android/server/wifi/WifiNative", gWifiMethods, NELEM(gWifiMethods));  
  820. }  
  821.   
  822.   
  823. }; // namespace android  
  824.   
  825.   
  826.   
  827.   
  828. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java  
  829.   
  830.   
  831.      private SupplicantStaNetworkHal addNetwork() {  
  832.         synchronized (mLock) {  
  833.             final String methodStr = "addNetwork";  
  834.             if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;  
  835.             Mutable<ISupplicantNetwork> newNetwork = new Mutable<>();  
  836.             try {  
  837.                 mISupplicantStaIface.addNetwork ((SupplicantStatus status,  
  838.                         ISupplicantNetwork network) -> {  
  839.                     if (checkStatusAndLogFailure(status, methodStr)) {  
  840.                         newNetwork.value = network;  
  841.                     } //什么语法  
  842.                 })   ;  
  843. checkSupplicantStaIfaceAndLogFailure(methodStr) ?  
  844.  checkStatusAndLogFailure?  
  845.    
  846.  final String methodStr = "addNetwork";  mISupplicantStaIface.addNetwork  
  847.  final String methodStr = "removeNetwork"; mISupplicantStaIface.removeNetwork  
  848.  final String methodStr = "getNetwork"; mISupplicantStaIface.getNetwork(  
  849.  final String methodStr = "registerCallback"; mISupplicantStaIface.registerCallback  
  850.  final String methodStr = "listNetworks";  mISupplicantStaIface.listNetworks((  
  851.  final String methodStr = "setWpsDeviceName";   mISupplicantStaIface.setWpsDeviceName(name)       
  852.  final String methodStr = "setWpsDeviceType"; mISupplicantStaIface.setWpsDeviceType(type);  
  853.  final String methodStr = "setWpsManufacturer";  mISupplicantStaIface.setWpsManufacturer(manufacturer)  
  854.  final String methodStr = "setWpsModelName"; mISupplicantStaIface.setWpsModelName(modelName);  
  855.  final String methodStr = "setWpsModelNumber"; mISupplicantStaIface.setWpsModelNumber(modelNumber);  
  856.  final String methodStr = "setWpsSerialNumber";  mISupplicantStaIface.setWpsSerialNumber(serialNumber);  
  857.  final String methodStr = "setWpsConfigMethods"; mISupplicantStaIface.setWpsConfigMethods(configMethods);  
  858.  final String methodStr = "reassociate";  mISupplicantStaIface.reassociate();  
  859.  final String methodStr = "reconnect";  mISupplicantStaIface.reconnect();   
  860.  final String methodStr = "disconnect"; mISupplicantStaIface.disconnect();  
  861.  final String methodStr = "setPowerSave"; mISupplicantStaIface.setPowerSave(enable);  
  862.  final String methodStr = "initiateTdlsDiscover"; mISupplicantStaIface.initiateTdlsDiscover(macAddress);  
  863.  final String methodStr = "initiateTdlsSetup"; mISupplicantStaIface.initiateTdlsSetup(macAddress)  
  864.  final String methodStr = "initiateTdlsTeardown"; mISupplicantStaIface.initiateTdlsTeardown(macAddress);  
  865.  final String methodStr = "initiateAnqpQuery";  mISupplicantStaIface.initiateAnqpQuery(macAddress,infoElements, subTypes);  
  866.  final String methodStr = "initiateHs20IconQuery"; mISupplicantStaIface.initiateHs20IconQuery(macAddress,fileName);  
  867.  final String methodStr = "getMacAddress"; mISupplicantStaIface.getMacAddress((SupplicantStatus status,byte[/* 6 */] macAddr)  
  868.  final String methodStr = "startRxFilter";  mISupplicantStaIface.startRxFilter();  
  869.  final String methodStr = "stopRxFilter"; mISupplicantStaIface.stopRxFilter();  
  870.  final String methodStr = "addRxFilter";  mISupplicantStaIface.addRxFilter(type);  
  871.  final String methodStr = "removeRxFilter"; mISupplicantStaIface.removeRxFilter(type);  
  872.  final String methodStr = "setBtCoexistenceMode";  mISupplicantStaIface.setBtCoexistenceMode(mode);  
  873.  final String methodStr = "setBtCoexistenceScanModeEnabled"; mISupplicantStaIface.setBtCoexistenceScanModeEnabled(enable);  
  874.  final String methodStr = "setSuspendModeEnabled"; mISupplicantStaIface.setSuspendModeEnabled(enable);  
  875.  final String methodStr = "setCountryCode";  mISupplicantStaIface.setCountryCode(code);  
  876.  final String methodStr = "startWpsRegistrar";  mISupplicantStaIface.startWpsRegistrar(bssid, pin);  
  877.  final String methodStr = "startWpsPbc";  mISupplicantStaIface.startWpsPbc(bssid);  
  878.  final String methodStr = "startWpsPinKeypad"; mISupplicantStaIface.startWpsPinKeypad(pin);  
  879.  final String methodStr = "startWpsPinDisplay";   mISupplicantStaIface.startWpsPinDisplay(  
  880.  final String methodStr = "cancelWps";  mISupplicantStaIface.cancelWps();  
  881.  final String methodStr = "setExternalSim";  mISupplicantStaIface.setExternalSim(useExternalSim);  
  882.  final String methodStr = "enableAutoReconnect";   mISupplicantStaIface.enableAutoReconnect(enable);  
  883.  final String methodStr = "setDebugParams";   mISupplicant.setDebugParams(level, showTimestamp, showKeys);  
  884.  final String methodStr = "setConcurrencyPriority";  mISupplicant.setConcurrencyPriority(type);  
  885.    
  886.  private ISupplicantStaIface mISupplicantStaIface;  
  887.  private ISupplicant mISupplicant;  
  888.    
  889.  private boolean initSupplicantStaIface() {  
  890.  /** List all supplicant Ifaces */  
  891. final ArrayList<ISupplicant.IfaceInfo> supplicantIfaces = new ArrayList<>();  
  892. try {  
  893.     mISupplicant.listInterfaces((SupplicantStatus status,  
  894.             ArrayList<ISupplicant.IfaceInfo> ifaces) -> {  
  895.         if (status.code != SupplicantStatusCode.SUCCESS) {  
  896.             Log.e(TAG, "Getting Supplicant Interfaces failed: " + status.code);  
  897.             return;  
  898.         }  
  899.         supplicantIfaces.addAll(ifaces);  
  900.     });  
  901. }   
  902. // HIDL   HAL Interface Define Lagurage  
  903. if (supplicantIfaces.size() == 0) {  
  904.     Log.e(TAG, "Got zero HIDL supplicant ifaces. Stopping supplicant HIDL startup.");  
  905.     return false;  
  906. }  
  907.   
  908.   
  909. Mutable<ISupplicantIface> supplicantIface = new Mutable<>();  
  910.     Mutable<String> ifaceName = new Mutable<>();  
  911.     for (ISupplicant.IfaceInfo ifaceInfo : supplicantIfaces) {  
  912.         if (ifaceInfo.type == IfaceType.STA) {  
  913.             try { // mISupplicant.getInterface 很重要他得到在Client端代理Service服务端Proxy的IBinder  
  914.                 mISupplicant.getInterface(ifaceInfo,  
  915.                         (SupplicantStatus status, ISupplicantIface【IBinder】 iface) -> {  
  916.                         if (status.code != SupplicantStatusCode.SUCCESS) {  
  917.                             Log.e(TAG, "Failed to get ISupplicantIface " + status.code);  
  918.                             return;  
  919.                         }  
  920.                         supplicantIface.value = iface【IBinder】;  
  921.                     });  
  922.             } catch (RemoteException e) {  
  923.                 Log.e(TAG, "ISupplicant.getInterface exception: " + e);  
  924.                 return false;  
  925.             }  
  926.             ifaceName.value = ifaceInfo.name;  
  927.             break;  
  928.         }  
  929.     }  
  930.     mISupplicantStaIface = getStaIfaceMockable(supplicantIface.value);  
  931.   
  932.   
  933.  }  
  934.    
  935.         private boolean initSupplicantService() {  
  936.         synchronized (mLock) {  
  937.             try {  
  938.                 mISupplicant = getSupplicantMockable();  
  939.                 }  
  940.             }  
  941.         }  
  942.   
  943.   
  944.     protected ISupplicantStaIface getStaIfaceMockable(ISupplicantIface iface) {  
  945.         return ISupplicantStaIface.asInterface(iface.asBinder());  
  946.     }  
  947.       
  948.     protected ISupplicant getSupplicantMockable() throws RemoteException {  
  949.         return ISupplicant.getService();  
  950.     }  
  951.       
  952. ========================================================  
  953. /hardware/interfaces/wifi/supplicant/1.0/ISupplicant.hal  
  954.   
  955.   
  956. package android.hardware.wifi.supplicant@1.0;  
  957.   
  958.   
  959. import ISupplicantCallback;  
  960. import ISupplicantIface;  
  961.   
  962.   
  963. interface ISupplicant {  
  964.   
  965.   
  966.   enum DebugLevel : uint32_t {  
  967.     EXCESSIVE = 0,  
  968.     MSGDUMP = 1,  
  969.     DEBUG = 2,  
  970.     INFO = 3,  
  971.     WARNING = 4,  
  972.     ERROR = 5  
  973.   };  
  974.   
  975.   
  976.   struct IfaceInfo {  
  977.     IfaceType type;  
  978.     string name;  
  979.   };  
  980.   getInterface(IfaceInfo ifaceInfo)  
  981.   generates (SupplicantStatus status, ISupplicantIface iface);  
  982.   listInterfaces() generates (SupplicantStatus status, vec<IfaceInfo> ifaces);  
  983.   registerCallback(ISupplicantCallback callback) generates (SupplicantStatus status);  
  984.   setDebugParams(DebugLevel level, bool showTimestamp, bool showKeys) generates (SupplicantStatus status);  
  985.   getDebugLevel() generates (DebugLevel level);  
  986.   isDebugShowTimestampEnabled() generates (bool enabled);  
  987.   isDebugShowKeysEnabled() generates (bool enabled);  
  988.   setConcurrencyPriority(IfaceType type) generates (SupplicantStatus status);  
  989. };  
  990.   
  991.   
  992.   
  993.   
  994. ========================================================  
  995. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaIface.hal  
  996.   
  997.   
  998. package android.hardware.wifi.supplicant@1.0;  
  999.   
  1000.   
  1001. import ISupplicantIface;  
  1002. import ISupplicantStaIfaceCallback;  
  1003.   
  1004.   
  1005. interface ISupplicantStaIface extends ISupplicantIface {  
  1006.   
  1007.   
  1008.   enum AnqpInfoId : uint16_t {  
  1009.     VENUE_NAME = 258,  
  1010.     ROAMING_CONSORTIUM = 261,  
  1011.     IP_ADDR_TYPE_AVAILABILITY = 262,  
  1012.     NAI_REALM = 263,  
  1013.     ANQP_3GPP_CELLULAR_NETWORK = 264,  
  1014.     DOMAIN_NAME = 268  
  1015.   };  
  1016.   
  1017.   
  1018.   enum Hs20AnqpSubtypes : uint32_t {  
  1019.     OPERATOR_FRIENDLY_NAME = 3,  
  1020.     WAN_METRICS = 4,  
  1021.     CONNECTION_CAPABILITY = 5,  
  1022.     OSU_PROVIDERS_LIST = 8,  
  1023.   };  
  1024.   
  1025.   
  1026.   enum RxFilterType : uint8_t {  
  1027.     V4_MULTICAST = 0,  
  1028.     V6_MULTICAST = 1  
  1029.   };  
  1030.   
  1031.   
  1032.   
  1033.   
  1034.   enum BtCoexistenceMode : uint8_t {  
  1035.     ENABLED = 0,  
  1036.     DISABLED = 1,  
  1037.     SENSE = 2  
  1038.   };  
  1039.   
  1040.   
  1041.   enum ExtRadioWorkDefaults : uint32_t {  
  1042.     TIMEOUT_IN_SECS = 10  
  1043.   };  
  1044.   
  1045.   
  1046.   registerCallback(ISupplicantStaIfaceCallback callback) generates (SupplicantStatus status);  
  1047.   reassociate() generates (SupplicantStatus status);  
  1048.   reconnect() generates (SupplicantStatus status);  
  1049.   disconnect() generates (SupplicantStatus status);  
  1050.   setPowerSave(bool enable) generates (SupplicantStatus status);  
  1051.   initiateTdlsDiscover(MacAddress macAddress) generates (SupplicantStatus status);  
  1052.   initiateTdlsSetup(MacAddress macAddress) generates (SupplicantStatus status);  
  1053.   initiateTdlsTeardown(MacAddress macAddress)generates (SupplicantStatus status);  
  1054.   initiateAnqpQuery(MacAddress macAddress,vec<AnqpInfoId> infoElements,vec<Hs20AnqpSubtypes> subTypes)  
  1055.       generates (SupplicantStatus status);  
  1056.   initiateHs20IconQuery(MacAddress macAddress, string fileName) generates (SupplicantStatus status);  
  1057.   getMacAddress() generates (SupplicantStatus status, MacAddress macAddr);  
  1058.   startRxFilter() generates (SupplicantStatus status);  
  1059.   stopRxFilter() generates (SupplicantStatus status);  
  1060.   addRxFilter(RxFilterType type) generates (SupplicantStatus status);  
  1061.   removeRxFilter(RxFilterType type) generates (SupplicantStatus status);  
  1062.   setBtCoexistenceMode(BtCoexistenceMode mode) generates (SupplicantStatus status);  
  1063.   setBtCoexistenceScanModeEnabled(bool enable) generates (SupplicantStatus status);  
  1064.   setSuspendModeEnabled(bool enable) generates (SupplicantStatus status);  
  1065.   setCountryCode(int8_t[2] code)  generates (SupplicantStatus status);  
  1066.   startWpsRegistrar(Bssid bssid, string pin) generates (SupplicantStatus status);  
  1067.   startWpsPbc(Bssid bssid) generates (SupplicantStatus status);  
  1068.   startWpsPinKeypad(string pin) generates (SupplicantStatus status);  
  1069.   startWpsPinDisplay(Bssid bssid) generates (SupplicantStatus status, string generatedPin);  
  1070.   cancelWps() generates (SupplicantStatus status);  
  1071.   setExternalSim(bool useExternalSim) generates (SupplicantStatus status);  
  1072.   addExtRadioWork(string name, uint32_t freqInMhz, uint32_t timeoutInSec) generates (SupplicantStatus status, uint32_t id);  
  1073.   removeExtRadioWork(uint32_t id) generates (SupplicantStatus status);  
  1074.   enableAutoReconnect(bool enable) generates (SupplicantStatus status);  
  1075. };  
  1076.   
  1077.   
  1078. ========================================================  
  1079. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantIface.hal  
  1080.   
  1081.   
  1082.   
  1083.   
  1084. package android.hardware.wifi.supplicant@1.0;  
  1085.   
  1086.   
  1087. import ISupplicantNetwork;  
  1088.   
  1089.   
  1090. /** 
  1091.  * Interface exposed by the supplicant for each network interface (e.g wlan0) 
  1092.  * it controls. 
  1093.  */  
  1094. interface ISupplicantIface {  
  1095.   
  1096.   
  1097.   enum ParamSizeLimits : uint32_t {  
  1098.       WPS_DEVICE_NAME_MAX_LEN = 32,  
  1099.       WPS_MANUFACTURER_MAX_LEN = 64,  
  1100.       WPS_MODEL_NAME_MAX_LEN = 32,  
  1101.       WPS_MODEL_NUMBER_MAX_LEN = 32,  
  1102.       WPS_SERIAL_NUMBER_MAX_LEN = 32  
  1103.   };  
  1104.   
  1105.   
  1106.   getName() generates (SupplicantStatus status, string name);  
  1107.   getType() generates (SupplicantStatus status, IfaceType type);  
  1108.   addNetwork() generates (SupplicantStatus status, ISupplicantNetwork network);  
  1109.   removeNetwork(SupplicantNetworkId id) generates (SupplicantStatus status);  
  1110.   getNetwork(SupplicantNetworkId id) generates (SupplicantStatus status, ISupplicantNetwork network);  
  1111.   listNetworks() generates (SupplicantStatus status, vec<SupplicantNetworkId> networkIds);  
  1112.   setWpsDeviceName(string name) generates (SupplicantStatus status);  
  1113.   setWpsDeviceType(uint8_t[8] type) generates (SupplicantStatus status);  
  1114.   setWpsManufacturer(string manufacturer) generates (SupplicantStatus status);  
  1115.   setWpsModelName(string modelName) generates (SupplicantStatus status);  
  1116.   setWpsModelNumber(string modelNumber) generates (SupplicantStatus status);  
  1117.   setWpsSerialNumber(string serialNumber) generates (SupplicantStatus status);  
  1118.   setWpsConfigMethods(bitfield<WpsConfigMethods> configMethods) generates (SupplicantStatus status);  
  1119. };  
  1120.   
  1121.   
  1122. ========================================================  
  1123.   
  1124.   
  1125. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h  
  1126.   
  1127.   
  1128.   
  1129.   
  1130. namespace android {  
  1131. namespace hardware {  
  1132. namespace wifi {  
  1133. namespace supplicant {  
  1134. namespace V1_0 {  
  1135. namespace implementation {  
  1136.   
  1137.   
  1138.   
  1139.   
  1140. class StaIface  
  1141.     : public android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface  
  1142. {  // 【实现 HIDL接口 ISupplicantStaIface的类】  
  1143. public:  
  1144.     StaIface(struct wpa_global* wpa_global, const char ifname[]);  
  1145.     ~StaIface() override = default;  
  1146.   
  1147.   
  1148.     void invalidate();  
  1149.     bool isValid();  
  1150.   
  1151.   
  1152.     // Hidl methods exposed.  
  1153.     Return<void> getName(getName_cb _hidl_cb) override;  
  1154.     Return<void> getType(getType_cb _hidl_cb) override;  
  1155.     Return<void> addNetwork(addNetwork_cb _hidl_cb) override;  
  1156.     Return<void> removeNetwork(SupplicantNetworkId id, removeNetwork_cb _hidl_cb) override;  
  1157.     Return<void> getNetwork(SupplicantNetworkId id, getNetwork_cb _hidl_cb) override;  
  1158.     Return<void> listNetworks(listNetworks_cb _hidl_cb) override;  
  1159.     Return<void> registerCallback(const sp<ISupplicantStaIfaceCallback>& callback,registerCallback_cb _hidl_cb) override;  
  1160.     Return<void> reassociate(reassociate_cb _hidl_cb) override;  
  1161.     Return<void> reconnect(reconnect_cb _hidl_cb) override;  
  1162.     Return<void> disconnect(disconnect_cb _hidl_cb) override;  
  1163.     Return<void> setPowerSave(bool enable, setPowerSave_cb _hidl_cb) override;  
  1164.     Return<void> initiateTdlsDiscover(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsDiscover_cb _hidl_cb) override;  
  1165.     Return<void> initiateTdlsSetup(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsSetup_cb _hidl_cb) override;  
  1166.     Return<void> initiateTdlsTeardown(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsTeardown_cb _hidl_cb) override;  
  1167.     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;  
  1168.     Return<void> initiateHs20IconQuery(const hidl_array<uint8_t, 6>& mac_address,const hidl_string& file_name,initiateHs20IconQuery_cb _hidl_cb) override;  
  1169.     Return<void> getMacAddress(getMacAddress_cb _hidl_cb) override;  
  1170.     Return<void> startRxFilter(startRxFilter_cb _hidl_cb) override;  
  1171.     Return<void> stopRxFilter(stopRxFilter_cb _hidl_cb) override;  
  1172.     Return<void> addRxFilter(ISupplicantStaIface::RxFilterType type,addRxFilter_cb _hidl_cb) override;  
  1173.     Return<void> removeRxFilter(ISupplicantStaIface::RxFilterType type,removeRxFilter_cb _hidl_cb) override;  
  1174.     Return<void> setBtCoexistenceMode(ISupplicantStaIface::BtCoexistenceMode mode,setBtCoexistenceMode_cb _hidl_cb) override;  
  1175.     Return<void> setBtCoexistenceScanModeEnabled(bool enable, setBtCoexistenceScanModeEnabled_cb _hidl_cb) override;  
  1176.     Return<void> setSuspendModeEnabled(bool enable, setSuspendModeEnabled_cb _hidl_cb) override;  
  1177.     Return<void> setCountryCode(const hidl_array<int8_t, 2>& code,setCountryCode_cb _hidl_cb) override;  
  1178.     Return<void> startWpsRegistrar(const hidl_array<uint8_t, 6>& bssid, const hidl_string& pin,startWpsRegistrar_cb _hidl_cb) override;  
  1179.     Return<void> startWpsPbc(const hidl_array<uint8_t, 6>& bssid,startWpsPbc_cb _hidl_cb) override;  
  1180.     Return<void> startWpsPinKeypad(const hidl_string& pin, startWpsPinKeypad_cb _hidl_cb) override;  
  1181.     Return<void> startWpsPinDisplay(const hidl_array<uint8_t, 6>& bssid,startWpsPinDisplay_cb _hidl_cb) override;  
  1182.     Return<void> cancelWps(cancelWps_cb _hidl_cb) override;  
  1183.     Return<void> setWpsDeviceName(const hidl_string& name, setWpsDeviceName_cb _hidl_cb) override;  
  1184.     Return<void> setWpsDeviceType(const hidl_array<uint8_t, 8>& type,setWpsDeviceType_cb _hidl_cb) override;  
  1185.     Return<void> setWpsManufacturer(const hidl_string& manufacturer,setWpsManufacturer_cb _hidl_cb) override;  
  1186.     Return<void> setWpsModelName(const hidl_string& model_name,setWpsModelName_cb _hidl_cb) override;  
  1187.     Return<void> setWpsModelNumber(const hidl_string& model_number,setWpsModelNumber_cb _hidl_cb) override;  
  1188.     Return<void> setWpsSerialNumber(const hidl_string& serial_number,setWpsSerialNumber_cb _hidl_cb) override;  
  1189.     Return<void> setWpsConfigMethods(uint16_t config_methods, setWpsConfigMethods_cb _hidl_cb) override;  
  1190.     Return<void> setExternalSim(bool useExternalSim, setExternalSim_cb _hidl_cb) override;  
  1191.     Return<void> addExtRadioWork(const hidl_string& name, uint32_t freq_in_mhz,uint32_t timeout_in_sec, addExtRadioWork_cb _hidl_cb) override;  
  1192.     Return<void> removeExtRadioWork(uint32_t id, removeExtRadioWork_cb _hidl_cb) override;  
  1193.     Return<void> enableAutoReconnect(bool enable, enableAutoReconnect_cb _hidl_cb) override;  
  1194.   
  1195.   
  1196.   
  1197.   
  1198. =============================================================================  
  1199.       
  1200.     /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.c  
  1201.       
  1202. using hidl_return_util::validateAndCall;  // HIDL函数 都是调用这个接口?  
  1203. StaIface::StaIface(struct wpa_global *wpa_global, const char ifname[])  
  1204.     : wpa_global_(wpa_global), ifname_(ifname), is_valid_(true)  
  1205. {  
  1206. }  
  1207.   
  1208.   
  1209. Return<void> StaIface::getName(getName_cb _hidl_cb)  
  1210. {  
  1211.     return validateAndCall(  
  1212.         this, SupplicantStatusCode::FAILURE_IFACE_INVALID,  
  1213.         &StaIface::getNameInternal 【作用函数】, _hidl_cb);  
  1214. }  
  1215.   
  1216.   
  1217. Return<void> StaIface::getType(getType_cb _hidl_cb)  
  1218. {  
  1219.     return validateAndCall(  
  1220.         this【作用对象】, SupplicantStatusCode::FAILURE_IFACE_INVALID【无效状态码】,  
  1221.         &StaIface::getTypeInternal 【WorkFuncT 调用的方法 【作用函数】】, _hidl_cb【回调】);  
  1222. }     
  1223.   
  1224.   
  1225. Return<void> StaIface::enableAutoReconnect(  
  1226.     bool enable, enableAutoReconnect_cb _hidl_cb)  
  1227. {  
  1228.     return validateAndCall(  
  1229.         this, SupplicantStatusCode::FAILURE_IFACE_INVALID,  
  1230.         &StaIface::enableAutoReconnectInternal【作用函数】, _hidl_cb, enable);  
  1231. }  
  1232.   
  1233.   
  1234.   
  1235.   
  1236. template <typename ObjT, typename WorkFuncT, typename... Args>  
  1237. Return<void> validateAndCall(  
  1238.     ObjT* obj, SupplicantStatusCode status_code_if_invalid, WorkFuncT&& work,  
  1239.     const std::function<void(const SupplicantStatus&)>& hidl_cb, Args&&... args)  
  1240. {  
  1241.   
  1242.   
  1243.     if (obj->isValid()) {   
  1244. //【如果ObjT 有效,那么执行方法WorkFuncT,并把WorkFuncT返回值作为参数 执行回调方法 hidl_cb】  
  1245.         hidl_cb((obj->*work)(std::forward<Args>(args)...)); // 没有返回值的回调  
  1246.     } else {  
  1247. //【如果ObjT 无效 执行回调方法 hidl_cb,参数为 SupplicantStatusCode::FAILURE_IFACE_INVALID【无效状态码】】  
  1248.         hidl_cb({status_code_if_invalid, ""});  
  1249.     }  
  1250.     return Void();  
  1251. }  
  1252.   
  1253.   
  1254.   
  1255.   
  1256. template <typename ObjT, typename WorkFuncT, typename ReturnT, typename... Args>  
  1257. Return<void> validateAndCall(  
  1258.     ObjT* obj, SupplicantStatusCode status_code_if_invalid, WorkFuncT&& work,  
  1259.     const std::function<void(const SupplicantStatus&, ReturnT 【有一个返回值的回调】)>& hidl_cb,  
  1260.     Args&&... args)  
  1261. {  
  1262.     if (obj->isValid()) {  
  1263.         const auto& ret_pair =  
  1264.             (obj->*work)(std::forward<Args>(args)...);  
  1265.         const SupplicantStatus& status = std::get<0>(ret_pair);  
  1266.         const auto& ret_value = std::get<1>(ret_pair);  
  1267.         hidl_cb(status, ret_value); // 【一个返回值的回调,回调需要两个参数】  
  1268.     } else {  
  1269.         hidl_cb(  
  1270.             {status_code_if_invalid, ""},  
  1271.             typename std::remove_reference<ReturnT>::type());  
  1272.     }  
  1273.     return Void();  
  1274. }  
  1275.   
  1276.   
  1277.   
  1278.   
  1279. Return<void> validateAndCall(  
  1280.     ObjT* obj, SupplicantStatusCode status_code_if_invalid, WorkFuncT&& work,  
  1281.     const std::function<void(const SupplicantStatus&, ReturnT1, ReturnT2)>&  
  1282.     hidl_cb 【两个返回值的回调,回调需要三个参数】,  
  1283.     Args&&... args)  
  1284. {  
  1285.     if (obj->isValid()) {  
  1286.         const auto& ret_tuple =  
  1287.             (obj->*work)(std::forward<Args>(args)...);  
  1288.         const SupplicantStatus& status = std::get<0>(ret_tuple);  
  1289.         const auto& ret_value1 = std::get<1>(ret_tuple);  
  1290.         const auto& ret_value2 = std::get<2>(ret_tuple);  
  1291.         hidl_cb(status, ret_value1, ret_value2);  
  1292.     } else {  
  1293.         hidl_cb(  
  1294.             {status_code_if_invalid, ""},  
  1295.             typename std::remove_reference<ReturnT1>::type(),  
  1296.             typename std::remove_reference<ReturnT2>::type());  
  1297.     }  
  1298.     return Void();  
  1299. }  
  1300.   
  1301.   
  1302.   
  1303.   
  1304. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.c  
  1305. Return<void> StaIface::enableAutoReconnect(  
  1306.     bool enable, enableAutoReconnect_cb _hidl_cb)  
  1307. {  
  1308.     return validateAndCall(  
  1309.         this, SupplicantStatusCode::FAILURE_IFACE_INVALID,  
  1310.         &StaIface::enableAutoReconnectInternal 【作用函数】, _hidl_cb, enable);  
  1311. }  
  1312.   
  1313.   
  1314. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.c  
  1315. SupplicantStatus StaIface::enableAutoReconnectInternal(bool enable)  
  1316. {  
  1317.     struct wpa_supplicant *wpa_s = retrieveIfacePtr();  
  1318.     wpa_s->auto_reconnect_disabled = enable ? 0 : 1;  //  设置了结构体 wpa_s->auto_reconnect_disabled  
  1319.     return {SupplicantStatusCode::SUCCESS, ""}; // 感觉像返回了元组,这个元组进入回调  
  1320. }  
  1321.   
  1322.   
  1323. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.c  
  1324.   
  1325.   
  1326. Return<void> StaIface::getMacAddress(getMacAddress_cb _hidl_cb)  
  1327. {  
  1328.     return validateAndCall(  
  1329.         this, SupplicantStatusCode::FAILURE_IFACE_INVALID,  
  1330.         &StaIface::getMacAddressInternal, _hidl_cb);  
  1331. }  
  1332.   
  1333.   
  1334. constexpr char kGetMacAddress[] = "MACADDR";  
  1335.   
  1336.   
  1337. StaIface::getMacAddressInternal()  
  1338. {  
  1339.     struct wpa_supplicant *wpa_s = retrieveIfacePtr();  
  1340.     std::vector<char> cmd(kGetMacAddress 【"MACADDR" 指针】, kGetMacAddress【初始化位置】 + sizeof(kGetMacAddress) 【字符串大小】);  
  1341.     char driver_cmd_reply_buf[4096] = {};  
  1342.     // 调用驱动执行命令 MACADDR 得到参数返回值 driver_cmd_reply_buf"Macaddr = XX:XX:XX:XX:XX:XX"    
  1343.     //函数返回值 ret 代表 命令是否执行成功  
  1344.     int ret = wpa_drv_driver_cmd(wpa_s, cmd.data(), driver_cmd_reply_buf,sizeof(driver_cmd_reply_buf));  
  1345.     // Reply is of the format: "Macaddr = XX:XX:XX:XX:XX:XX"  
  1346.     std::string reply_str = driver_cmd_reply_buf;  
  1347.       
  1348.     // 如果调用失败的情况发生  那么返回 执行失败的元组  
  1349.    if (ret < 0 || reply_str.empty() || reply_str.find("=") == std::string::npos) {  
  1350.         return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};  
  1351.     }  
  1352.   
  1353.   
  1354. eply_str.erase(remove_if(reply_str.begin(), reply_str.end(), isspace),reply_str.end());  
  1355. std::string mac_addr_str =reply_str.substr(reply_str.find("=") + 1, reply_str.size()); // 截取子字符串=后的  
  1356.     std::array<uint8_t, 6> mac_addr; //字节数组  
  1357.     if (hwaddr_aton(mac_addr_str.c_str(), mac_addr.data())) {   
  1358.     //【hwaddr_aton(const char *txt, u8 *addr)】 Convert ASCII string to MAC address  
  1359.     //  0 on success, -1 on failure   MAC address as a string (e.g., "00:11:22:33:44:55")   
  1360.     return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};  
  1361.     }  
  1362.   
  1363.   
  1364.      // 返回 SupplicantStatusCode 和 mac字节数组的元组  
  1365.     return {{SupplicantStatusCode::SUCCESS, ""}, mac_addr};   
  1366.       
  1367. }  
  1368.   
  1369.   
  1370.   
  1371.   
  1372.   
  1373.   
  1374.   
  1375.   
  1376. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java  
  1377.     /** See ISupplicant.hal for documentation */  
  1378.     public boolean enableAutoReconnect(boolean enable) {  
  1379.         synchronized (mLock) {  
  1380.             final String methodStr = "enableAutoReconnect";  
  1381.             if (!checkSupplicantAndLogFailure(methodStr)) return false;  
  1382.             try { // enableAutoReconnect 不需要参数返回值  单单只需要返回状态就可以  
  1383.                 SupplicantStatus status = mISupplicantStaIface.enableAutoReconnect(enable);  
  1384.                 return checkStatusAndLogFailure(status, methodStr);   
  1385.             } catch (RemoteException e) {  
  1386.                 handleRemoteException(e, methodStr);  
  1387.                 return false;  
  1388.             }  
  1389.         }  
  1390.     }  
  1391.       
  1392.       
  1393.       
  1394. public String getMacAddress() {  
  1395.         synchronized (mLock) {  
  1396.             final String methodStr = "getMacAddress";  
  1397.             if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;  
  1398.             Mutable<String> gotMac = new Mutable<>();  
  1399.             try { // getMacAddress函数 需要参数返回值macAddr,所以需要->{}来表示回调方法,在回调方法内取得  
  1400.                  // 除了SupplicantStatus 之外的参数    ->{} 是对元组的操作  
  1401.                 mISupplicantStaIface.getMacAddress((SupplicantStatus status,  
  1402.                         byte[/* 6 */] macAddr) -> {  
  1403.                     if (checkStatusAndLogFailure(status, methodStr)) {  
  1404.                     // 回调函数,把{{SupplicantStatusCode::SUCCESS, ""}, mac_addr} 中的mac_addr 进行回调提取  
  1405.                         gotMac.value = NativeUtil.macAddressFromByteArray(macAddr);  
  1406.                     }  
  1407.                 });  
  1408.             } catch (RemoteException e) {  
  1409.                 handleRemoteException(e, methodStr);  
  1410.             }  
  1411.             return gotMac.value;  
  1412.         }  
  1413.     }  
  1414. =============================================================================  
  1415. disconnect 从 .hal 文件开始到 与驱动交互结束分析 -------开始  
  1416. disconnect(disconnect_cb _hidl_cb)--->disconnectInternal()--->wpas_request_disconnection(wpa_s)  
  1417. --->wpa_drv_deauthenticate()--->wpa_s->driver->deauthenticate--->NL80211_CMD_DISCONNECT  
  1418. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h  
  1419. Return<void> disconnect(disconnect_cb _hidl_cb) override;  
  1420.   
  1421. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp  
  1422. Return<void> StaIface::disconnect(disconnect_cb _hidl_cb)  
  1423. {  
  1424. return validateAndCall(this, SupplicantStatusCode::FAILURE_IFACE_INVALID, &StaIface::disconnectInternal, _hidl_cb);  
  1425. }  
  1426.   
  1427.   
  1428.   
  1429.   
  1430. SupplicantStatus StaIface::disconnectInternal()  
  1431. {  
  1432. struct wpa_supplicant *wpa_s = retrieveIfacePtr();  
  1433. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {  
  1434.     return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};  
  1435.  }  
  1436. wpas_request_disconnection(wpa_s); // 请求断开函数  
  1437. return {SupplicantStatusCode::SUCCESS, ""};  
  1438. }  
  1439.   
  1440.   
  1441.   
  1442.   
  1443.   
  1444.   
  1445. /external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.c  
  1446. void wpas_request_disconnection(struct wpa_supplicant *wpa_s)  
  1447. {  
  1448. #ifdef CONFIG_SME  
  1449.       wpa_s->sme.prev_bssid_set = 0;  
  1450. #endif /* CONFIG_SME */  
  1451. wpa_s->reassociate = 0;  
  1452. wpa_s->disconnected = 1;  
  1453. wpa_supplicant_cancel_sched_scan(wpa_s);  
  1454. wpa_supplicant_cancel_scan(wpa_s);  
  1455. #define WLAN_REASON_DEAUTH_LEAVING 3  
  1456. wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);  
  1457. eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);  
  1458. }  
  1459.   
  1460.   
  1461.   
  1462.   
  1463. void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,int reason_code)  
  1464. {  
  1465. wpa_drv_deauthenticate(wpa_s, addr, reason_code);  
  1466. wpa_supplicant_event(wpa_s, EVENT_DEAUTH, &event);  
  1467. }  
  1468.   
  1469.   
  1470.   
  1471.   
  1472. /external/wpa_supplicant_8/wpa_supplicant/driver_i.h  
  1473. static inline int wpa_drv_deauthenticate(struct wpa_supplicant *wpa_s,const u8 *addr, int reason_code)  
  1474. {  
  1475. if (wpa_s->driver->deauthenticate) {  
  1476. return wpa_s->driver->deauthenticate(wpa_s->drv_priv, addr,reason_code); 【与驱动交互】  
  1477. }  
  1478. return -1;  
  1479. }  
  1480.   
  1481.   
  1482.   
  1483.   
  1484. /external/wpa_supplicant_8/src/drivers/driver_nl80211.c  
  1485. //【 nl80211对应的驱动提供的接口函数 wpa_s->driver 数据结构】  
  1486. const struct wpa_driver_ops wpa_driver_nl80211_ops = {  
  1487. //<span style="white-space:pre;">   </span>ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,reason_code, 0);  
  1488. .deauthenticate = driver_nl80211_deauthenticate,  
  1489.   
  1490. }  
  1491. disconnect 从 .hal 文件开始到 与驱动交互结束分析 -------结束  
  1492. =============================================================================  
  1493.       
  1494.       
  1495.   
  1496.   
  1497.  /frameworks/opt/net/wifi/service/jni/com_android_server_wifi_WifiNative.cpp  
  1498. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative.java  
  1499.   
  1500.   
  1501. doBooleanCommand("SET device_name " + name); ======= mSupplicantStaIfaceHal.setWpsDeviceName(name);  
  1502. doBooleanCommand("SET serial_number " + value); =====mSupplicantStaIfaceHal.setWpsSerialNumber(value);  
  1503. doBooleanCommand("SET ps 1"); doBooleanCommand("SET ps 0");===mSupplicantStaIfaceHal.setPowerSave(enabled);  
  1504. doBooleanCommand("DISCONNECT"); =======mSupplicantStaIfaceHal.disconnect();  
  1505. doBooleanCommand("DRIVER SETSUSPENDMODE 1"); doBooleanCommand("DRIVER SETSUSPENDMODE 0");  
  1506. ======mSupplicantStaIfaceHal.setSuspendModeEnabled(enabled);  
  1507. 变化好大好大  
  1508.   
  1509.   
  1510.   
  1511.   
  1512.   
  1513.   
  1514. 总结:  
  1515. 在安卓8.0  大规模删除了原有的JNI函数的注册 ~~~使用HIDL定义了很多 对应的接口,直接调用这些接口进行IPC交互  
  1516. 改动太大 太大~~~~  
  1517. 猜测的目的可能是为了Treable计划,使得上层Framework往下变得解耦  
  1518. 使得上下层能独立更新,用户更新系统时不依赖于硬件的限制  
  1519.   
  1520.   
  1521. disconnect(disconnect_cb _hidl_cb)--->disconnectInternal()--->wpas_request_disconnection(wpa_s)  
  1522. --->wpa_drv_deauthenticate()--->wpa_s->driver->deauthenticate--->NL80211_CMD_DISCONNECT  
  1523. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h  
  1524. Return<void> disconnect(disconnect_cb _hidl_cb) override;  
  1525. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp  
  1526. Return<void> StaIface::disconnect(disconnect_cb _hidl_cb)  
  1527. {  
  1528. return validateAndCall(this, SupplicantStatusCode::FAILURE_IFACE_INVALID,&StaIface::disconnectInternal, _hidl_cb);  
  1529. }  
  1530.   
  1531.   
  1532.   
  1533.   
  1534. SupplicantStatus StaIface::disconnectInternal()  
  1535. {  
  1536. struct wpa_supplicant *wpa_s = retrieveIfacePtr();  
  1537. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {  
  1538.         return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};  
  1539.     }  
  1540.    wpas_request_disconnection(wpa_s); // 请求断开函数  
  1541.    return {SupplicantStatusCode::SUCCESS, ""};  
  1542. }  
  1543.   
  1544.   
  1545.   
  1546.   
  1547.   
  1548.   
  1549. /external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.c  
  1550. void wpas_request_disconnection(struct wpa_supplicant *wpa_s)  
  1551. {  
  1552. #ifdef CONFIG_SME  
  1553.         wpa_s->sme.prev_bssid_set = 0;  
  1554. #endif /* CONFIG_SME */  
  1555. wpa_s->reassociate = 0;  
  1556. wpa_s->disconnected = 1;  
  1557. wpa_supplicant_cancel_sched_scan(wpa_s);  
  1558. wpa_supplicant_cancel_scan(wpa_s);  
  1559. #define WLAN_REASON_DEAUTH_LEAVING 3  
  1560. wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);  
  1561. eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);  
  1562. }  
  1563.   
  1564.   
  1565.   
  1566.   
  1567. void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,int reason_code)  
  1568. {  
  1569. wpa_drv_deauthenticate(wpa_s, addr, reason_code);  
  1570. wpa_supplicant_event(wpa_s, EVENT_DEAUTH, &event);  
  1571. }  
  1572.   
  1573.   
  1574.   
  1575.   
  1576. /external/wpa_supplicant_8/wpa_supplicant/driver_i.h  
  1577. static inline int wpa_drv_deauthenticate(struct wpa_supplicant *wpa_s,const u8 *addr, int reason_code)  
  1578. {  
  1579. if (wpa_s->driver->deauthenticate) {  
  1580.       return wpa_s->driver->deauthenticate(wpa_s->drv_priv, addr,reason_code); 【与驱动交互】  
  1581.     }  
  1582.    return -1;  
  1583. }  
  1584.   
  1585.   
  1586.   
  1587.   
  1588. /external/wpa_supplicant_8/src/drivers/driver_nl80211.c  
  1589. //【 nl80211对应的驱动提供的接口函数 wpa_s->driver 数据结构】  
  1590. const struct wpa_driver_ops wpa_driver_nl80211_ops = {  
  1591.         //ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,reason_code, 0);  
  1592.        .deauthenticate = driver_nl80211_deauthenticate,  
  1593. }  
[java]  view plain  copy
  1. 【 HIDL方法 追踪 】  
  2. // Hidl methods exposed.    
  3. Return<void> getName(getName_cb _hidl_cb) override;    
  4. Return<void> getType(getType_cb _hidl_cb) override;    
  5. Return<void> addNetwork(addNetwork_cb _hidl_cb) override;    
  6. Return<void> removeNetwork(SupplicantNetworkId id, removeNetwork_cb _hidl_cb) override;    
  7. Return<void> getNetwork(SupplicantNetworkId id, getNetwork_cb _hidl_cb) override;    
  8. Return<void> listNetworks(listNetworks_cb _hidl_cb) override;    
  9. Return<void> registerCallback(const sp<ISupplicantStaIfaceCallback>& callback,registerCallback_cb _hidl_cb) override;    
  10. Return<void> reassociate(reassociate_cb _hidl_cb) override;    
  11. Return<void> reconnect(reconnect_cb _hidl_cb) override;    
  12. Return<void> disconnect(disconnect_cb _hidl_cb) override;  【8 disconnect_cb】  
  13. Return<void> setPowerSave(bool enable, setPowerSave_cb _hidl_cb) override;    
  14. Return<void> initiateTdlsDiscover(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsDiscover_cb _hidl_cb) override;    
  15. Return<void> initiateTdlsSetup(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsSetup_cb _hidl_cb) override;    
  16. Return<void> initiateTdlsTeardown(const hidl_array<uint8_t, 6>& mac_address,initiateTdlsTeardown_cb _hidl_cb) override;    
  17. 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;    
  18. Return<void> initiateHs20IconQuery(const hidl_array<uint8_t, 6>& mac_address,const hidl_string& file_name,initiateHs20IconQuery_cb _hidl_cb) override;    
  19. Return<void> getMacAddress(getMacAddress_cb _hidl_cb) override;    
  20. Return<void> startRxFilter(startRxFilter_cb _hidl_cb) override;    
  21. Return<void> stopRxFilter(stopRxFilter_cb _hidl_cb) override;    
  22. Return<void> addRxFilter(ISupplicantStaIface::RxFilterType type,addRxFilter_cb _hidl_cb) override;    
  23. Return<void> removeRxFilter(ISupplicantStaIface::RxFilterType type,removeRxFilter_cb _hidl_cb) override;    
  24. Return<void> setBtCoexistenceMode(ISupplicantStaIface::BtCoexistenceMode mode,setBtCoexistenceMode_cb _hidl_cb) override;    
  25. Return<void> setBtCoexistenceScanModeEnabled(bool enable, setBtCoexistenceScanModeEnabled_cb _hidl_cb) override;    
  26. Return<void> setSuspendModeEnabled(bool enable, setSuspendModeEnabled_cb _hidl_cb) override;    
  27. Return<void> setCountryCode(const hidl_array<int8_t, 2>& code,setCountryCode_cb _hidl_cb) override;    
  28. Return<void> startWpsRegistrar(const hidl_array<uint8_t, 6>& bssid, const hidl_string& pin,startWpsRegistrar_cb _hidl_cb) override;    
  29. Return<void> startWpsPbc(const hidl_array<uint8_t, 6>& bssid,startWpsPbc_cb _hidl_cb) override;    
  30. Return<void> startWpsPinKeypad(const hidl_string& pin, startWpsPinKeypad_cb _hidl_cb) override;    
  31. Return<void> startWpsPinDisplay(const hidl_array<uint8_t, 6>& bssid,startWpsPinDisplay_cb _hidl_cb) override;    
  32. Return<void> cancelWps(cancelWps_cb _hidl_cb) override;    
  33. Return<void> setWpsDeviceName(const hidl_string& name, setWpsDeviceName_cb _hidl_cb) override;    
  34. Return<void> setWpsDeviceType(const hidl_array<uint8_t, 8>& type,setWpsDeviceType_cb _hidl_cb) override;    
  35. Return<void> setWpsManufacturer(const hidl_string& manufacturer,setWpsManufacturer_cb _hidl_cb) override;    
  36. Return<void> setWpsModelName(const hidl_string& model_name,setWpsModelName_cb _hidl_cb) override;    
  37. Return<void> setWpsModelNumber(const hidl_string& model_number,setWpsModelNumber_cb _hidl_cb) override;    
  38. Return<void> setWpsSerialNumber(const hidl_string& serial_number,setWpsSerialNumber_cb _hidl_cb) override;    
  39. Return<void> setWpsConfigMethods(uint16_t config_methods, setWpsConfigMethods_cb _hidl_cb) override;    
  40. Return<void> setExternalSim(bool useExternalSim, setExternalSim_cb _hidl_cb) override;    
  41. Return<void> addExtRadioWork(const hidl_string& name, uint32_t freq_in_mhz,uint32_t timeout_in_sec, addExtRadioWork_cb _hidl_cb) override;    
  42. Return<void> removeExtRadioWork(uint32_t id, removeExtRadioWork_cb _hidl_cb) override;    
  43. Return<void> enableAutoReconnect(bool enable, enableAutoReconnect_cb _hidl_cb) override;    
  44.   
  45.   
  46.   
  47.   
  48.   
  49.   
  50.   
  51.   
  52.   
  53.   
  54.   
  55.   
  56. =====================================【】===========================  
  57.    
  58. =======================================【1 getName_cb 】===================================  
  59.   
  60.   
  61.  getName(getName_cb _hidl_cb) --->getNameInternal()--->{{SupplicantStatusCode::SUCCESS, ""}, ifname_}  
  62.   
  63.   
  64. Return<void> getName(getName_cb _hidl_cb) override;    
  65. std::pair<SupplicantStatus, std::string> StaIface::getNameInternal()  
  66. {  
  67.          return {{SupplicantStatusCode::SUCCESS, ""}, ifname_};  
  68. }  
  69. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h    
  70. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp  
  71. =====================================【2 getType_cb 】==============================================  
  72. getType(getType_cb _hidl_cb) ---> getTypeInternal()---> {{SupplicantStatusCode::SUCCESS, ""}, IfaceType::STA}  
  73.   
  74.   
  75. Return<void> getType(getType_cb _hidl_cb) override;  
  76.   
  77.   
  78. std::pair<SupplicantStatus, IfaceType> StaIface::getTypeInternal()  
  79. {  
  80.       return {{SupplicantStatusCode::SUCCESS, ""}, IfaceType::STA};  
  81. }  
  82. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h    
  83. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp  
  84. =====================================【3 addNetwork_cb 】===========================  
  85. addNetwork(addNetwork_cb _hidl_cb) ---> addNetworkInternal() ---> wpa_supplicant_add_network(wpa_s)  
  86. --->wpa_config_add_network(wpa_s->conf)--->wpa_config_add_network()  
  87. Return<void> addNetwork(addNetwork_cb _hidl_cb) override;    
  88.   
  89.   
  90. std::pair<SupplicantStatus, sp<ISupplicantNetwork>>  
  91. StaIface::addNetworkInternal()  
  92. {  
  93. android::sp<ISupplicantStaNetwork> network;  
  94. struct wpa_supplicant *wpa_s = retrieveIfacePtr();  
  95. struct wpa_ssid *ssid = wpa_supplicant_add_network(wpa_s);  
  96. HidlManager *hidl_manager = HidlManager::getInstance();  
  97. hidl_manager->getStaNetworkHidlObjectByIfnameAndNetworkId(wpa_s->ifname, ssid->id, &network)  
  98. return {{SupplicantStatusCode::SUCCESS, ""}, network};  
  99. }  
  100.   
  101.   
  102. int HidlManager::getStaNetworkHidlObjectByIfnameAndNetworkId(const std::string &ifname, int network_id,  
  103.      android::sp<ISupplicantStaNetwork> *network_object)  
  104. {  
  105. if (ifname.empty() || network_id < 0 || !network_object)    return 1;  
  106. // Generate the key to be used to lookup the network.  
  107. const std::string network_key = getNetworkObjectMapKey(ifname, network_id);  
  108. auto network_object_iter = sta_network_object_map_.find(network_key);  
  109. if (network_object_iter == sta_network_object_map_.end())   return 1;  
  110. *network_object = network_object_iter->second;  
  111. return 0;  
  112. }  
  113.   
  114.   
  115.   
  116.   
  117. struct wpa_ssid * wpa_supplicant_add_network(struct wpa_supplicant *wpa_s)  
  118. {  
  119. struct wpa_ssid *ssid;  
  120. ssid = wpa_config_add_network(wpa_s->conf);  
  121. wpas_notify_network_added(wpa_s, ssid);  
  122. ssid->disabled = 1;  
  123. wpa_config_set_network_defaults(ssid);  
  124.   
  125. return ssid;  
  126. }  
  127.   
  128.   
  129.   
  130.   
  131. struct wpa_ssid * wpa_config_add_network(struct wpa_config *config)  
  132. {  
  133. wpa_config_update_prio_list(config);  
  134. }  
  135.   
  136.   
  137. int wpa_config_update_prio_list(struct wpa_config *config)  
  138. {  
  139. wpa_config_add_prio_network(config, ssid)  
  140. }  
  141.   
  142.   
  143. int wpa_config_add_prio_network(struct wpa_config *config,struct wpa_ssid *ssid){  
  144. nlist = os_realloc_array(config->pssid, config->num_prio + 1,sizeof(struct wpa_ssid *));  
  145. nlist[prio] = ssid;<span style="white-space:pre;">  </span>  
  146. }  
  147.   
  148. msg = dbus_message_new_signal(wpa_s->dbus_new_path,WPAS_DBUS_NEW_IFACE_INTERFACE,sig_name)  
  149. dbus_message_iter_init_append(msg, &iter);  
  150. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h    
  151. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp  
  152. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/hidl_manager.cpp  
  153. /external/wpa_supplicant_8/wpa_supplicant/config.c  
  154. /external/wpa_supplicant_8/wpa_supplicant/dbus/dbus_new.c  
  155.   
  156.   
  157.   
  158.   
  159.   
  160.   
  161.   
  162.   
  163. =====================================【3 removeNetwork_cb 】===========================  
  164.   
  165.   
  166. removeNetwork(removeNetwork_cb _hidl_cb) ---> removeNetworkInternal() ---> wpa_supplicant_remove_network(wpa_s)  
  167. --->wpa_supplicant_deauthenticate(wpa_s->conf)--->wpa_drv_deauthenticate()--->NL80211_CMD_DISCONNECT  
  168.   
  169.   
  170.   
  171.   
  172. Return<void> removeNetwork(SupplicantNetworkId id, removeNetwork_cb _hidl_cb) override;    
  173.   
  174.   
  175. SupplicantStatus StaIface::removeNetworkInternal(SupplicantNetworkId id)  
  176. {  
  177. struct wpa_supplicant *wpa_s = retrieveIfacePtr();  
  178. int result = wpa_supplicant_remove_network(wpa_s, id);  
  179. }  
  180.   
  181.   
  182. int wpa_supplicant_remove_network(struct wpa_supplicant *wpa_s, int id)  
  183. {  
  184.    wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);  
  185. }  
  186.   
  187. void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,int reason_code)  
  188. {  
  189.     wpa_drv_deauthenticate(wpa_s, addr, reason_code);  
  190. }  
  191.   
  192.   
  193. static inline int wpa_drv_deauthenticate(struct wpa_supplicant *wpa_s,const u8 *addr, int reason_code)  
  194. {  
  195.        return wpa_s->driver->deauthenticate(wpa_s->drv_priv, addr,reason_code);  
  196. }  
  197.   
  198.   
  199. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h    
  200. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp  
  201. /external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.c  
  202. /external/wpa_supplicant_8/wpa_supplicant/driver_i.h  
  203. /external/wpa_supplicant_8/src/drivers/driver_nl80211.c    
  204. =====================================【4 getNetwork_cb 】===========================  
  205. Return<void> getNetwork(SupplicantNetworkId id, getNetwork_cb _hidl_cb) override;    
  206.   
  207.   
  208.   
  209.   
  210.   
  211.   
  212.   
  213.   
  214. P2pIface::getNetworkInternal(SupplicantNetworkId id)  
  215. {  
  216. android::sp<ISupplicantP2pNetwork> network;  
  217. struct wpa_supplicant* wpa_s = retrieveIfacePtr();  
  218. struct wpa_ssid* ssid = wpa_config_get_network(wpa_s->conf, id);  
  219. }  
  220.   
  221.   
  222. =====================================【5 listNetworks_cb 】===========================  
  223. Return<void> listNetworks(listNetworks_cb _hidl_cb) override;   
  224.   
  225.   
  226.   
  227.   
  228. StaIface::listNetworksInternal()  
  229. {  
  230. std::vector<SupplicantNetworkId> network_ids;  
  231. struct wpa_supplicant *wpa_s = retrieveIfacePtr();  
  232. for (struct wpa_ssid *wpa_ssid = wpa_s->conf->ssid; wpa_ssid;wpa_ssid = wpa_ssid->next) {  
  233.              network_ids.emplace_back(wpa_ssid->id);  
  234.     }  
  235.         return {{SupplicantStatusCode::SUCCESS, ""}, std::move(network_ids)};  
  236. }  
  237.   
  238.   
  239. =====================================【6 registerCallback_cb 】===========================  
  240. Return<void> registerCallback(const sp<ISupplicantStaIfaceCallback>& callback,registerCallback_cb _hidl_cb) override;    
  241.   
  242.   
  243.   
  244.   
  245.   
  246.   
  247. SupplicantStatus StaIface::registerCallbackInternal( const sp<ISupplicantStaIfaceCallback> &callback)  
  248. {  
  249. HidlManager *hidl_manager = HidlManager::getInstance();  
  250. <span style="white-space:pre;"> </span>if (!hidl_manager || hidl_manager->addStaIfaceCallbackHidlObject(ifname_, callback)) {  
  251.              return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};  
  252.               }  
  253. return {SupplicantStatusCode::SUCCESS, ""};  
  254. }  
  255.   
  256.   
  257. =====================================【7 reassociate 】===========================  
  258.   
  259.   
  260. Return<void> reassociate(reassociate_cb _hidl_cb) override;    
  261.   
  262.   
  263. SupplicantStatus StaIface::reassociateInternal()  
  264. {  
  265. struct wpa_supplicant *wpa_s = retrieveIfacePtr();  
  266. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {  
  267.       return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};  
  268.  }  
  269. wpas_request_connection(wpa_s);  
  270. return {SupplicantStatusCode::SUCCESS, ""};  
  271. }  
  272.   
  273.   
  274.   
  275.   
  276. void wpas_request_connection(struct wpa_supplicant *wpa_s)  
  277. {  
  278. wpa_supplicant_fast_associate(wpa_s)  
  279. }  
  280. int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)  
  281. {  
  282. wpas_select_network_from_last_scan(wpa_s, 01);  
  283. }  
  284. wpas_select_network_from_last_scan(){  
  285. wpa_supplicant_connect(wpa_s, selected, ssid)  
  286. }  
  287. wpa_supplicant_associate(wpa_s, selected, ssid);  
  288.   
  289.   
  290. =====================================【7  reconnect_cb 】===========================  
  291. Return<void> reconnect(reconnect_cb _hidl_cb) override;   
  292.   
  293.   
  294. SupplicantStatus StaIface::reconnectInternal()  
  295. {  
  296. struct wpa_supplicant *wpa_s = retrieveIfacePtr();  
  297. wpas_request_connection(wpa_s);  
  298. return {SupplicantStatusCode::SUCCESS, ""};  
  299. }  
  300.   
  301.   
  302.   
  303.   
  304. void wpas_request_connection(struct wpa_supplicant *wpa_s)  
  305. {  
  306. wpa_supplicant_reinit_autoscan(wpa_s);  
  307. wpa_supplicant_fast_associate(wpa_s)  
  308.   
  309.   
  310. }  
  311.   
  312.   
  313.   
  314.   
  315. =====================================【8 disconnect_cb】================================  
  316. disconnect(disconnect_cb _hidl_cb)--->disconnectInternal()--->wpas_request_disconnection(wpa_s)    
  317. --->wpa_drv_deauthenticate()--->wpa_s->driver->deauthenticate--->NL80211_CMD_DISCONNECT   
  318.   
  319.   
  320. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h    
  321. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.cpp  
  322. /external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.c    
  323. /external/wpa_supplicant_8/wpa_supplicant/driver_i.h    
  324. /external/wpa_supplicant_8/src/drivers/driver_nl80211.c    
  325. =====================================【 setPowerSave 】===========================  
  326. Return<void> setPowerSave(bool enable, setPowerSave_cb _hidl_cb) override;    
  327.   
  328.   
  329.   
  330.   
  331. SupplicantStatus StaIface::setPowerSaveInternal(bool enable)  
  332. {  
  333. struct wpa_supplicant *wpa_s = retrieveIfacePtr();  
  334. wpa_drv_set_p2p_powersave(wpa_s, enable, -1, -1))   
  335. return {SupplicantStatusCode::SUCCESS, ""};  
  336. }  
  337.   
  338.   
  339.   
  340.   
  341. static inline int wpa_drv_set_p2p_powersave(struct wpa_supplicant *wpa_s,int legacy_ps, int opp_ps,  
  342. int ctwindow)  
  343. {  
  344. if (!wpa_s->driver->set_p2p_powersave) return -1;  
  345. return wpa_s->driver->set_p2p_powersave(wpa_s->drv_priv, legacy_ps,opp_ps, ctwindow);  
  346. }  
  347.   
  348.   
  349. =====================================【 getMacAddress 】===========================  
  350.   
  351.   
  352. Return<void> getMacAddress(getMacAddress_cb _hidl_cb) override;    
  353.   
  354.   
  355.   
  356.   
  357. std::pair<SupplicantStatus, std::array<uint8_t, 6>>  
  358. StaIface::getMacAddressInternal()  
  359. {  
  360. struct wpa_supplicant *wpa_s = retrieveIfacePtr();  
  361. char driver_cmd_reply_buf[4096] = {};  
  362. int ret = wpa_drv_driver_cmd(wpa_s, cmd.data(), driver_cmd_reply_buf,  
  363.   
  364. }  
  365.   
  366.   
  367. static inline int wpa_drv_driver_cmd(struct wpa_supplicant *wpa_s,  
  368. <span style="white-space:pre;">             </span>     char *cmd, char *buf, size_t buf_len)  
  369. {  
  370. if (!wpa_s->driver->driver_cmd)  
  371.     return -1;  
  372. return wpa_s->driver->driver_cmd(wpa_s->drv_priv, cmd, buf, buf_len);  
  373. }  
  374.   
  375.     
[java]  view plain  copy
  1.   
[cpp]  view plain  copy
  1.   
[cpp]  view plain  copy
  1. =================================================================================  
  2. 【实现HIDL接口?   ISupplicantStaIface 这个HIDL接口?】  
  3. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_iface.h   
  4. StaIface    : public android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface    
  5.   
  6. 【实现HIDL接口?   ISupplicant 这个HIDL接口?】  
  7. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/supplicant.h   
  8. class Supplicant : public android::hardware::wifi::supplicant::V1_0::ISupplicant  
  9.   
  10. 【实现HIDL接口?   ISupplicantP2pIface 这个HIDL接口?】  
  11. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/p2p_iface.h   
  12. class P2pIface : public android::hardware::wifi::supplicant::V1_0::ISupplicantP2pIface  
  13.   
  14. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/p2p_network.h  
  15. 【实现HIDL接口?   ISupplicantP2pNetwork 这个HIDL接口?】  
  16. class P2pNetwork : public ISupplicantP2pNetwork    
  17.   
  18. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/sta_network.h  
  19. 【实现HIDL接口?   ISupplicantStaNetwork 这个HIDL接口?】  
  20. class StaNetwork : public ISupplicantStaNetwork  
  21.   
  22.   
  23. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaIface.hal   【ok】  
  24. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantIface.hal    
  25. /hardware/interfaces/wifi/supplicant/1.0/ISupplicant.hal  【ok】  
  26.   
  27. 【未找到对应的实现类 但存在#include <android/hardware/wifi/supplicant/1.0/ISupplicantCallback.h> 】  
  28. 【应该是.bp 文件进行了转换】  
  29. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantCallback.hal    
  30. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantNetwork.hal  
  31. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantP2pIface.hal  【ok】  
  32. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantP2pIfaceCallback.hal  
  33. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantP2pNetwork.hal  【ok】  
  34. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantP2pNetworkCallback.hal  
  35. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaIface.hal  
  36. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaIfaceCallback.hal  
  37. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaNetwork.hal   【ok】  
  38. /hardware/interfaces/wifi/supplicant/1.0/ISupplicantStaNetworkCallback.hal  
  39. /hardware/interfaces/wifi/supplicant/1.0/types.hal  
  40.     
  41. interface ISupplicantStaIface extends ISupplicantIface { }  
  42. interface ISupplicantIface { }  
  43. interface ISupplicant {}  
  44. interface ISupplicantCallback {}  
  45. interface ISupplicantNetwork {}  
  46. interface ISupplicantP2pIface {}  
  47. interface ISupplicantP2pIfaceCallback {}  
  48. interface ISupplicantP2pNetwork {}  
  49. interface ISupplicantP2pNetworkCallback {}  
  50. interface ISupplicantStaIface {}  
  51. interface ISupplicantStaIfaceCallback {}  
  52. interface ISupplicantStaNetwork {}  
  53. interface ISupplicantStaNetworkCallback {}  
  54. interface types {}  
  55.   
  56. =================================================================================  
  57.   
  58. 在 /hardware/interfaces/wifi/supplicant/1.0/   定义了suplicant对应的HIDL 接口  
  59. 在 /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/ 实现了上述supplicant对应的上述接口  
  60.   
  61.   
  62. /hardware/interfaces/wifi/supplicant/1.0/  【为supplicant定义的hidl接口】  
  63. ISupplicant.hal 29-Aug-2017 5.1 KiB  
  64. ISupplicantCallback.hal 29-Aug-2017 1.4 KiB  
  65. ISupplicantIface.hal    29-Aug-2017 7.8 KiB  
  66. ISupplicantNetwork.hal  29-Aug-2017 2.3 KiB  
  67. ISupplicantP2pIface.hal 29-Aug-2017 25.7 KiB  
  68. ISupplicantP2pIfaceCallback.hal 29-Aug-2017 7.9 KiB  
  69. ISupplicantP2pNetwork.hal   29-Aug-2017 4.7 KiB  
  70. ISupplicantP2pNetworkCallback.hal   29-Aug-2017 1 KiB  
  71. ISupplicantStaIface.hal 29-Aug-2017 16.8 KiB  
  72. ISupplicantStaIfaceCallback.hal 29-Aug-2017 17.4 KiB  
  73. ISupplicantStaNetwork.hal   29-Aug-2017 36.1 KiB  
  74. ISupplicantStaNetworkCallback.hal   29-Aug-2017 2.3 KiB  
  75. types.hal   29-Aug-2017 3 KiB  
  76.   
  77.   
  78. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/  
  79. hidl.cpp    29-Aug-2017 14.8 KiB  
  80. hidl.h  29-Aug-2017 8.2 KiB  
  81. hidl_constants.h    29-Aug-2017 578  
  82. hidl_i.h    29-Aug-2017 513  
  83. hidl_manager.cpp    29-Aug-2017 51.6 KiB  
  84. hidl_manager.h  29-Aug-2017 24.7 KiB  
  85. hidl_return_util.h  29-Aug-2017 3.2 KiB  
  86. iface_config_utils.cpp  29-Aug-2017 5.7 KiB  
  87. iface_config_utils.h    29-Aug-2017 1.8 KiB  
  88. misc_utils.h    29-Aug-2017 1.8 KiB  
  89. p2p_iface.cpp   29-Aug-2017 40 KiB  
  90. p2p_iface.h 29-Aug-2017 12.8 KiB  
  91. p2p_network.cpp 29-Aug-2017 7.3 KiB  
  92. p2p_network.h   29-Aug-2017 3.4 KiB  
  93. sta_iface.cpp   29-Aug-2017 30.7 KiB  
  94. sta_iface.h 29-Aug-2017 10 KiB  
  95. sta_network.cpp 29-Aug-2017 58.5 KiB  
  96. sta_network.h   29-Aug-2017 14.3 KiB  
  97. supplicant.cpp  29-Aug-2017 5.5 KiB  
  98. supplicant.h    29-Aug-2017 2.9 KiB  
  99.   
  100.   
  101.   
  102. /hardware/interfaces/wifi/1.0/  路径下定义了一些操作wifi硬件的hal接口  .hal  
  103. /hardware/interfaces/wifi/1.0/default/  实现了上述定义的接口   .c  .h  
  104.   
  105. /hardware/interfaces/wifi/1.0/  
  106. IWifi.hal   29-Aug-2017 4.1 KiB  
  107. IWifiApIface.hal    29-Aug-2017 1.9 KiB  
  108. IWifiChip.hal   29-Aug-2017 26.1 KiB  
  109. IWifiChipEventCallback.hal  29-Aug-2017 3.6 KiB  
  110. IWifiEventCallback.hal  29-Aug-2017 1.5 KiB  
  111. IWifiIface.hal  29-Aug-2017 1.4 KiB  
  112. IWifiNanIface.hal   29-Aug-2017 10.3 KiB  
  113. IWifiNanIfaceEventCallback.hal  29-Aug-2017 12.4 KiB  
  114. IWifiP2pIface.hal   29-Aug-2017 832  
  115. IWifiRttController.hal  29-Aug-2017 6.4 KiB  
  116. IWifiRttControllerEventCallback.hal 29-Aug-2017 990  
  117. IWifiStaIface.hal   29-Aug-2017 20.9 KiB  
  118. IWifiStaIfaceEventCallback.hal  29-Aug-2017 2.3 KiB  
  119. types.hal   29-Aug-2017 69.4 KiB  
  120.   
  121.   
  122.   
  123. /hardware/interfaces/wifi/1.0/default/   //实现上述.hal 文件定义的接口  
  124. hidl_callback_util.h    29-Aug-2017 3.6 KiB  
  125. hidl_return_util.h  29-Aug-2017 3.8 KiB  
  126. hidl_struct_util.cpp    29-Aug-2017 89.7 KiB  
  127. hidl_struct_util.h  29-Aug-2017 7 KiB  
  128. hidl_sync_util.cpp  29-Aug-2017 1.1 KiB  
  129. hidl_sync_util.h    29-Aug-2017 1.2 KiB  
  130. service.cpp 29-Aug-2017 1.4 KiB  
  131. THREADING.README    29-Aug-2017 1.9 KiB  
  132. wifi.cpp    29-Aug-2017 6.6 KiB  
  133. wifi.h  29-Aug-2017 2.6 KiB  
  134. wifi_ap_iface.cpp   29-Aug-2017 3.6 KiB  
  135. wifi_ap_iface.h 29-Aug-2017 2.2 KiB  
  136. wifi_chip.cpp   29-Aug-2017 33.1 KiB  
  137. wifi_chip.h 29-Aug-2017 9.2 KiB  
  138. wifi_feature_flags.h    29-Aug-2017 1.1 KiB  
  139. wifi_legacy_hal.cpp 29-Aug-2017 49.9 KiB  
  140. wifi_legacy_hal.h   29-Aug-2017 13.7 KiB  
  141. wifi_legacy_hal_stubs.cpp   29-Aug-2017 6.1 KiB  
  142. wifi_legacy_hal_stubs.h 29-Aug-2017 1.1 KiB  
  143. wifi_mode_controller.cpp    29-Aug-2017 2.3 KiB  
  144. wifi_mode_controller.h  29-Aug-2017 1.8 KiB  
  145. wifi_nan_iface.cpp  29-Aug-2017 29.6 KiB  
  146. wifi_nan_iface.h    29-Aug-2017 6.4 KiB  
  147. wifi_p2p_iface.cpp  29-Aug-2017 2.1 KiB  
  148. wifi_p2p_iface.h    29-Aug-2017 1.8 KiB  
  149. wifi_rtt_controller.cpp 29-Aug-2017 11.3 KiB  
  150. wifi_rtt_controller.h   29-Aug-2017 4.3 KiB  
  151. wifi_sta_iface.cpp  29-Aug-2017 24.5 KiB  
  152. wifi_sta_iface.h    29-Aug-2017 7 KiB  
  153. wifi_status_util.cpp    29-Aug-2017 3.5 KiB  
  154. wifi_status_util.h  29-Aug-2017 1.4 KiB  
  155.   
  156.   
  157.   
  158.   
  159.   
  160. ========================================================================================  
  161. /hardware/interfaces/wifi/supplicant/1.0/Android.bp  里面应该写了一些.hal 文件转为 .h 文件的方法  
  162.   
  163. // This file is autogenerated by hidl-gen. Do not edit manually.  
  164.   
  165. filegroup {  
  166.     name: "[email protected]_hal",  
  167.     srcs: [  
  168.         "types.hal",  
  169.         "ISupplicant.hal",  
  170.         "ISupplicantCallback.hal",  
  171.         "ISupplicantIface.hal",  
  172.         "ISupplicantNetwork.hal",  
  173.         "ISupplicantP2pIface.hal",  
  174.         "ISupplicantP2pIfaceCallback.hal",  
  175.         "ISupplicantP2pNetwork.hal",  
  176.         "ISupplicantP2pNetworkCallback.hal",  
  177.         "ISupplicantStaIface.hal",  
  178.         "ISupplicantStaIfaceCallback.hal",  
  179.         "ISupplicantStaNetwork.hal",  
  180.         "ISupplicantStaNetworkCallback.hal",  
  181.     ],  
  182. }  
  183.   
  184. genrule {  
  185.     name: "[email protected]_genc++",  
  186.     tools: ["hidl-gen"],  
  187.     cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport [email protected]",  
  188.     srcs: [  
  189.         ":[email protected]_hal",  
  190.     ],  
  191.     out: [  
  192.         "android/hardware/wifi/supplicant/1.0/types.cpp",  
  193.         "android/hardware/wifi/supplicant/1.0/SupplicantAll.cpp",  
  194.         "android/hardware/wifi/supplicant/1.0/SupplicantCallbackAll.cpp",  
  195.         "android/hardware/wifi/supplicant/1.0/SupplicantIfaceAll.cpp",  
  196.         "android/hardware/wifi/supplicant/1.0/SupplicantNetworkAll.cpp",  
  197.         "android/hardware/wifi/supplicant/1.0/SupplicantP2pIfaceAll.cpp",  
  198.         "android/hardware/wifi/supplicant/1.0/SupplicantP2pIfaceCallbackAll.cpp",  
  199.         "android/hardware/wifi/supplicant/1.0/SupplicantP2pNetworkAll.cpp",  
  200.         "android/hardware/wifi/supplicant/1.0/SupplicantP2pNetworkCallbackAll.cpp",  
  201.         "android/hardware/wifi/supplicant/1.0/SupplicantStaIfaceAll.cpp",  
  202.         "android/hardware/wifi/supplicant/1.0/SupplicantStaIfaceCallbackAll.cpp",  
  203.         "android/hardware/wifi/supplicant/1.0/SupplicantStaNetworkAll.cpp",  
  204.         "android/hardware/wifi/supplicant/1.0/SupplicantStaNetworkCallbackAll.cpp",  
  205.     ],  
  206. }  
  207.   
  208. genrule {  
  209.     name: "[email protected]_genc++_headers",  
  210.     tools: ["hidl-gen"],  
  211.     cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport [email protected]",  
  212.     srcs: [  
  213.         ":[email protected]_hal",  
  214.     ],  
  215.     out: [  
  216.         "android/hardware/wifi/supplicant/1.0/types.h",  
  217.         "android/hardware/wifi/supplicant/1.0/hwtypes.h",  
  218.         "android/hardware/wifi/supplicant/1.0/ISupplicant.h",  
  219.         "android/hardware/wifi/supplicant/1.0/IHwSupplicant.h",  
  220.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicant.h",  
  221.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicant.h",  
  222.         "android/hardware/wifi/supplicant/1.0/BsSupplicant.h",  
  223.         "android/hardware/wifi/supplicant/1.0/ISupplicantCallback.h",  
  224.         "android/hardware/wifi/supplicant/1.0/IHwSupplicantCallback.h",  
  225.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicantCallback.h",  
  226.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicantCallback.h",  
  227.         "android/hardware/wifi/supplicant/1.0/BsSupplicantCallback.h",  
  228.         "android/hardware/wifi/supplicant/1.0/ISupplicantIface.h",  
  229.         "android/hardware/wifi/supplicant/1.0/IHwSupplicantIface.h",  
  230.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicantIface.h",  
  231.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicantIface.h",  
  232.         "android/hardware/wifi/supplicant/1.0/BsSupplicantIface.h",  
  233.         "android/hardware/wifi/supplicant/1.0/ISupplicantNetwork.h",  
  234.         "android/hardware/wifi/supplicant/1.0/IHwSupplicantNetwork.h",  
  235.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicantNetwork.h",  
  236.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicantNetwork.h",  
  237.         "android/hardware/wifi/supplicant/1.0/BsSupplicantNetwork.h",  
  238.         "android/hardware/wifi/supplicant/1.0/ISupplicantP2pIface.h",  
  239.         "android/hardware/wifi/supplicant/1.0/IHwSupplicantP2pIface.h",  
  240.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicantP2pIface.h",  
  241.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicantP2pIface.h",  
  242.         "android/hardware/wifi/supplicant/1.0/BsSupplicantP2pIface.h",  
  243.         "android/hardware/wifi/supplicant/1.0/ISupplicantP2pIfaceCallback.h",  
  244.         "android/hardware/wifi/supplicant/1.0/IHwSupplicantP2pIfaceCallback.h",  
  245.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicantP2pIfaceCallback.h",  
  246.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicantP2pIfaceCallback.h",  
  247.         "android/hardware/wifi/supplicant/1.0/BsSupplicantP2pIfaceCallback.h",  
  248.         "android/hardware/wifi/supplicant/1.0/ISupplicantP2pNetwork.h",  
  249.         "android/hardware/wifi/supplicant/1.0/IHwSupplicantP2pNetwork.h",  
  250.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicantP2pNetwork.h",  
  251.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicantP2pNetwork.h",  
  252.         "android/hardware/wifi/supplicant/1.0/BsSupplicantP2pNetwork.h",  
  253.         "android/hardware/wifi/supplicant/1.0/ISupplicantP2pNetworkCallback.h",  
  254.         "android/hardware/wifi/supplicant/1.0/IHwSupplicantP2pNetworkCallback.h",  
  255.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicantP2pNetworkCallback.h",  
  256.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicantP2pNetworkCallback.h",  
  257.         "android/hardware/wifi/supplicant/1.0/BsSupplicantP2pNetworkCallback.h",  
  258.         "android/hardware/wifi/supplicant/1.0/ISupplicantStaIface.h",  
  259.         "android/hardware/wifi/supplicant/1.0/IHwSupplicantStaIface.h",  
  260.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicantStaIface.h",  
  261.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicantStaIface.h",  
  262.         "android/hardware/wifi/supplicant/1.0/BsSupplicantStaIface.h",  
  263.         "android/hardware/wifi/supplicant/1.0/ISupplicantStaIfaceCallback.h",  
  264.         "android/hardware/wifi/supplicant/1.0/IHwSupplicantStaIfaceCallback.h",  
  265.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicantStaIfaceCallback.h",  
  266.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicantStaIfaceCallback.h",  
  267.         "android/hardware/wifi/supplicant/1.0/BsSupplicantStaIfaceCallback.h",  
  268.         "android/hardware/wifi/supplicant/1.0/ISupplicantStaNetwork.h",  
  269.         "android/hardware/wifi/supplicant/1.0/IHwSupplicantStaNetwork.h",  
  270.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicantStaNetwork.h",  
  271.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicantStaNetwork.h",  
  272.         "android/hardware/wifi/supplicant/1.0/BsSupplicantStaNetwork.h",  
  273.         "android/hardware/wifi/supplicant/1.0/ISupplicantStaNetworkCallback.h",  
  274.         "android/hardware/wifi/supplicant/1.0/IHwSupplicantStaNetworkCallback.h",  
  275.         "android/hardware/wifi/supplicant/1.0/BnHwSupplicantStaNetworkCallback.h",  
  276.         "android/hardware/wifi/supplicant/1.0/BpHwSupplicantStaNetworkCallback.h",  
  277.         "android/hardware/wifi/supplicant/1.0/BsSupplicantStaNetworkCallback.h",  
  278.     ],  
  279. }  
  280.   
  281. cc_library_shared {  
  282.     name: "[email protected]",  
  283.     defaults: ["hidl-module-defaults"],  
  284.     generated_sources: ["[email protected]_genc++"],  
  285.     generated_headers: ["[email protected]_genc++_headers"],  
  286.     export_generated_headers: ["[email protected]_genc++_headers"],  
  287.     vendor_available: true,  
  288.     shared_libs: [  
  289.         "libhidlbase",  
  290.         "libhidltransport",  
  291.         "libhwbinder",  
  292.         "liblog",  
  293.         "libutils",  
  294.         "libcutils",  
  295.         "[email protected]",  
  296.     ],  
  297.     export_shared_lib_headers: [  
  298.         "libhidlbase",  
  299.         "libhidltransport",  
  300.         "libhwbinder",  
  301.         "libutils",  
  302.         "[email protected]",  
  303.     ],  
  304. }  
  305. ========================================================================================  
  306. /hardware/interfaces/wifi/1.0/default/[email protected]  
  307. service wifi_hal_legacy /vendor/bin/hw/[email protected]  
  308.     class hal  
  309.     user wifi  
  310.     group wifi gps  
  311.   
  312. =================================================================================  
  313.   
  314.   
  315. ##############################################  
  316. # android8.0 安卓8.0 定义的hal的接口文件  
  317. # Do not change this file except to add new interfaces. Changing  
  318. # pre-existing interfaces will fail VTS and break framework-only OTAs  
  319.   
  320. # HALs released in Android O  
  321.   
  322. [email protected]::IDevice  
  323. [email protected]::IDevicesFactory  
  324. [email protected]::IPrimaryDevice  
  325. [email protected]::IStream  
  326. [email protected]::IStreamIn  
  327. [email protected]::IStreamOut  
  328. [email protected]::IStreamOutCallback  
  329. [email protected]::types  
  330. [email protected]::types  
  331. [email protected]::IAcousticEchoCancelerEffect  
  332. [email protected]::IAutomaticGainControlEffect  
  333. [email protected]::IBassBoostEffect  
  334. [email protected]::IDownmixEffect  
  335. [email protected]::IEffect  
  336. [email protected]::IEffectBufferProviderCallback  
  337. [email protected]::IEffectsFactory  
  338. [email protected]::IEnvironmentalReverbEffect  
  339. [email protected]::IEqualizerEffect  
  340. [email protected]::ILoudnessEnhancerEffect  
  341. [email protected]::INoiseSuppressionEffect  
  342. [email protected]::IPresetReverbEffect  
  343. [email protected]::IVirtualizerEffect  
  344. [email protected]::IVisualizerEffect  
  345. [email protected]::types  
  346. [email protected]::IEvsCamera  
  347. [email protected]::IEvsCameraStream  
  348. [email protected]::IEvsDisplay  
  349. [email protected]::IEvsEnumerator  
  350. [email protected]::types  
  351. [email protected]::IVehicle  
  352. [email protected]::IVehicleCallback  
  353. [email protected]::types  
  354. [email protected]::IBiometricsFingerprint  
  355. [email protected]::IBiometricsFingerprintClientCallback  
  356. [email protected]::types  
  357. [email protected]::IBluetoothHci  
  358. [email protected]::IBluetoothHciCallbacks  
  359. [email protected]::types  
  360. [email protected]::IBootControl  
  361. [email protected]::types  
  362. [email protected]::IBroadcastRadio  
  363. [email protected]::IBroadcastRadioFactory  
  364. [email protected]::ITuner  
  365. [email protected]::ITunerCallback  
  366. [email protected]::types  
  367. [email protected]::types  
  368. [email protected]::ICameraDevice  
  369. [email protected]::ICameraDeviceCallback  
  370. [email protected]::ICameraDevicePreviewCallback  
  371. [email protected]::types  
  372. [email protected]::ICameraDevice  
  373. [email protected]::ICameraDeviceCallback  
  374. [email protected]::ICameraDeviceSession  
  375. [email protected]::types  
  376. [email protected]::types  
  377. [email protected]::ICameraProvider  
  378. [email protected]::ICameraProviderCallback  
  379. [email protected]::ISurfaceFlingerConfigs  
  380. [email protected]::types  
  381. [email protected]::IContexthub  
  382. [email protected]::IContexthubCallback  
  383. [email protected]::types  
  384. [email protected]::ICryptoFactory  
  385. [email protected]::ICryptoPlugin  
  386. [email protected]::IDrmFactory  
  387. [email protected]::IDrmPlugin  
  388. [email protected]::IDrmPluginListener  
  389. [email protected]::types  
  390. [email protected]::IDumpstateDevice  
  391. [email protected]::IGatekeeper  
  392. [email protected]::types  
  393. [email protected]::IAGnss  
  394. [email protected]::IAGnssCallback  
  395. [email protected]::IAGnssRil  
  396. [email protected]::IAGnssRilCallback  
  397. [email protected]::IGnss  
  398. [email protected]::IGnssBatching  
  399. [email protected]::IGnssBatchingCallback  
  400. [email protected]::IGnssCallback  
  401. [email protected]::IGnssConfiguration  
  402. [email protected]::IGnssDebug  
  403. [email protected]::IGnssGeofenceCallback  
  404. [email protected]::IGnssGeofencing  
  405. [email protected]::IGnssMeasurement  
  406. [email protected]::IGnssMeasurementCallback  
  407. [email protected]::IGnssNavigationMessage  
  408. [email protected]::IGnssNavigationMessageCallback  
  409. [email protected]::IGnssNi  
  410. [email protected]::IGnssNiCallback  
  411. [email protected]::IGnssXtra  
  412. [email protected]::IGnssXtraCallback  
  413. [email protected]::types  
  414. [email protected]::IAllocator  
  415. [email protected]::IGraphicBufferProducer  
  416. [email protected]::IProducerListener  
  417. [email protected]::types  
  418. [email protected]::IComposer  
  419. [email protected]::IComposerCallback  
  420. [email protected]::IComposerClient  
  421. [email protected]::types  
  422. [email protected]::IMapper  
  423. [email protected]::types  
  424. [email protected]::IHealth  
  425. [email protected]::types  
  426. [email protected]::IConsumerIr  
  427. [email protected]::types  
  428. [email protected]::IKeymasterDevice  
  429. [email protected]::types  
  430. [email protected]::ILight  
  431. [email protected]::types  
  432. [email protected]::types  
  433. [email protected]::IGraphicBufferSource  
  434. [email protected]::IOmx  
  435. [email protected]::IOmxBufferSource  
  436. [email protected]::IOmxNode  
  437. [email protected]::IOmxObserver  
  438. [email protected]::IOmxStore  
  439. [email protected]::types  
  440. [email protected]::IMemtrack  
  441. [email protected]::types  
  442. [email protected]::INfc  
  443. [email protected]::INfcClientCallback  
  444. [email protected]::types  
  445. [email protected]::IPower  
  446. [email protected]::types  
  447. [email protected]::IRadio  
  448. [email protected]::IRadioIndication  
  449. [email protected]::IRadioResponse  
  450. [email protected]::ISap  
  451. [email protected]::ISapCallback  
  452. [email protected]::types  
  453. android.hardware.radio.deprecated@1.0::IOemHook  
  454. android.hardware.radio.deprecated@1.0::IOemHookIndication  
  455. android.hardware.radio.deprecated@1.0::IOemHookResponse  
  456. [email protected]::IContext  
  457. [email protected]::IDevice  
  458. [email protected]::types  
  459. [email protected]::ISensors  
  460. [email protected]::types  
  461. [email protected]::ISoundTriggerHw  
  462. [email protected]::ISoundTriggerHwCallback  
  463. [email protected]::types  
  464. [email protected]::IThermal  
  465. [email protected]::types  
  466. [email protected]::IHdmiCec  
  467. [email protected]::IHdmiCecCallback  
  468. [email protected]::types  
  469. [email protected]::ITvInput  
  470. [email protected]::ITvInputCallback  
  471. [email protected]::types  
  472. [email protected]::IUsb  
  473. [email protected]::IUsbCallback  
  474. [email protected]::types  
  475. [email protected]::IVibrator  
  476. [email protected]::types  
  477. [email protected]::IVr  
  478. [email protected]::IWifi  
  479. [email protected]::IWifiApIface  
  480. [email protected]::IWifiChip  
  481. [email protected]::IWifiChipEventCallback  
  482. [email protected]::IWifiEventCallback  
  483. [email protected]::IWifiIface  
  484. [email protected]::IWifiNanIface  
  485. [email protected]::IWifiNanIfaceEventCallback  
  486. [email protected]::IWifiP2pIface  
  487. [email protected]::IWifiRttController  
  488. [email protected]::IWifiRttControllerEventCallback  
  489. [email protected]::IWifiStaIface  
  490. [email protected]::IWifiStaIfaceEventCallback  
  491. [email protected]::types  
  492. [email protected]::ISupplicant  
  493. [email protected]::ISupplicantCallback  
  494. [email protected]::ISupplicantIface  
  495. [email protected]::ISupplicantNetwork  
  496. [email protected]::ISupplicantP2pIface  
  497. [email protected]::ISupplicantP2pIfaceCallback  
  498. [email protected]::ISupplicantP2pNetwork  
  499. [email protected]::ISupplicantP2pNetworkCallback  
  500. [email protected]::ISupplicantStaIface  
  501. [email protected]::ISupplicantStaIfaceCallback  
  502. [email protected]::ISupplicantStaNetwork  
  503. [email protected]::ISupplicantStaNetworkCallback  
  504. [email protected]::types  
  505. ##############################################  




[cpp]  view plain  copy
  1. ===============================wificond的一些分析(安卓8.0才开始出现)↓======================  
  2. //system/connectivity/wificond/aidl/android/net/wifi/IWificond.aidl  
  3. // Service interface that exposes primitives for controlling the WiFi  
  4. // subsystems of a device.  
  5. interface IWificond {  
  6.   
  7.     @nullable IApInterface createApInterface();  
  8.     @nullable IClientInterface createClientInterface();  
  9.     void tearDownInterfaces();  
  10.   
  11. }  
  12.   
  13.   
  14. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiInjector.java  
  15.     public IWificond makeWificond() {  
  16.         // We depend on being able to refresh our binder in WifiStateMachine, so don't cache it.  
  17.         IBinder binder = ServiceManager.getService(WIFICOND_SERVICE_NAME【"wificond"】);  
  18.         return IWificond.Stub.asInterface(binder);  
  19.     }  
  20.       
  21.   
  22. adb shell  service list | findstr wifi  
  23. 59      wifip2p: [android.net.wifi.p2p.IWifiP2pManager]  
  24. 60      rttmanager: [android.net.wifi.IRttManager]  
  25. 61      wifiscanner: [android.net.wifi.IWifiScanner]  
  26. 62      wifi: [android.net.wifi.IWifiManager]  
  27. 125     wificond: []     // 没有具体的内容  只知道是系统的后台运行服务service   
  28.   
  29.   
  30. ============================================  
  31. /system/sepolicy/private/wificond.te  
  32.   
  33.   
  34. typeattribute wificond coredomain;  
  35. init_daemon_domain(wificond)  
  36. hal_client_domain(wificond, hal_wifi_offload)  
  37.   
  38.   
  39. ============================================  
  40. /system/sepolicy/public/wificond.te  
  41.   
  42. # wificond  
  43. type wificond, domain;  
  44. type wificond_exec, exec_type, file_type;  
  45.   
  46. binder_use(wificond)  
  47. binder_call(wificond, system_server)  
  48.   
  49. add_service(wificond, wificond_service)  
  50.   
  51. set_prop(wificond, wifi_prop)  
  52. set_prop(wificond, ctl_default_prop)  
  53.   
  54. # create sockets to set interfaces up and down  
  55. allow wificond self:udp_socket create_socket_perms;  
  56. # setting interface state up/down is a privileged ioctl  
  57. allowxperm wificond self:udp_socket ioctl { SIOCSIFFLAGS };  
  58. allow wificond self:capability { net_admin net_raw };  
  59. # allow wificond to speak to nl80211 in the kernel  
  60. allow wificond self:netlink_socket create_socket_perms_no_ioctl;  
  61. # newer kernels (e.g. 4.4 but not 4.1) have a new class for sockets  
  62. allow wificond self:netlink_generic_socket create_socket_perms_no_ioctl;  
  63.   
  64. r_dir_file(wificond, proc_net)  
  65.   
  66. # wificond writes out configuration files for wpa_supplicant/hostapd.  
  67. # wificond also reads pid files out of this directory  
  68. allow wificond wifi_data_file:dir rw_dir_perms;  
  69. allow wificond wifi_data_file:file create_file_perms;  
  70.   
  71. # allow wificond to check permission for dumping logs  
  72. allow wificond permission_service:service_manager find;  
  73.   
  74. # dumpstate support  
  75. allow wificond dumpstate:fd use;  
  76. allow wificond dumpstate:fifo_file write;  
  77. ============================================  
  78. /system/connectivity/wificond/wificond.rc  
  79. service wificond /system/bin/wificond  
  80.     class main  
  81.     user wifi  
  82.     group wifi net_raw net_admin  
  83. ============================================  
  84.   
  85. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WificondControl.java  
  86.   
  87.   
  88. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative.java  
  89.     /** 
  90.     * Disable wpa_supplicant via wificond.  关闭wpa_supplicant通过 wificond 
  91.     * @return Returns true on success. 
  92.     */  
  93.     public boolean disableSupplicant() {  
  94.         return mWificondControl.disableSupplicant();  
  95.     }  
  96.   
  97.     /** 
  98.     * Enable wpa_supplicant via wificond.   打开wpa_supplicant通过 wificond 
  99.     * @return Returns true on success. 
  100.     */  
  101.     public boolean enableSupplicant() {  
  102.         return mWificondControl.enableSupplicant();  
  103.     }  
  104. ===============================wificond的一些分析(安卓8.0才开始出现)↑======================  

[cpp]  view plain  copy
  1. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiNative.java    
  2.     /**  
  3.     * Disable wpa_supplicant via wificond.  关闭wpa_supplicant通过 wificond  
  4.     * @return Returns true on success.  
  5.     */    
  6.     public boolean disableSupplicant() {    
  7.         return mWificondControl.disableSupplicant();    
  8.     }    
  9.     
  10.     /**  
  11.     * Enable wpa_supplicant via wificond.   打开wpa_supplicant通过 wificond  
  12.     * @return Returns true on success.  
  13.     */    
  14.     public boolean enableSupplicant() {    
  15.         return mWificondControl.enableSupplicant();    
  16.     }    
  17.   
  18.       
  19.       
  20. =========================WifiInjector↓================================  
  21. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiInjector.java  
  22. public class WifiInjector {  
  23.   
  24.   
  25.   
  26. private final WificondControl mWificondControl;   
  27.   
  28. public WifiInjector(Context context) {  
  29.   
  30. mWifiMonitor = new WifiMonitor(this);  
  31. mHalDeviceManager = new HalDeviceManager();  // 这个类是什么?  
  32.   
  33. // IWifiVendor.Hal  文件?     ISupplicantStaIface.Hal 文件  
  34. mWifiVendorHal =new WifiVendorHal(mHalDeviceManager, mWifiStateMachineHandlerThread.getLooper());  
  35.   
  36. mSupplicantStaIfaceHal = new SupplicantStaIfaceHal(mContext, mWifiMonitor);  
  37.   
  38. mWificondControl = new WificondControl(this, mWifiMonitor);  
  39.   
  40.   
  41. mWifiNative = new WifiNative(SystemProperties.get("wifi.interface""wlan0"),mWifiVendorHal, mSupplicantStaIfaceHal, mWificondControl);  
  42.   
  43. //----------------------P2P相关--------------------------  
  44.   
  45. mWifiP2pMonitor = new WifiP2pMonitor(this);  
  46. mSupplicantP2pIfaceHal = new SupplicantP2pIfaceHal(mWifiP2pMonitor);  
  47. mWifiP2pNative = new  WifiP2pNative(SystemProperties.get("wifi.direct.interface","p2p0"),mSupplicantP2pIfaceHal);  
  48.   
  49.   
  50.   
  51. //依赖 handlerThread 的对象   Now get instances of all the objects that depend on the HandlerThreads  
  52. mTrafficPoller =  new WifiTrafficPoller(mContext,mWifiServiceHandlerThread.getLooper(),mWifiNative.getInterfaceName());  
  53. mCountryCode = new WifiCountryCode(mWifiNative,SystemProperties.get(BOOT_DEFAULT_WIFI_COUNTRY_CODE),  
  54. mContext.getResources().getBoolean(R.bool.config_wifi_revert_country_code_on_cellular_loss));  
  55. mWifiApConfigStore = new WifiApConfigStore(mContext, mBackupManagerProxy);  
  56.   
  57. }  
  58. private static final String BOOT_DEFAULT_WIFI_COUNTRY_CODE = "ro.boot.wificountrycode";  
  59. =========================WifiInjector↑================================  
  60.   
  61.   
  62. =========================WifiMonitor 的作用==================  
  63. 【 WifiMonitor 的作用:】监听来自 wpa_supplicant的事件,不请自来的事件,相当于attach函数被调用  
  64. Listens for events from the wpa_supplicant server, and passes them on  
  65. to the {@link StateMachine} for handling.  
  66. 主要就是包含了两个MAP     
  67. 一个Map mHandlerMap 保存  (key=接口名字,value=需要处理事件的handler集合)  
  68. 一个map mMonitoringMap 用于保存当前的  ( key=接口名字,value=是否监听对应事件 Boolean )  
  69. private final Map<String, SparseArray<Set<Handler>>> mHandlerMap = new HashMap<>();  
  70. private final Map<String, Boolean> mMonitoringMap = new HashMap<>();  
  71.   
  72.   
  73.   
  74.   
  75.     // TODO(b/27569474) remove support for multiple handlers for the same event  
  76.     private final Map<String, SparseArray<Set<Handler>>> mHandlerMap = new HashMap<>();  
  77.       
  78.     // registerHandler 是在WifiMonitor注册监听函数,需要两个key 一个 iface 和 what  
  79.     // 这样能统一找到对某一事件感兴趣的 handler集合  
  80.     public synchronized void registerHandler(String iface, int what, Handler handler) {  
  81.         SparseArray<Set<Handler>> ifaceHandlers = mHandlerMap.get(iface);  
  82.         if (ifaceHandlers == null) {  
  83.             ifaceHandlers = new SparseArray<>();  
  84.             mHandlerMap.put(iface, ifaceHandlers);  
  85.         }  
  86.         Set<Handler> ifaceWhatHandlers = ifaceHandlers.get(what);  
  87.         if (ifaceWhatHandlers == null) {  
  88.             ifaceWhatHandlers = new ArraySet<>();  
  89.             ifaceHandlers.put(what, ifaceWhatHandlers);  
  90.         }  
  91.         ifaceWhatHandlers.add(handler);  
  92.     }  
  93.   
  94.       
  95.   
  96.   
  97.   
  98.     /**开始监听 
  99.      * Start Monitoring for wpa_supplicant events. 
  100.      * 
  101.      * @param iface Name of iface. 
  102.      * TODO: Add unit tests for these once we remove the legacy code. 
  103.      */  
  104.     public synchronized void startMonitoring(String iface, boolean isStaIface) {  
  105.         if (ensureConnectedLocked()) {  // 从WifiNative 得到Supplicant 连接的状态    
  106.             setMonitoring(iface, true);  
  107.             broadcastSupplicantConnectionEvent(iface); // 发送连接事件   
  108.         } else {  
  109.             boolean originalMonitoring = isMonitoring(iface);  
  110.             setMonitoring(iface, true);  
  111.             broadcastSupplicantDisconnectionEvent(iface);  
  112.             setMonitoring(iface, originalMonitoring);  
  113.             Log.e(TAG, "startMonitoring(" + iface + ") failed!");  
  114.         }  
  115.     }  
  116.   
  117.     /**断开监听 
  118.      * Stop Monitoring for wpa_supplicant events. 
  119.      * 
  120.      * @param iface Name of iface. 
  121.      * TODO: Add unit tests for these once we remove the legacy code. 
  122.      */  
  123.     public synchronized void stopMonitoring(String iface) {  
  124.         if (mVerboseLoggingEnabled) Log.d(TAG, "stopMonitoring(" + iface + ")");  
  125.         setMonitoring(iface, true);  
  126.         broadcastSupplicantDisconnectionEvent(iface);  
  127.         setMonitoring(iface, false);  
  128.     }  
  129.   
  130. /* Connection to supplicant established */  
  131.     private static final int BASE = Protocol.BASE_WIFI_MONITOR;//0x00024000  
  132.     public static final int SUP_CONNECTION_EVENT                 = BASE + 1  
  133.   
  134.     public void broadcastSupplicantConnectionEvent(String iface) { // 发送给handler已经开始监听的Message  
  135.         sendMessage(iface, SUP_CONNECTION_EVENT);  
  136.     }  
  137.       
  138. private void sendMessage(String iface, int what) {  
  139.     sendMessage(iface, Message.obtain(null, what)); // 封装为Message  
  140. }  
  141.   
  142.   
  143.   private void sendMessage(String iface, Message message) {  
  144.  // 通过iface拿到 那些对该接口注册了处理函数的handler集合  
  145.         SparseArray<Set<Handler>> ifaceHandlers = mHandlerMap.get(iface);   
  146.         if (iface != null && ifaceHandlers != null) {  
  147.             if (isMonitoring(iface)) {  
  148.  // 通过message.what拿到 那些对该接口注册了处理函数的handler集合 中找对message有处理函数的 handler集合  
  149.                 Set<Handler> ifaceWhatHandlers = ifaceHandlers.get(message.what);  
  150.                 if (ifaceWhatHandlers != null) {  
  151.                     for (Handler handler : ifaceWhatHandlers) {  
  152.                         if (handler != null) {  
  153.   // 往这些handler 中发送对应的这个消息  
  154.                             sendMessage(handler, Message.obtain(message));  
  155.                         }  
  156.                     }  
  157.                 }  
  158.             } else {  
  159.                 if (mVerboseLoggingEnabled) {  
  160.                     Log.d(TAG, "Dropping event because (" + iface + ") is stopped");  
  161.                 }  
  162.             }  
  163.         } else {  
  164.             if (mVerboseLoggingEnabled) {  
  165.                 Log.d(TAG, "Sending to all monitors because there's no matching iface");  
  166.             }  
  167.             for (Map.Entry<String, SparseArray<Set<Handler>>> entry : mHandlerMap.entrySet()) {  
  168.                 if (isMonitoring(entry.getKey())) {  
  169.                     Set<Handler> ifaceWhatHandlers = entry.getValue().get(message.what);  
  170.                     for (Handler handler : ifaceWhatHandlers) {  
  171.                         if (handler != null) {  
  172.                             sendMessage(handler, Message.obtain(message));  
  173.                         }  
  174.                     }  
  175.                 }  
  176.             }  
  177.         }  
  178.   
  179.         message.recycle();  
  180.     }  
  181.   
  182.     private void sendMessage(Handler handler, Message message) {  
  183.         message.setTarget(handler);  
  184.         message.sendToTarget();  // 发送给对应的handler 去处理  这个消息  
  185.     }  
  186.   
  187.   
  188. WifiMonitor提供如下函数供 类 /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WificondControl.java 调用  
  189. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java调用  
  190. 最终会调用到 sendMessage(String iface, Message message)  sendMessage(Handler handler, Message message)  
  191.   
  192. broadcastAnqpDoneEvent(String iface, AnqpEvent anqpEvent) {  
  193. sendMessage(iface, ANQP_DONE_EVENT, anqpEvent);  
  194. }  
  195.   
  196.   
  197. public void broadcastAssociatedBssidEvent(String iface, String bssid) {  
  198. sendMessage(iface, WifiStateMachine.CMD_ASSOCIATED_BSSID, 0, 0, bssid);  
  199. }  
  200.   
  201. public void broadcastAssociationRejectionEvent(String iface, int status, boolean timedOut,String bssid) {  
  202. sendMessage(iface, ASSOCIATION_REJECTION_EVENT, timedOut ? 1 : 0, status, bssid);  
  203. }  
  204.   
  205. public void broadcastAuthenticationFailureEvent(String iface, int reason) {  
  206. sendMessage(iface, AUTHENTICATION_FAILURE_EVENT, 0, reason);  
  207. }  
  208.   
  209. public void broadcastIconDoneEvent(String iface, IconEvent iconEvent) {  
  210. sendMessage(iface, RX_HS20_ANQP_ICON_EVENT, iconEvent);  
  211. }  
  212.   
  213. public void broadcastNetworkConnectionEvent(String iface, int networkId, String bssid) {  
  214. sendMessage(iface, NETWORK_CONNECTION_EVENT, networkId, 0, bssid);  
  215. }  
  216.   
  217.   
  218. public void broadcastNetworkDisconnectionEvent(String iface, int local, int reason,String bssid) {  
  219. sendMessage(iface, NETWORK_DISCONNECTION_EVENT, local, reason, bssid);  
  220. }  
  221.   
  222. public void broadcastNetworkGsmAuthRequestEvent(String iface, int networkId, String ssid,String[] data) {  
  223. sendMessage(iface, SUP_REQUEST_SIM_AUTH,new SimAuthRequestData(networkId, WifiEnterpriseConfig.Eap.SIM, ssid, data));  
  224. }  
  225.   
  226.   
  227. public void broadcastNetworkIdentityRequestEvent(String iface, int networkId, String ssid) {  
  228. sendMessage(iface, SUP_REQUEST_IDENTITY, 0, networkId, ssid);  
  229. }  
  230.   
  231. public void broadcastNetworkUmtsAuthRequestEvent(String iface, int networkId, String ssid,String[] data) {  
  232. sendMessage(iface, SUP_REQUEST_SIM_AUTH,  
  233. new SimAuthRequestData(networkId, WifiEnterpriseConfig.Eap.AKA, ssid, data));  
  234. }  
  235.   
  236. public void broadcastPnoScanResultEvent(String iface) {  
  237. sendMessage(iface, PNO_SCAN_RESULTS_EVENT);  
  238. }  
  239. public void broadcastScanFailedEvent(String iface) {  
  240. sendMessage(iface, SCAN_FAILED_EVENT);  
  241. }  
  242. public void broadcastScanResultEvent(String iface) {  // 【扫描结果】  
  243. sendMessage(iface, SCAN_RESULTS_EVENT);  
  244. }   
  245. public void broadcastSupplicantConnectionEvent(String iface) {  
  246. sendMessage(iface, SUP_CONNECTION_EVENT);  
  247. }  
  248. public void broadcastSupplicantDisconnectionEvent(String iface) {  
  249. sendMessage(iface, SUP_DISCONNECTION_EVENT);  
  250. }  
  251. public void broadcastSupplicantStateChangeEvent(String iface, int networkId, WifiSsid wifiSsid,  
  252. String bssid,SupplicantState newSupplicantState) {  
  253. sendMessage(iface, SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,  
  254. new StateChangeResult(networkId, wifiSsid, bssid, newSupplicantState));  
  255. }  
  256.   
  257.   
  258. public void broadcastTargetBssidEvent(String iface, String bssid) {  
  259. sendMessage(iface, WifiStateMachine.CMD_TARGET_BSSID, 0, 0, bssid);  
  260. }  
  261.   
  262. public void broadcastWnmEvent(String iface, WnmData wnmData) {  
  263. sendMessage(iface, HS20_REMEDIATION_EVENT, wnmData);  
  264. }  
  265.   
  266.   
  267. public void broadcastWpsFailEvent(String iface, int cfgError, int vendorErrorCode) {  
  268. int reason = 0;  
  269. switch(vendorErrorCode) {  
  270. case REASON_TKIP_ONLY_PROHIBITED:  
  271. sendMessage(iface, WPS_FAIL_EVENT, WifiManager.WPS_TKIP_ONLY_PROHIBITED);  
  272. return;  
  273. case REASON_WEP_PROHIBITED:  
  274. sendMessage(iface, WPS_FAIL_EVENT, WifiManager.WPS_WEP_PROHIBITED);  
  275. return;  
  276. default:  
  277. reason = vendorErrorCode;  
  278. break;  
  279. }  
  280. switch(cfgError) {  
  281. case CONFIG_AUTH_FAILURE:  
  282. sendMessage(iface, WPS_FAIL_EVENT, WifiManager.WPS_AUTH_FAILURE);  
  283. return;  
  284. case CONFIG_MULTIPLE_PBC_DETECTED:  
  285. sendMessage(iface, WPS_FAIL_EVENT, WifiManager.WPS_OVERLAP_ERROR);  
  286. return;  
  287. default:  
  288. if (reason == 0) {  
  289. reason = cfgError;  
  290. }  
  291. break;  
  292. }  
  293. //For all other errors, return a generic internal error  
  294. sendMessage(iface, WPS_FAIL_EVENT, WifiManager.ERROR, reason);  
  295. }  
  296.   
  297. public void broadcastWpsOverlapEvent(String iface) {  
  298. sendMessage(iface, WPS_OVERLAP_EVENT);  
  299. }  
  300. public void broadcastWpsSuccessEvent(String iface) {  
  301. sendMessage(iface, WPS_SUCCESS_EVENT);  
  302. }  
  303.   
  304. public void broadcastWpsTimeoutEvent(String iface) {  
  305. sendMessage(iface, WPS_TIMEOUT_EVENT);  
  306. }  
  307.   
  308.   
  309.   
  310. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/WificondControl.java 调用  
  311. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java调用  
  312.   
  313. broadcastAnqpDoneEvent   WificondControl.java 调用  
  314. broadcastAssociatedBssidEvent   SupplicantStaIfaceHal.java调用  
  315. broadcastAssociationRejectionEvent  SupplicantStaIfaceHal.java调用  
  316. broadcastAuthenticationFailureEvent    SupplicantStaIfaceHal.java调用  
  317. broadcastIconDoneEvent   SupplicantStaIfaceHal.java调用   
  318. broadcastNetworkConnectionEvent    SupplicantStaIfaceHal.java调用  
  319. broadcastNetworkDisconnectionEvent   SupplicantStaIfaceHal.java调用  
  320. broadcastNetworkGsmAuthRequestEvent    SupplicantStaIfaceHal.java调用  
  321. broadcastNetworkIdentityRequestEvent        SupplicantStaIfaceHal.java调用    
  322. broadcastNetworkUmtsAuthRequestEvent  SupplicantStaIfaceHal.java调用  
  323. broadcastPnoScanResultEvent     SupplicantStaIfaceHal.java调用  
  324. broadcastScanFailedEvent      SupplicantStaIfaceHal.java调用  
  325. broadcastScanResultEvent         WificondControl.java 调用   
  326. broadcastSupplicantConnectionEvent  
  327. broadcastSupplicantDisconnectionEvent  
  328. broadcastSupplicantStateChangeEvent  
  329. broadcastTargetBssidEvent  
  330. broadcastWnmEvent  
  331. broadcastWpsFailEvent  
  332. broadcastWpsOverlapEvent  
  333. broadcastWpsSuccessEvent  
  334. broadcastWpsTimeoutEvent  
  335.   
  336.   
  337. ISupplicantStaIfaceCallback.Stub 和文件 ISupplicantStaIfaceCallback.hal 关系怎样?   
  338. /frameworks/opt/net/wifi/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java  
  339.  private class SupplicantStaIfaceHalCallback extends ISupplicantStaIfaceCallback.Stub {  
  340. 定义了下列函数,下列函数应该是一些回调函数  被谁回调呢?  
  341. onAnqpQueryDone                ()  
  342. onAssociationRejected          ()  
  343. public void onAuthenticationTimeout( byte [/* 6 */] bssid)  
  344. onBssidChanged                 ()  
  345. onDisconnected                 ()  
  346. onEapFailure                   ()  
  347. onExtRadioWorkStart            ()  
  348. onExtRadioWorkTimeout          ()  
  349. onHs20DeauthImminentNotice     ()  
  350. onHs20IconQueryDone            ()  
  351. onHs20SubscriptionRemediation  ()  
  352. onNetworkAdded                 ()  
  353. onNetworkRemoved               ()  
  354. onStateChanged                 ()  
  355. onWpsEventFail                 ()  
  356. onWpsEventPbcOverlap           ()  
  357. onWpsEventSuccess              ()  
  358.  }  
  359.    
  360.    
  361. /external/wpa_supplicant_8/wpa_supplicant/hidl/1.0/hidl_manager.cpp    
  362.  void HidlManager::notifyAuthTimeout(struct wpa_supplicant *wpa_s)  
  363. {  
  364. if (!wpa_s)  
  365. return;  
  366.   
  367. const std::string ifname(wpa_s->ifname);  
  368. if (sta_iface_object_map_.find(ifname) == sta_iface_object_map_.end())  
  369. return;  
  370.   
  371. const u8 *bssid = wpa_s->bssid;  
  372. if (is_zero_ether_addr(bssid)) {  
  373. bssid = wpa_s->pending_bssid;  
  374. }  
  375. callWithEachStaIfaceCallback(  
  376. wpa_s->ifname,  
  377. std::bind(  
  378. &ISupplicantStaIfaceCallback::onAuthenticationTimeout, // 难道是在这里被回调?? Fuck Understand!!  
  379. std::placeholders::_1, bssid));  
  380. }  
  381.   
  382.   
  383.     callWithEachStaIfaceCallback(  
  384.         wpa_s->ifname, std::bind(  
  385.                    &ISupplicantStaIfaceCallback::onAnqpQueryDone,  
  386.                    std::placeholders::_1, bssid, hidl_anqp_data,  
  387.                    hidl_hs20_anqp_data));  
  388.   
  389.                      
  390.                      
  391. void HidlManager::callWithEachStaIfaceCallback(  
  392.     const std::string &ifname,  
  393.     const std::function<Return<void>(android::sp<ISupplicantStaIfaceCallback>)> &method)  
  394. {  
  395.     callWithEachIfaceCallback(ifname, method, sta_iface_callbacks_map_);  
  396. }  
  397.   
  398.   
  399.   
  400. template <class CallbackType>   // 把CallbackType 当做一个类  这个类是方法&method的执行类   
  401. void callWithEachIfaceCallback(  
  402.     const std::string &ifname,  
  403.     const std::function<android::hardware::Return<void>(android::sp<CallbackType>)> &method,  
  404.     const std::map<const std::string, std::vector<android::sp<CallbackType>>> &callbacks_map)  
  405. {  
  406.     if (ifname.empty())  
  407.         return;  
  408.   
  409.     auto iface_callback_map_iter = callbacks_map.find(ifname);  
  410.     if (iface_callback_map_iter == callbacks_map.end())  
  411.         return;  
  412.     const auto &iface_callback_list = iface_callback_map_iter->second;  
  413.     for (const auto &callback : iface_callback_list) {  
  414.         if (!method(callback).isOk()) {  
  415.             wpa_printf(MSG_ERROR, "Failed to invoke HIDL iface callback");  
  416.         }  
  417.     }  
  418. }  
  419.   
  420.   
  421. sta_iface_callbacks_map_[wpa_s->ifname] =std::vector<android::sp<ISupplicantStaIfaceCallback>>();  
  422. (removeAllIfaceCallbackHidlObjectsFromMap(wpa_s->ifname, sta_iface_callbacks_map_))  
  423.   
  424.   
  425. addIfaceCallbackHidlObjectToMap(ifname, callback, on_hidl_died_fctor, sta_iface_callbacks_map_);  
  426.   
  427.   
  428.   
  429. template <class CallbackType>  
  430. int addIfaceCallbackHidlObjectToMap(  
  431.     const std::string &ifname,  
  432.     const android::sp<CallbackType> &callback,  
  433.     const std::function<void(const android::sp<CallbackType> &)> &on_hidl_died_fctor,  
  434.     std::map<const std::string, std::vector<android::sp<CallbackType>>> &callbacks_map)  
  435. {  
  436.     if (ifname.empty())  
  437.         return 1;  
  438.   
  439.     auto iface_callback_map_iter = callbacks_map.find(ifname);  
  440.     if (iface_callback_map_iter == callbacks_map.end())  
  441.         return 1;  
  442.     auto &iface_callback_list = iface_callback_map_iter->second;  
  443.   
  444.     // Register for death notification before we add it to our list.  
  445.     return registerForDeathAndAddCallbackHidlObjectToList<CallbackType>(  
  446.         callback, on_hidl_died_fctor, iface_callback_list);  
  447. }  
  448.   
  449.   
  450.   
  451. template <class CallbackType>  
  452. int registerForDeathAndAddCallbackHidlObjectToList(  
  453.     const android::sp<CallbackType> &callback,  
  454.     const std::function<void(const android::sp<CallbackType> &)>  
  455.     &on_hidl_died_fctor,  
  456.     std::vector<android::sp<CallbackType>> &callback_list)  
  457. {  
  458. #if 0   // TODO(b/31632518): HIDL object death notifications.  
  459.     auto death_notifier = new CallbackObjectDeathNotifier<CallbackType>(  
  460.         callback, on_hidl_died_fctor);  
  461.     // Use the |callback.get()| as cookie so that we don't need to  
  462.     // store a reference to this |CallbackObjectDeathNotifier| instance  
  463.     // to use in |unlinkToDeath| later.  
  464.     // NOTE: This may cause an immediate callback if the object is already  
  465.     // dead, so add it to the list before we register for callback!  
  466.     if (android::hardware::IInterface::asBinder(callback)->linkToDeath(  
  467.         death_notifier, callback.get()) != android::OK) {  
  468.         wpa_printf(  
  469.             MSG_ERROR,  
  470.             "Error registering for death notification for "  
  471.             "supplicant callback object");  
  472.         callback_list.erase(  
  473.             std::remove(  
  474.             callback_list.begin(), callback_list.end(), callback),  
  475.             callback_list.end());  
  476.         return 1;  
  477.     }  
  478. #endif  // TODO(b/31632518): HIDL object death notifications.  
  479.     callback_list.push_back(callback);  // 把当前的类 CallbackType 放到  iface_callback_list  
  480.     return 0;  
  481. }  
  482.   
  483.   
  484. template <class CallbackType>  
  485. int removeAllIfaceCallbackHidlObjectsFromMap(  
  486.     const std::string &ifname,  
  487.     std::map<const std::string, std::vector<android::sp<CallbackType>>> &callbacks_map)  
  488. {  
  489.     auto iface_callback_map_iter = callbacks_map.find(ifname);  
  490.     if (iface_callback_map_iter == callbacks_map.end())  
  491.         return 1;  
  492. #if 0   // TODO(b/31632518): HIDL object death notifications.  
  493.     const auto &iface_callback_list = iface_callback_map_iter->second;  
  494.     for (const auto &callback : iface_callback_list) {  
  495.         if (android::hardware::IInterface::asBinder(callback)  
  496.             ->unlinkToDeath(nullptr, callback.get()) !=  
  497.             android::OK) {  
  498.             wpa_printf(  
  499.                 MSG_ERROR,  
  500.                 "Error deregistering for death notification for "  
  501.                 "iface callback object");  
  502.         }  
  503.     }  
  504. #endif  // TODO(b/31632518): HIDL object death notifications.  
  505.     callbacks_map.erase(iface_callback_map_iter);  
  506.     return 0;  
  507. }  
  508.   
  509. ===============================================================  
  510.   
  511.   
  512.   
  513. /** 
  514.  * Register an interface to hidl manager. 
  515.  * 
  516.  * @param wpa_s |wpa_supplicant| struct corresponding to the interface. 
  517.  * 
  518.  * @return 0 on success, 1 on failure. 
  519.  */  
  520. int HidlManager::registerInterface(struct wpa_supplicant *wpa_s)  
  521. {  
  522. sta_iface_callbacks_map_[wpa_s->ifname] =std::vector<android::sp<ISupplicantStaIfaceCallback>>();  
  523.   
  524.     // Invoke the |onInterfaceCreated| method on all registered callbacks.  
  525.     callWithEachSupplicantCallback(std::bind(  
  526.         &ISupplicantCallback::onInterfaceCreated, std::placeholders::_1,  
  527.         wpa_s->ifname));  
  528. }     
  529. // 注册一个 接口  在 hidl manager?   难道就是创建一个   
  530. //std::vector<android::sp<ISupplicantStaIfaceCallback>>() 并把它放到map中?  
  531.   
  532.   
  533.   
  534. /** 
  535.  * Helper function to invoke the provided callback method on all the 
  536.  * registered |ISupplicantCallback| callback hidl objects. 
  537.  * 
  538.  * @param method Pointer to the required hidl method from 
  539.  * |ISupplicantCallback|. 
  540.  */  
  541. void HidlManager::callWithEachSupplicantCallback(  
  542.     const std::function<Return<void>(android::sp<ISupplicantCallback>)> &method)  
  543. {  
  544.     for (const auto &callback : supplicant_callbacks_) {  
  545. // supplicant_callbacks_ 就是一系列 定义了函数的&ISupplicantCallback::onInterfaceCreated的类  
  546. //执行这些类的 onInterfaceCreated方法   
  547.         if (!method(callback).isOk()) {    
  548.             wpa_printf(MSG_ERROR, "Failed to invoke HIDL callback");  
  549.         }  
  550.     }  
  551. }  
  552.   
  553.   
  554. // http://blog.csdn.net/eclipser1987/article/details/24406203  C++ 新特性    
  555. // http://coliru.stacked-crooked.com/   C++ 在线编辑  
[cpp]  view plain  copy
  1. // std::bind函数绑定    std::placeholders::_1, std::placeholders::_2  占位符   FUCK  

https://blog.csdn.net/u010842019/article/details/78820831

猜你喜欢

转载自blog.csdn.net/andytian1991/article/details/80443255