blob: fde3a44d2a6a9f6627016f996a9648461b662113 [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)))) {
Steve Block01dda202012-01-06 14:13:42 +000036 ALOGE("Failed to allocate packet (out of memory)");
San Mehat5fc41292009-06-16 10:50:06 -070037 return true;
38 }
39
40 if (recv(cli->getSocket(), data, sizeof(struct ipc_ev_data), 0) < 0) {
Steve Block01dda202012-01-06 14:13:42 +000041 ALOGE("recv failed (%s)", strerror(errno));
San Mehat5fc41292009-06-16 10:50:06 -070042 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) {
Steve Blockae8b56c2012-01-05 22:25:38 +000050 ALOGW("Low signal/noise ratio");
San Mehat5fc41292009-06-16 10:50:06 -070051 } else if (data->event_type == IPC_EVENT_LOW_RSSI) {
Steve Blockae8b56c2012-01-05 22:25:38 +000052 ALOGW("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}