blob: 16c63c196caa2f175eeb94a40d4b8d60d4a4fdd6 [file] [log] [blame]
San Mehat5fc41292009-06-16 10:50:06 -07001/*
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
28TiwlanEventListener::TiwlanEventListener(int socket) :
29 SocketListener(socket, false) {
30}
31
32bool 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;
Steve Block8d66c492011-12-20 16:07:45 +000048// ALOGD("Link speed = %u MB/s", *spd);
San Mehat5fc41292009-06-16 10:50:06 -070049 } else if (data->event_type == IPC_EVENT_LOW_SNR) {
San Mehat052403e2009-06-16 12:01:24 -070050 LOGW("Low signal/noise ratio");
San Mehat5fc41292009-06-16 10:50:06 -070051 } else if (data->event_type == IPC_EVENT_LOW_RSSI) {
San Mehat052403e2009-06-16 12:01:24 -070052 LOGW("Low RSSI");
San Mehat5fc41292009-06-16 10:50:06 -070053 } else {
Steve Block8d66c492011-12-20 16:07:45 +000054// ALOGD("Dropping unhandled driver event %d", data->event_type);
San Mehat5fc41292009-06-16 10:50:06 -070055 }
56
57 // TODO: Tell WifiController about the event
58out:
59 free(data);
60 return true;
61}