Home | History | Annotate | Download | only in nexus
      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         LOGW("Low signal/noise ratio");
     51     } else if (data->event_type == IPC_EVENT_LOW_RSSI) {
     52         LOGW("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 }
     62