1/* 2 * ACSD shared include file 3 * 4 * Copyright (C) 2012, Broadcom Corporation 5 * All Rights Reserved. 6 * 7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation; 8 * the contents of this file may not be disclosed to third parties, copied 9 * or duplicated in any form, in whole or in part, without the prior 10 * written permission of Broadcom Corporation. 11 * 12 * $Id: acsd.h 394886 2013-04-04 02:48:41Z $ 13 */ 14 15#ifndef _acsd_h_ 16#define _acsd_h_ 17 18#include <stdio.h> 19#include <stdlib.h> 20#include <unistd.h> 21#include <string.h> 22#include <errno.h> 23 24#include <assert.h> 25#include <typedefs.h> 26#include <bcmnvram.h> 27#include <bcmutils.h> 28#include <bcmtimer.h> 29#include <bcmendian.h> 30 31#include <shutils.h> 32#include <bcmendian.h> 33#include <bcmwifi_channels.h> 34#include <wlioctl.h> 35#include <wlutils.h> 36 37#include <security_ipc.h> 38#include <sys/socket.h> 39#include <netinet/in.h> 40#include <net/if.h> 41#include <arpa/inet.h> 42 43#include "acs_dfsr.h" 44 45#define ACSD_DEBUG_ERROR 0x0001 46#define ACSD_DEBUG_WARNING 0x0002 47#define ACSD_DEBUG_INFO 0x0004 48#define ACSD_DEBUG_DETAIL 0x0008 49#define ACSD_DEBUG_CHANIM 0x0010 50#define ACSD_DEBUG_FCS 0x0020 51#define ACSD_DEBUG_DFSR 0x0040 52 53#define ACSD_VERSION 1 54#define ACSD_DFLT_FD -1 55#define ACSD_DFLT_CLI_PORT 5916 /* need to double check if it is used */ 56 57extern bool acsd_swap; 58#define htod32(i) (acsd_swap?bcmswap32(i):(uint32)(i)) 59#define htod16(i) (acsd_swap?bcmswap16(i):(uint16)(i)) 60#define dtoh32(i) (acsd_swap?bcmswap32(i):(uint32)(i)) 61#define dtoh16(i) (acsd_swap?bcmswap16(i):(uint16)(i)) 62#define htodchanspec(i) (acsd_swap?htod16(i):i) 63#define dtohchanspec(i) (acsd_swap?dtoh16(i):i) 64#define htodenum(i) (acsd_swap?((sizeof(i) == 4) ? \ 65 htod32(i) : ((sizeof(i) == 2) ? htod16(i) : i)):i) 66#define dtohenum(i) (acsd_swap?((sizeof(i) == 4) ? \ 67 dtoh32(i) : ((sizeof(i) == 2) ? htod16(i) : i)):i) 68 69#define acsddbg(fmt, args...) do { FILE *fp = fopen("/dev/console", "w"); if (fp) { fprintf(fp, fmt, ## args); fclose(fp); } else fprintf(stderr, fmt, ## args); } while (0) 70#define acsddbG(fmt, args...) acsddbg(fmt, ##args) 71 72extern int acsd_debug_level; 73#define ACSD_ERROR(fmt, arg...) \ 74 do { acsddbG("ACSD >>%s(%d): "fmt, __FUNCTION__, __LINE__, ##arg); } while (0) 75 76#define ACSD_WARNING(fmt, arg...) \ 77 do { acsddbG("ACSD >>%s(%d): "fmt, __FUNCTION__, __LINE__, ##arg); } while (0) 78 79#define ACSD_INFO(fmt, arg...) \ 80 do { acsddbG("ACSD >>%s(%d): "fmt, __FUNCTION__, __LINE__, ##arg); } while (0) 81 82#define ACSD_DEBUG(fmt, arg...) \ 83 do { acsddbG("ACSD >>%s(%d): "fmt, __FUNCTION__, __LINE__, ##arg); } while (0) 84 85#define ACSD_CHANIM(fmt, arg...) \ 86 do { acsddbG("ACSD >>%s(%d): "fmt, __FUNCTION__, __LINE__, ##arg); } while (0) 87 88#define ACSD_FCS(fmt, arg...) \ 89 do { acsddbG("ACSD >>%s(%d): "fmt, __FUNCTION__, __LINE__, ##arg); } while (0) 90 91#define ACSD_DFSR(fmt, arg...) \ 92 do { acsddbG("ACSD >>%s(%d): "fmt, __FUNCTION__, __LINE__, ##arg); } while (0) 93 94#define ACSD_PRINT(fmt, arg...) \ 95 do { acsddbG("acsd: "fmt, ##arg); logmessage("acsd", fmt, ##arg); } while (0) 96 97#define HERE ACSD_ERROR("trace\n") 98 99#define ACS_FREE(data_ptr) \ 100 do { \ 101 if (data_ptr) \ 102 free(data_ptr); \ 103 data_ptr = NULL; \ 104 } while (0) 105 106#define ACS_ERR(ret, string) \ 107 do { \ 108 if (ret < 0) { \ 109 ACSD_ERROR(string "ret code: %d\n", ret); \ 110 return ret; \ 111 } \ 112 } while (0) 113 114#define SSID_FMT_BUF_LEN 4*32+1 /* Length for SSID format string */ 115 116/* other bss info derived from scan result */ 117typedef struct acs_chan_bssinfo { 118 uint8 channel; 119 uint8 aAPs; /* # of 20MHz LG/HT/VHT BSSs seen in 5G band */ 120 uint8 bAPs; /* # of 20MHz 11b BSSs seen in 2.4G band */ 121 uint8 gAPs; /* # of 20MHz LG/HT BSSs seen in 2.4G band */ 122 uint8 lSBs; /* # of 40MHz HT/VHT BSSs using this as "lower" ctl channel */ 123 uint8 uSBs; /* # of 40MHz HT/VHT BSSs using this as "upper" ctl channel */ 124 uint8 nEXs; /* # of 40MHz HT/VTH BSSs using this as extension channel */ 125 uint8 llSBs; /* # of 80MHz VHT BSSs using this as LL ctl channel */ 126 uint8 luSBs; /* # of 80MHz VHT BSSs using this as LU ctl channel */ 127 uint8 ulSBs; /* # of 80MHz VHT BSSs using this as UL ctl channel */ 128 uint8 uuSBs; /* # of 80MHz VHT BSSs using this as UU ctl channel */ 129 uint8 wEX20s; /* # of 80MHz VHT BSSs using this as 20MHz extension */ 130 uint8 wEX40s; /* # of 80MHz VHT BSSs using this as (one side of) 40MHz extension */ 131} acs_chan_bssinfo_t; 132 133typedef struct acs_channel { 134 uint8 control; 135 uint8 ext20; 136 uint8 ext40[2]; 137} acs_channel_t; 138 139typedef struct ch_score { 140 int score; 141 int weight; 142} ch_score_t; 143 144#define CH_SCORE_BSS 0 /* number of bss */ 145#define CH_SCORE_BUSY 1 /* channel occupancy */ 146#define CH_SCORE_INTF 2 /* interference */ 147#define CH_SCORE_INTFADJ 3 /* interference adjustment, include neighboring channels */ 148#define CH_SCORE_FCS 4 /* FCS */ 149#define CH_SCORE_TXPWR 5 /* TX pwr consideration */ 150#define CH_SCORE_BGNOISE 6 151#define CH_SCORE_TOTAL 7 152#define CH_SCORE_CNS 8 153/* adjacent channel score(number of bss's using the adjacent channel spec) */ 154#define CH_SCORE_ADJ 9 155#define CH_SCORE_MAX 10 156 157#define ACS_INVALID_COEX 0x1 158#define ACS_INVALID_INTF_CCA 0x2 159#define ACS_INVALID_INTF_BGN 0x4 160#define ACS_INVALID_OVLP 0x8 161#define ACS_INVALID_NOISE 0x10 162#define ACS_INVALID_ALIGN 0x20 163#define ACS_INVALID_144 0x40 164#define ACS_INVALID_DFS 0x80 165#define ACS_INVALID_CHAN_FLOP_PERIOD 0x100 166#define ACS_INVALID_EXCL 0x200 167#define ACS_INVALID_SKIP 0x400 168 169#define ACSD_BUFSIZE_4K 4096 170 171typedef struct ch_candidate { 172 chanspec_t chspec; 173 bool valid; 174 bool is_dfs; 175 uint16 reason; 176 uint8 in_use; /* number of bss's using the identical channel spec */ 177 ch_score_t chscore[CH_SCORE_MAX]; 178} ch_candidate_t; 179 180/* all the policy related configuration goes here */ 181extern int acs_safe_get_conf(char *outval, int outval_size, char *name); 182extern void dump_networks(char *network_buf); 183extern char * acsd_malloc(int bufsize); 184extern void sleep_ms(const unsigned int ms); 185extern int swrite(int fd, char *buf, unsigned int size); 186extern int sread(int fd, char *buf, unsigned int size); 187extern void acs_dump_score(ch_score_t* score_p); 188extern int wl_format_ssid(char* ssid_buf, uint8* ssid, int ssid_len); 189extern char *wl_ether_etoa(const struct ether_addr *n); 190extern long uptime(void); 191#endif /* _acsd_h_ */ 192