San Mehat | 5fc4129 | 2009-06-16 10:50:06 -0700 | [diff] [blame] | 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; |
San Mehat | 052403e | 2009-06-16 12:01:24 -0700 | [diff] [blame] | 48 | // LOGD("Link speed = %u MB/s", *spd); |
San Mehat | 5fc4129 | 2009-06-16 10:50:06 -0700 | [diff] [blame] | 49 | } else if (data->event_type == IPC_EVENT_LOW_SNR) { |
San Mehat | 052403e | 2009-06-16 12:01:24 -0700 | [diff] [blame] | 50 | LOGW("Low signal/noise ratio"); |
San Mehat | 5fc4129 | 2009-06-16 10:50:06 -0700 | [diff] [blame] | 51 | } else if (data->event_type == IPC_EVENT_LOW_RSSI) { |
San Mehat | 052403e | 2009-06-16 12:01:24 -0700 | [diff] [blame] | 52 | LOGW("Low RSSI"); |
San Mehat | 5fc4129 | 2009-06-16 10:50:06 -0700 | [diff] [blame] | 53 | } else { |
San Mehat | 052403e | 2009-06-16 12:01:24 -0700 | [diff] [blame] | 54 | // LOGD("Dropping unhandled driver event %d", data->event_type); |
San Mehat | 5fc4129 | 2009-06-16 10:50:06 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | // TODO: Tell WifiController about the event |
| 58 | out: |
| 59 | free(data); |
| 60 | return true; |
| 61 | } |