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
218 Condition mCondition
;
220 interface_info
*mIfaceInfo
;
223 WifiCommand(wifi_handle handle
, wifi_request_id id
)
224 : mMsg(getHalInfo(handle
)->nl80211_family_id
), mId(id
), mRefs(1)
227 mInfo
= getHalInfo(handle
);
228 // ALOGD("WifiCommand %p created, mInfo = %p, mIfaceInfo = %p", this, mInfo, mIfaceInfo);
231 WifiCommand(wifi_interface_handle iface
, wifi_request_id id
)
232 : mMsg(getHalInfo(iface
)->nl80211_family_id
, getIfaceInfo(iface
)->id
), mId(id
), mRefs(1)
234 mIfaceInfo
= getIfaceInfo(iface
);
235 mInfo
= getHalInfo(iface
);
236 // ALOGD("WifiCommand %p created, mInfo = %p, mIfaceInfo = %p", this, mInfo, mIfaceInfo);
239 virtual ~WifiCommand() {
240 // ALOGD("WifiCommand %p destroyed", this);
243 wifi_request_id
id() {
247 virtual void addRef() {
248 __sync_add_and_fetch(&mRefs
, 1);
249 //int refs = __sync_add_and_fetch(&mRefs, 1);
250 // ALOGD("addRef: WifiCommand %p has %d references", this, refs);
253 virtual void releaseRef() {
254 int refs
= __sync_sub_and_fetch(&mRefs
, 1);
258 // ALOGD("releaseRef: WifiCommand %p has %d references", this, refs);
262 virtual int create() {
263 /* by default there is no way to cancel */
264 //ALOGD("WifiCommand %p can't be created", this);
265 return WIFI_ERROR_NOT_SUPPORTED
;
268 virtual int cancel() {
269 /* by default there is no way to cancel */
270 return WIFI_ERROR_NOT_SUPPORTED
;
273 int requestResponse();
274 int requestEvent(int cmd
);
275 int requestVendorEvent(uint32_t id
, int subcmd
);
276 int requestResponse(WifiRequest
& request
);
279 wifi_handle
wifiHandle() {
280 return getWifiHandle(mInfo
);
283 wifi_interface_handle
ifaceHandle() {
284 return getIfaceHandle(mIfaceInfo
);
288 return mInfo
->nl80211_family_id
;
292 return mIfaceInfo
->id
;
295 /* Override this method to parse reply and dig out data; save it in the object */
296 virtual int handleResponse(WifiEvent
& reply
) {
297 ALOGI("skipping a response");
301 /* Override this method to parse event and dig out data; save it in the object */
302 virtual int handleEvent(WifiEvent
& event
) {
303 ALOGI("skipping an event");
307 int registerHandler(int cmd
) {
308 return wifi_register_handler(wifiHandle(), cmd
, &event_handler
, this);
311 void unregisterHandler(int cmd
) {
312 wifi_unregister_handler(wifiHandle(), cmd
);
315 int registerVendorHandler(uint32_t id
, int subcmd
) {
316 return wifi_register_vendor_handler(wifiHandle(), id
, subcmd
, &event_handler
, this);
319 void unregisterVendorHandler(uint32_t id
, int subcmd
) {
320 wifi_unregister_vendor_handler(wifiHandle(), id
, subcmd
);
324 WifiCommand(const WifiCommand
& ); // hide copy constructor to prevent copies
327 static int response_handler(struct nl_msg
*msg
, void *arg
);
329 static int event_handler(struct nl_msg
*msg
, void *arg
);
331 /* Other event handlers */
332 static int valid_handler(struct nl_msg
*msg
, void *arg
);
334 static int ack_handler(struct nl_msg
*msg
, void *arg
);
336 static int finish_handler(struct nl_msg
*msg
, void *arg
);
338 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
, void *arg
);
341 /* nl message processing macros (required to pass C++ type checks) */
343 #define for_each_attr(pos, nla, rem) \
344 for (pos = (nlattr *)nla_data(nla), rem = nla_len(nla); \
346 pos = (nlattr *)nla_next(pos, &(rem)))