1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 * Abstraction on top of the wifi support from libhardware_legacy that we
7 * use to talk to the wpa_supplicant.
14 #include "nsAutoPtr.h"
15 #include "mozilla/dom/WifiOptionsBinding.h"
16 #include "mozilla/dom/network/NetUtils.h"
17 #include "WifiHotspotUtils.h"
18 #include "nsCxPusher.h"
20 // Needed to add a copy constructor to WifiCommandOptions.
24 CommandOptions(const CommandOptions
& aOther
) {
27 mRequest
= aOther
.mRequest
;
28 mIfname
= aOther
.mIfname
;
29 mRoute
= aOther
.mRoute
;
30 mIpaddr
= aOther
.mIpaddr
;
32 mGateway
= aOther
.mGateway
;
36 mValue
= aOther
.mValue
;
37 mDefaultValue
= aOther
.mDefaultValue
;
40 CommandOptions(const mozilla::dom::WifiCommandOptions
& aOther
) {
42 #define COPY_OPT_FIELD(prop, defaultValue) \
43 if (aOther.prop.WasPassed()) { \
44 prop = aOther.prop.Value(); \
46 prop = defaultValue; \
49 #define COPY_FIELD(prop) prop = aOther.prop;
52 COPY_OPT_FIELD(mRequest
, EmptyString())
53 COPY_OPT_FIELD(mIfname
, EmptyString())
54 COPY_OPT_FIELD(mIpaddr
, 0)
55 COPY_OPT_FIELD(mRoute
, 0)
56 COPY_OPT_FIELD(mMask
, 0)
57 COPY_OPT_FIELD(mGateway
, 0)
58 COPY_OPT_FIELD(mDns1
, 0)
59 COPY_OPT_FIELD(mDns2
, 0)
60 COPY_OPT_FIELD(mKey
, EmptyString())
61 COPY_OPT_FIELD(mValue
, EmptyString())
62 COPY_OPT_FIELD(mDefaultValue
, EmptyString())
68 // All the fields, not Optional<> anymore to get copy constructors.
70 nsString mDefaultValue
;
84 // Abstract class that exposes libhardware_legacy functions we need for
86 // We use the ICS signatures here since they are likely more future-proof.
87 class WpaSupplicantImpl
90 // Suppress warning from nsAutoPtr
91 virtual ~WpaSupplicantImpl() {}
94 do_wifi_wait_for_event(const char *iface
, char *buf
, size_t len
) = 0; // KK == ICS != JB
97 do_wifi_command(const char* iface
, const char* cmd
, char* buff
, size_t* len
) = 0; // KK == ICS != JB
100 do_wifi_load_driver() = 0;
103 do_wifi_unload_driver() = 0;
106 do_wifi_start_supplicant(int32_t) = 0; // ICS != JB == KK
109 do_wifi_stop_supplicant(int32_t) = 0; //ICS != JB == KK
112 do_wifi_connect_to_supplicant(const char* iface
) = 0; // KK == ICS != JB
115 do_wifi_close_supplicant_connection(const char* iface
) = 0; // KK == ICS != JB
118 // Concrete class to use to access the wpa supplicant.
119 class WpaSupplicant MOZ_FINAL
124 // Use nsCString as the type of aInterface to guarantee it's
125 // null-terminated so that we can pass it to c API without
127 void WaitForEvent(nsAString
& aEvent
, const nsCString
& aInterface
);
128 bool ExecuteCommand(CommandOptions aOptions
,
129 mozilla::dom::WifiResultOptions
& result
,
130 const nsCString
& aInterface
);
133 nsAutoPtr
<WpaSupplicantImpl
> mImpl
;
134 nsAutoPtr
<NetUtils
> mNetUtils
;
135 nsAutoPtr
<WifiHotspotUtils
> mWifiHotspotUtils
;
138 void CheckBuffer(char* buffer
, int32_t length
, nsAString
& aEvent
);
139 uint32_t MakeMask(uint32_t len
);
142 #endif // WifiUtils_h