Home | History | Annotate | Download | only in wifi_hal
      1 /*
      2  * Copyright (C) 2014 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 "wifi_hal.h"
     18 
     19 #ifndef __WIFI_HAL_COMMON_H__
     20 #define __WIFI_HAL_COMMON_H__
     21 
     22 #ifndef LOG_TAG
     23 #define LOG_TAG  "WifiHAL"
     24 #endif
     25 
     26 #include <stdint.h>
     27 #include <fcntl.h>
     28 #include <sys/socket.h>
     29 #include <netlink/genl/genl.h>
     30 #include <netlink/genl/family.h>
     31 #include <netlink/genl/ctrl.h>
     32 #include <linux/rtnetlink.h>
     33 #include <netpacket/packet.h>
     34 #include <linux/filter.h>
     35 #include <linux/errqueue.h>
     36 
     37 #include <linux/pkt_sched.h>
     38 #include <netlink/object-api.h>
     39 #include <netlink/netlink.h>
     40 #include <netlink/socket.h>
     41 #include <netlink-types.h>
     42 
     43 #include "nl80211_copy.h"
     44 
     45 #include <utils/Log.h>
     46 
     47 #define SOCKET_BUFFER_SIZE      (32768U)
     48 #define RECV_BUF_SIZE           (4096)
     49 #define DEFAULT_EVENT_CB_SIZE   (64)
     50 #define DEFAULT_CMD_SIZE        (64)
     51 
     52 typedef void (*wifi_internal_event_handler) (wifi_handle handle, int events);
     53 
     54 class WifiCommand;
     55 
     56 typedef struct {
     57     int nl_cmd;
     58     uint32_t vendor_id;
     59     int vendor_subcmd;
     60     nl_recvmsg_msg_cb_t cb_func;
     61     void *cb_arg;
     62 } cb_info;
     63 
     64 typedef struct {
     65     wifi_request_id id;
     66     WifiCommand *cmd;
     67 } cmd_info;
     68 
     69 typedef struct {
     70     wifi_handle handle;                             // handle to wifi data
     71     char name[8+1];                                 // interface name + trailing null
     72     int  id;                                        // id to use when talking to driver
     73 } interface_info;
     74 
     75 typedef struct {
     76 
     77     struct nl_sock *cmd_sock;                       // command socket object
     78     struct nl_sock *event_sock;                     // event socket object
     79     int nl80211_family_id;                          // family id for 80211 driver
     80 
     81     bool in_event_loop;                             // Indicates that event loop is active
     82     bool clean_up;                                  // Indication to clean up the socket
     83 
     84     wifi_internal_event_handler event_handler;      // default event handler
     85     wifi_cleaned_up_handler cleaned_up_handler;     // socket cleaned up handler
     86 
     87     cb_info *event_cb;                              // event callbacks
     88     int num_event_cb;                               // number of event callbacks
     89     int alloc_event_cb;                             // number of allocated callback objects
     90 
     91     cmd_info *cmd;                                  // Outstanding commands
     92     int num_cmd;                                    // number of commands
     93     int alloc_cmd;                                  // number of commands allocated
     94 
     95     interface_info **interfaces;                    // array of interfaces
     96     int num_interfaces;                             // number of interfaces
     97 
     98     // add other details
     99 } hal_info;
    100 
    101 wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg);
    102 wifi_error wifi_register_vendor_handler(wifi_handle handle,
    103             uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg);
    104 
    105 void wifi_unregister_handler(wifi_handle handle, int cmd);
    106 void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd);
    107 
    108 wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd);
    109 WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id);
    110 void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd);
    111 
    112 interface_info *getIfaceInfo(wifi_interface_handle);
    113 wifi_handle getWifiHandle(wifi_interface_handle handle);
    114 hal_info *getHalInfo(wifi_handle handle);
    115 hal_info *getHalInfo(wifi_interface_handle handle);
    116 wifi_handle getWifiHandle(hal_info *info);
    117 wifi_interface_handle getIfaceHandle(interface_info *info);
    118 
    119 
    120 // some common macros
    121 
    122 #define min(x, y)       ((x) < (y) ? (x) : (y))
    123 #define max(x, y)       ((x) > (y) ? (x) : (y))
    124 
    125 #ifdef __cplusplus
    126 extern "C"
    127 {
    128 #endif /* __cplusplus */
    129 void hexdump(char *bytes, u16 len);
    130 #ifdef __cplusplus
    131 }
    132 #endif /* __cplusplus */
    133 
    134 #endif
    135 
    136