system/corennnnn
Revisão | 5fc4129fcb9609790e2d1d3a93c7d9de8dd94ccb (tree) |
---|---|
Hora | 2009-06-17 02:50:06 |
Autor | San Mehat <san@goog...> |
Commiter | San Mehat |
nexus: Add TiwlanEventListener for reading driver events directly
Signed-off-by: San Mehat <san@google.com>
@@ -0,0 +1,61 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2008 The Android Open Source Project | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | + | |
17 | +#include <errno.h> | |
18 | +#include <pthread.h> | |
19 | +#include <sys/types.h> | |
20 | +#include <sys/types.h> | |
21 | +#include <sys/socket.h> | |
22 | + | |
23 | +#define LOG_TAG "TiwlanEventListener" | |
24 | +#include <cutils/log.h> | |
25 | + | |
26 | +#include "TiwlanEventListener.h" | |
27 | + | |
28 | +TiwlanEventListener::TiwlanEventListener(int socket) : | |
29 | + SocketListener(socket, false) { | |
30 | +} | |
31 | + | |
32 | +bool TiwlanEventListener::onDataAvailable(SocketClient *cli) { | |
33 | + struct ipc_ev_data *data; | |
34 | + | |
35 | + if (!(data = (struct ipc_ev_data *) malloc(sizeof(struct ipc_ev_data)))) { | |
36 | + LOGE("Failed to allocate packet (out of memory)"); | |
37 | + return true; | |
38 | + } | |
39 | + | |
40 | + if (recv(cli->getSocket(), data, sizeof(struct ipc_ev_data), 0) < 0) { | |
41 | + LOGE("recv failed (%s)", strerror(errno)); | |
42 | + goto out; | |
43 | + } | |
44 | + | |
45 | + if (data->event_type == IPC_EVENT_LINK_SPEED) { | |
46 | + uint32_t *spd = (uint32_t *) data->buffer; | |
47 | + *spd /= 2; | |
48 | + LOGD("Link speed = %u MB/s", *spd); | |
49 | + } else if (data->event_type == IPC_EVENT_LOW_SNR) { | |
50 | + LOGD("Low signal/noise ratio"); | |
51 | + } else if (data->event_type == IPC_EVENT_LOW_RSSI) { | |
52 | + LOGD("Low RSSI"); | |
53 | + } else { | |
54 | + LOGD("Dropping unhandled driver event %d", data->event_type); | |
55 | + } | |
56 | + | |
57 | + // TODO: Tell WifiController about the event | |
58 | +out: | |
59 | + free(data); | |
60 | + return true; | |
61 | +} |
@@ -0,0 +1,55 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2008 The Android Open Source Project | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | + | |
17 | +#ifndef _TIWLAN_EVENT_LISTENER_H__ | |
18 | +#define _TIWLAN_EVENT_LISTENER_H__ | |
19 | + | |
20 | +#include <sysutils/SocketListener.h> | |
21 | + | |
22 | +struct wpa_ctrl; | |
23 | +class SocketClient; | |
24 | +class ITiwlanEventHandler; | |
25 | +class TiwlanEventFactory; | |
26 | + | |
27 | +class TiwlanEventListener: public SocketListener { | |
28 | + | |
29 | +public: | |
30 | + TiwlanEventListener(int sock); | |
31 | + virtual ~TiwlanEventListener() {} | |
32 | + | |
33 | +protected: | |
34 | + virtual bool onDataAvailable(SocketClient *c); | |
35 | +}; | |
36 | + | |
37 | +// TODO: Move all this crap into a factory | |
38 | +#define TI_DRIVER_MSG_PORT 9001 | |
39 | + | |
40 | +#define IPC_EVENT_LINK_SPEED 2 | |
41 | +#define IPC_EVENT_LOW_SNR 13 | |
42 | +#define IPC_EVENT_LOW_RSSI 14 | |
43 | + | |
44 | +struct ipc_ev_data { | |
45 | + uint32_t event_type; | |
46 | + void *event_id; | |
47 | + uint32_t process_id; | |
48 | + uint32_t delivery_type; | |
49 | + uint32_t user_param; | |
50 | + void *event_callback; | |
51 | + uint32_t bufferSize; | |
52 | + uint8_t buffer[2048]; | |
53 | +}; | |
54 | + | |
55 | +#endif |
@@ -18,6 +18,9 @@ | ||
18 | 18 | #include <fcntl.h> |
19 | 19 | #include <errno.h> |
20 | 20 | #include <string.h> |
21 | +#include <sys/types.h> | |
22 | +#include <sys/socket.h> | |
23 | +#include <arpa/inet.h> | |
21 | 24 | |
22 | 25 | #include <cutils/properties.h> |
23 | 26 | #define LOG_TAG "TiwlanWifiController" |
@@ -25,6 +28,7 @@ | ||
25 | 28 | |
26 | 29 | #include "PropertyManager.h" |
27 | 30 | #include "TiwlanWifiController.h" |
31 | +#include "TiwlanEventListener.h" | |
28 | 32 | |
29 | 33 | #define DRIVER_PROP_NAME "wlan.driver.status" |
30 | 34 |
@@ -36,6 +40,8 @@ TiwlanWifiController::TiwlanWifiController(PropertyManager *propmngr, | ||
36 | 40 | char *modargs) : |
37 | 41 | WifiController(propmngr, handlers, modpath, modname, |
38 | 42 | modargs) { |
43 | + mEventListener = NULL; | |
44 | + mListenerSock = -1; | |
39 | 45 | } |
40 | 46 | |
41 | 47 | int TiwlanWifiController::powerUp() { |
@@ -43,6 +49,13 @@ int TiwlanWifiController::powerUp() { | ||
43 | 49 | } |
44 | 50 | |
45 | 51 | int TiwlanWifiController::powerDown() { |
52 | + if (mEventListener) { | |
53 | + delete mEventListener; | |
54 | + close(mListenerSock); | |
55 | + mListenerSock = -1; | |
56 | + mEventListener = NULL; | |
57 | + } | |
58 | + | |
46 | 59 | return 0; // Powerdown is currently done when the driver is unloaded |
47 | 60 | } |
48 | 61 |
@@ -60,17 +73,56 @@ int TiwlanWifiController::loadFirmware() { | ||
60 | 73 | // Wait for driver to be ready |
61 | 74 | while (count-- > 0) { |
62 | 75 | if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) { |
63 | - if (strcmp(driver_status, "ok") == 0) | |
76 | + if (!strcmp(driver_status, "ok")) { | |
77 | + LOGD("Firmware loaded OK"); | |
78 | + | |
79 | + if (startDriverEventListener()) { | |
80 | + LOGW("Failed to start driver event listener"); | |
81 | + } | |
82 | + | |
64 | 83 | return 0; |
65 | - else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) | |
84 | + } else if (!strcmp(DRIVER_PROP_NAME, "failed")) { | |
85 | + LOGE("Firmware load failed"); | |
66 | 86 | return -1; |
87 | + } | |
67 | 88 | } |
68 | 89 | usleep(200000); |
69 | 90 | } |
70 | 91 | property_set(DRIVER_PROP_NAME, "timeout"); |
92 | + LOGE("Firmware load timed out"); | |
71 | 93 | return -1; |
72 | 94 | } |
73 | 95 | |
96 | +int TiwlanWifiController::startDriverEventListener() { | |
97 | + struct sockaddr_in addr; | |
98 | + int s; | |
99 | + | |
100 | + if ((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) | |
101 | + return -1; | |
102 | + | |
103 | + memset(&addr, 0, sizeof(addr)); | |
104 | + addr.sin_family = AF_INET; | |
105 | + addr.sin_addr.s_addr = htonl(INADDR_ANY); | |
106 | + addr.sin_port = htons(TI_DRIVER_MSG_PORT); | |
107 | + | |
108 | + if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { | |
109 | + close(s); | |
110 | + return -1; | |
111 | + } | |
112 | + | |
113 | + mEventListener = new TiwlanEventListener(s); | |
114 | + | |
115 | + if (mEventListener->startListener()) { | |
116 | + LOGE("Error starting driver listener (%s)", strerror(errno)); | |
117 | + delete mEventListener; | |
118 | + mEventListener = NULL; | |
119 | + close(s); | |
120 | + return -1; | |
121 | + } | |
122 | + mListenerSock = s; | |
123 | + return 0; | |
124 | +} | |
125 | + | |
74 | 126 | bool TiwlanWifiController::isFirmwareLoaded() { |
75 | 127 | // Always load the firmware |
76 | 128 | return false; |
@@ -21,8 +21,12 @@ | ||
21 | 21 | #include "WifiController.h" |
22 | 22 | |
23 | 23 | class IControllerHandler; |
24 | +class TiwlanEventListener; | |
24 | 25 | |
25 | 26 | class TiwlanWifiController : public WifiController { |
27 | + int mListenerSock; | |
28 | + TiwlanEventListener *mEventListener; | |
29 | + | |
26 | 30 | public: |
27 | 31 | TiwlanWifiController(PropertyManager *propmngr, IControllerHandler *handlers, char *modpath, char *modname, char *modargs); |
28 | 32 | virtual ~TiwlanWifiController() {} |
@@ -32,5 +36,8 @@ public: | ||
32 | 36 | virtual bool isPoweredUp(); |
33 | 37 | virtual int loadFirmware(); |
34 | 38 | virtual bool isFirmwareLoaded(); |
39 | + | |
40 | +private: | |
41 | + int startDriverEventListener(); | |
35 | 42 | }; |
36 | 43 | #endif |