Bug 1025824 - Fix mHwcLayerMap handling r=sushil
[gecko.git] / dom / wifi / WifiUtils.h
blob41e20f1b0a121cfec79530a287dcdbf743c6b432
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/. */
5 /**
6 * Abstraction on top of the wifi support from libhardware_legacy that we
7 * use to talk to the wpa_supplicant.
8 */
10 #ifndef WifiUtils_h
11 #define WifiUtils_h
13 #include "nsString.h"
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.
21 struct CommandOptions
23 public:
24 CommandOptions(const CommandOptions& aOther) {
25 mId = aOther.mId;
26 mCmd = aOther.mCmd;
27 mRequest = aOther.mRequest;
28 mIfname = aOther.mIfname;
29 mRoute = aOther.mRoute;
30 mIpaddr = aOther.mIpaddr;
31 mMask = aOther.mMask;
32 mGateway = aOther.mGateway;
33 mDns1 = aOther.mDns1;
34 mDns2 = aOther.mDns2;
35 mKey = aOther.mKey;
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(); \
45 } else { \
46 prop = defaultValue; \
49 #define COPY_FIELD(prop) prop = aOther.prop;
50 COPY_FIELD(mId)
51 COPY_FIELD(mCmd)
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())
64 #undef COPY_OPT_FIELD
65 #undef COPY_FIELD
68 // All the fields, not Optional<> anymore to get copy constructors.
69 nsString mCmd;
70 nsString mDefaultValue;
71 int32_t mDns1;
72 int32_t mDns2;
73 int32_t mGateway;
74 int32_t mId;
75 nsString mIfname;
76 int32_t mIpaddr;
77 nsString mKey;
78 int32_t mMask;
79 nsString mRequest;
80 int32_t mRoute;
81 nsString mValue;
84 // Abstract class that exposes libhardware_legacy functions we need for
85 // wifi management.
86 // We use the ICS signatures here since they are likely more future-proof.
87 class WpaSupplicantImpl
89 public:
90 // Suppress warning from nsAutoPtr
91 virtual ~WpaSupplicantImpl() {}
93 virtual int32_t
94 do_wifi_wait_for_event(const char *iface, char *buf, size_t len) = 0; // KK == ICS != JB
96 virtual int32_t
97 do_wifi_command(const char* iface, const char* cmd, char* buff, size_t* len) = 0; // KK == ICS != JB
99 virtual int32_t
100 do_wifi_load_driver() = 0;
102 virtual int32_t
103 do_wifi_unload_driver() = 0;
105 virtual int32_t
106 do_wifi_start_supplicant(int32_t) = 0; // ICS != JB == KK
108 virtual int32_t
109 do_wifi_stop_supplicant(int32_t) = 0; //ICS != JB == KK
111 virtual int32_t
112 do_wifi_connect_to_supplicant(const char* iface) = 0; // KK == ICS != JB
114 virtual void
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
121 public:
122 WpaSupplicant();
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
126 // conversion
127 void WaitForEvent(nsAString& aEvent, const nsCString& aInterface);
128 bool ExecuteCommand(CommandOptions aOptions,
129 mozilla::dom::WifiResultOptions& result,
130 const nsCString& aInterface);
132 private:
133 nsAutoPtr<WpaSupplicantImpl> mImpl;
134 nsAutoPtr<NetUtils> mNetUtils;
135 nsAutoPtr<WifiHotspotUtils> mWifiHotspotUtils;
137 protected:
138 void CheckBuffer(char* buffer, int32_t length, nsAString& aEvent);
139 uint32_t MakeMask(uint32_t len);
142 #endif // WifiUtils_h