• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

修訂5fc4129fcb9609790e2d1d3a93c7d9de8dd94ccb (tree)
時間2009-06-17 02:50:06
作者San Mehat <san@goog...>
CommiterSan Mehat

Log Message

nexus: Add TiwlanEventListener for reading driver events directly

Signed-off-by: San Mehat <san@google.com>

Change Summary

差異

--- /dev/null
+++ b/nexus/TiwlanEventListener.cpp
@@ -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+}
--- /dev/null
+++ b/nexus/TiwlanEventListener.h
@@ -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
--- a/nexus/TiwlanWifiController.cpp
+++ b/nexus/TiwlanWifiController.cpp
@@ -18,6 +18,9 @@
1818 #include <fcntl.h>
1919 #include <errno.h>
2020 #include <string.h>
21+#include <sys/types.h>
22+#include <sys/socket.h>
23+#include <arpa/inet.h>
2124
2225 #include <cutils/properties.h>
2326 #define LOG_TAG "TiwlanWifiController"
@@ -25,6 +28,7 @@
2528
2629 #include "PropertyManager.h"
2730 #include "TiwlanWifiController.h"
31+#include "TiwlanEventListener.h"
2832
2933 #define DRIVER_PROP_NAME "wlan.driver.status"
3034
@@ -36,6 +40,8 @@ TiwlanWifiController::TiwlanWifiController(PropertyManager *propmngr,
3640 char *modargs) :
3741 WifiController(propmngr, handlers, modpath, modname,
3842 modargs) {
43+ mEventListener = NULL;
44+ mListenerSock = -1;
3945 }
4046
4147 int TiwlanWifiController::powerUp() {
@@ -43,6 +49,13 @@ int TiwlanWifiController::powerUp() {
4349 }
4450
4551 int TiwlanWifiController::powerDown() {
52+ if (mEventListener) {
53+ delete mEventListener;
54+ close(mListenerSock);
55+ mListenerSock = -1;
56+ mEventListener = NULL;
57+ }
58+
4659 return 0; // Powerdown is currently done when the driver is unloaded
4760 }
4861
@@ -60,17 +73,56 @@ int TiwlanWifiController::loadFirmware() {
6073 // Wait for driver to be ready
6174 while (count-- > 0) {
6275 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+
6483 return 0;
65- else if (strcmp(DRIVER_PROP_NAME, "failed") == 0)
84+ } else if (!strcmp(DRIVER_PROP_NAME, "failed")) {
85+ LOGE("Firmware load failed");
6686 return -1;
87+ }
6788 }
6889 usleep(200000);
6990 }
7091 property_set(DRIVER_PROP_NAME, "timeout");
92+ LOGE("Firmware load timed out");
7193 return -1;
7294 }
7395
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+
74126 bool TiwlanWifiController::isFirmwareLoaded() {
75127 // Always load the firmware
76128 return false;
--- a/nexus/TiwlanWifiController.h
+++ b/nexus/TiwlanWifiController.h
@@ -21,8 +21,12 @@
2121 #include "WifiController.h"
2222
2323 class IControllerHandler;
24+class TiwlanEventListener;
2425
2526 class TiwlanWifiController : public WifiController {
27+ int mListenerSock;
28+ TiwlanEventListener *mEventListener;
29+
2630 public:
2731 TiwlanWifiController(PropertyManager *propmngr, IControllerHandler *handlers, char *modpath, char *modname, char *modargs);
2832 virtual ~TiwlanWifiController() {}
@@ -32,5 +36,8 @@ public:
3236 virtual bool isPoweredUp();
3337 virtual int loadFirmware();
3438 virtual bool isFirmwareLoaded();
39+
40+private:
41+ int startDriverEventListener();
3542 };
3643 #endif