8 /* TODO: remove this when nl headers are updated */
9 static const unsigned NL80211_ATTR_MAX_INTERNAL
= 256;
12 struct genlmsghdr
*mHeader
;
13 struct nlattr
*mAttributes
[NL80211_ATTR_MAX_INTERNAL
+ 1];
16 WifiEvent(nl_msg
*msg
) {
19 memset(mAttributes
, 0, sizeof(mAttributes
));
22 /* don't destroy mMsg; it doesn't belong to us */
29 genlmsghdr
*header() {
38 return get_u32(NL80211_ATTR_VENDOR_ID
);
41 int get_vendor_subcmd() {
42 return get_u32(NL80211_ATTR_VENDOR_SUBCMD
);
45 void *get_vendor_data() {
46 return get_data(NL80211_ATTR_VENDOR_DATA
);
49 int get_vendor_data_len() {
50 return get_len(NL80211_ATTR_VENDOR_DATA
);
53 const char *get_cmdString();
55 nlattr
** attributes() {
59 nlattr
*get_attribute(int attribute
) {
60 return mAttributes
[attribute
];
63 uint8_t get_u8(int attribute
) {
64 return mAttributes
[attribute
] ? nla_get_u8(mAttributes
[attribute
]) : 0;
67 uint16_t get_u16(int attribute
) {
68 return mAttributes
[attribute
] ? nla_get_u16(mAttributes
[attribute
]) : 0;
71 uint32_t get_u32(int attribute
) {
72 return mAttributes
[attribute
] ? nla_get_u32(mAttributes
[attribute
]) : 0;
75 uint64_t get_u64(int attribute
) {
76 return mAttributes
[attribute
] ? nla_get_u64(mAttributes
[attribute
]) : 0;
79 int get_len(int attribute
) {
80 return mAttributes
[attribute
] ? nla_len(mAttributes
[attribute
]) : 0;
83 void *get_data(int attribute
) {
84 return mAttributes
[attribute
] ? nla_data(mAttributes
[attribute
]) : NULL
;
88 WifiEvent(const WifiEvent
&); // hide copy constructor to prevent copies
95 nl_iterator(struct nlattr
*attr
) {
96 pos
= (struct nlattr
*)nla_data(attr
);
100 return nla_ok(pos
, rem
);
103 pos
= (struct nlattr
*)nla_next(pos
, &(rem
));
105 struct nlattr
*get() {
108 uint16_t get_type() {
109 return pos
->nla_type
;
112 return nla_get_u8(pos
);
115 return nla_get_u16(pos
);
118 return nla_get_u32(pos
);
121 return nla_get_u64(pos
);
124 return nla_data(pos
);
130 nl_iterator(const nl_iterator
&); // hide copy constructor to prevent copies
141 WifiRequest(int family
) {
147 WifiRequest(int family
, int iface
) {
164 nl_msg
*getMessage() {
168 /* Command assembly helpers */
169 int create(int family
, uint8_t cmd
, int flags
, int hdrlen
);
170 int create(uint8_t cmd
) {
171 return create(mFamily
, cmd
, 0, 0);
174 int create(uint32_t id
, int subcmd
);
176 int put(int attribute
, void *ptr
, unsigned len
) {
177 return nla_put(mMsg
, attribute
, len
, ptr
);
179 int put_u8(int attribute
, uint8_t value
) {
180 return nla_put(mMsg
, attribute
, sizeof(value
), &value
);
182 int put_u16(int attribute
, uint16_t value
) {
183 return nla_put(mMsg
, attribute
, sizeof(value
), &value
);
185 int put_u32(int attribute
, uint32_t value
) {
186 return nla_put(mMsg
, attribute
, sizeof(value
), &value
);
188 int put_u64(int attribute
, uint64_t value
) {
189 return nla_put(mMsg
, attribute
, sizeof(value
), &value
);
191 int put_string(int attribute
, const char *value
) {
192 return nla_put(mMsg
, attribute
, strlen(value
) + 1, value
);
194 int put_addr(int attribute
, mac_addr value
) {
195 return nla_put(mMsg
, attribute
, sizeof(mac_addr
), value
);
198 struct nlattr
* attr_start(int attribute
) {
199 return nla_nest_start(mMsg
, attribute
);
201 void attr_end(struct nlattr
*attr
) {
202 nla_nest_end(mMsg
, attr
);
205 int set_iface_id(int ifindex
) {
206 return put_u32(NL80211_ATTR_IFINDEX
, ifindex
);
209 WifiRequest(const WifiRequest
&); // hide copy constructor to prevent copies
219 Condition mCondition
;
221 interface_info
*mIfaceInfo
;
224 WifiCommand(const char *type
, wifi_handle handle
, wifi_request_id id
)
225 : mType(type
), mMsg(getHalInfo(handle
)->nl80211_family_id
), mId(id
), mRefs(1)
228 mInfo
= getHalInfo(handle
);
229 // ALOGD("WifiCommand %p created, mInfo = %p, mIfaceInfo = %p", this, mInfo, mIfaceInfo);
232 WifiCommand(const char *type
, wifi_interface_handle iface
, wifi_request_id id
)
233 : mType(type
), mMsg(getHalInfo(iface
)->nl80211_family_id
, getIfaceInfo(iface
)->id
),
236 mIfaceInfo
= getIfaceInfo(iface
);
237 mInfo
= getHalInfo(iface
);
238 // ALOGD("WifiCommand2 %p created, mInfo=%p, mIfaceInfo=%p, id=%d", this, mInfo, mIfaceInfo, mIfaceInfo->id);
241 virtual ~WifiCommand() {
242 // ALOGD("WifiCommand %p destroyed", this);
245 wifi_request_id
id() {
249 const char *getType() {
253 virtual void addRef() {
254 int refs
= __sync_add_and_fetch(&mRefs
, 1);
255 // ALOGD("addRef: WifiCommand %p has %d references", this, refs);
258 virtual void releaseRef() {
259 int refs
= __sync_sub_and_fetch(&mRefs
, 1);
263 // ALOGD("releaseRef: WifiCommand %p has %d references", this, refs);
267 virtual int create() {
268 /* by default there is no way to cancel */
269 ALOGD("WifiCommand %p can't be created", this);
270 return WIFI_ERROR_NOT_SUPPORTED
;
273 virtual int cancel() {
274 /* by default there is no way to cancel */
275 return WIFI_ERROR_NOT_SUPPORTED
;
278 int requestResponse();
279 int requestEvent(int cmd
);
280 int requestVendorEvent(uint32_t id
, int subcmd
);
281 int requestResponse(WifiRequest
& request
);
284 wifi_handle
wifiHandle() {
285 return getWifiHandle(mInfo
);
288 wifi_interface_handle
ifaceHandle() {
289 return getIfaceHandle(mIfaceInfo
);
293 return mInfo
->nl80211_family_id
;
297 return mIfaceInfo
->id
;
300 /* Override this method to parse reply and dig out data; save it in the object */
301 virtual int handleResponse(WifiEvent
& reply
) {
302 ALOGI("skipping a response");
306 /* Override this method to parse event and dig out data; save it in the object */
307 virtual int handleEvent(WifiEvent
& event
) {
308 ALOGI("skipping an event");
312 int registerHandler(int cmd
) {
313 return wifi_register_handler(wifiHandle(), cmd
, &event_handler
, this);
316 void unregisterHandler(int cmd
) {
317 wifi_unregister_handler(wifiHandle(), cmd
);
320 int registerVendorHandler(uint32_t id
, int subcmd
) {
321 return wifi_register_vendor_handler(wifiHandle(), id
, subcmd
, &event_handler
, this);
324 void unregisterVendorHandler(uint32_t id
, int subcmd
) {
325 wifi_unregister_vendor_handler(wifiHandle(), id
, subcmd
);
329 WifiCommand(const WifiCommand
& ); // hide copy constructor to prevent copies
332 static int response_handler(struct nl_msg
*msg
, void *arg
);
334 static int event_handler(struct nl_msg
*msg
, void *arg
);
336 /* Other event handlers */
337 static int valid_handler(struct nl_msg
*msg
, void *arg
);
339 static int ack_handler(struct nl_msg
*msg
, void *arg
);
341 static int finish_handler(struct nl_msg
*msg
, void *arg
);
343 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
, void *arg
);
346 /* nl message processing macros (required to pass C++ type checks) */
348 #define for_each_attr(pos, nla, rem) \
349 for (pos = (nlattr *)nla_data(nla), rem = nla_len(nla); \
351 pos = (nlattr *)nla_next(pos, &(rem)))