1/* 2 * LICENSE NOTICE. 3 * 4 * Use of the Microsoft Windows Rally Development Kit is covered under 5 * the Microsoft Windows Rally Development Kit License Agreement, 6 * which is provided within the Microsoft Windows Rally Development 7 * Kit or at http://www.microsoft.com/whdc/rally/rallykit.mspx. If you 8 * want a license from Microsoft to use the software in the Microsoft 9 * Windows Rally Development Kit, you must (1) complete the designated 10 * "licensee" information in the Windows Rally Development Kit License 11 * Agreement, and (2) sign and return the Agreement AS IS to Microsoft 12 * at the address provided in the Agreement. 13 */ 14 15/* 16 * Copyright (c) Microsoft Corporation 2005. All rights reserved. 17 * This software is provided with NO WARRANTY. 18 */ 19 20/* This is both the definition and the declaration of all global variables */ 21 22#include <stdio.h> 23 24//#define __DEBUG__ 25#define CAN_FOPEN_IN_SELECT_LOOP 1 26#define USING_UNAME 27 28#include <inttypes.h> /* for uint8_t, uint16_t etc */ 29#include <sys/time.h> /* for timeval */ 30#include <sys/types.h> /* for size_t */ 31#include <arpa/inet.h> /* for in6addr, htons(), and friends */ 32 33#define TRUE 1 34#define FALSE 0 35 36#ifdef __ARM_PIKA__ 37// std function memcpy() fails on earliest ARM architectures (as used in Pika reference platform), 38// whenever the span is divisible by 4 and the source or destination address is not aligned to 4-bytes... 39#define memcpy(pDest, pSrc, cnt) {int i; for (i=0;i<(int)cnt;i++) ((uint8_t*)(pDest))[i] = ((uint8_t*)(pSrc))[i];} 40#define FMT_SIZET "%ld" 41#else 42#define FMT_SIZET "%d" 43#endif 44 45#ifdef __ARM_PIKA_PAL__ 46// Microsoft Pika Platform Abstraction Layer (PAL) definitions 47#include "../rmpal/include/rmpaltypes.h" 48#include "../rmpal/include/rmpalexec.h" 49#include "../rmpal/include/rmpalsocket.h" 50#define FMT_UINT32 "%lu" 51#define FMT_UINT16 "%u" 52#else 53typedef unsigned long bool_t; 54#define FMT_UINT32 "%u" 55#define FMT_UINT16 "%u" 56#endif 57 58#include "lld2d_types.h" 59#include "osl.h" 60 61#include "band.h" 62#include "seeslist.h" 63 64#define JFFS_ICON_PATH "/jffs/usericon/" 65//#define TMP_ICON_PATH "/tmp/" 66#define TMP_ICON_PATH "/jffs/usericon/" 67 68#ifndef GLOBALS_H 69#define GLOBALS_H 70 71#ifdef DECLARING_GLOBALS 72#define GLOBAL 73char releaseVersion[] = {"RELEASE 1.2"}; 74#else 75#define GLOBAL extern 76#endif 77 78 79typedef struct IconFile { 80 char name[12]; 81 struct IconFile *next; 82}IconFile; 83 84typedef struct MacInfo { 85 etheraddr_t MacAddr; 86 int getIcon; 87 int query; 88 struct MacInfo *next; 89}MacInfo; 90 91GLOBAL char *g_Progname; 92GLOBAL char *g_interface; /* name of interface */ 93GLOBAL char *g_wl_interface; /* name of wireless interface (may be different) */ 94GLOBAL char g_buf[160]; /* parse buffer for /proc/.... things */ 95GLOBAL etheraddr_t g_hwaddr; /* MAC address of this interface */ 96 97GLOBAL uint g_trace_flags; /* which subsystems to trace */ 98 99GLOBAL smE_state_t g_smE_state; 100GLOBAL smT_state_t g_smT_state; 101 102GLOBAL protocol_event_t g_this_event; /* input to state machines, to drive transitions */ 103 104#define MAX_NUM_SESSIONS 11 105GLOBAL session_t g_sessions[MAX_NUM_SESSIONS]; /* sessions started by Discover msgs (either quick or topo) */ 106GLOBAL session_t *g_topo_session; /* the unique session that can do emits, etc... */ 107GLOBAL tlv_info_t g_info; /* useful info about the interface and machine (TLV data) */ 108GLOBAL char *g_icon_path; 109GLOBAL char *g_jumbo_icon_path; 110GLOBAL band_t g_band; /* BAND algorthm's state */ 111 112GLOBAL osl_t *g_osl; /* OS-Layer state */ 113 114 /* network receive / transmit context - many of these are macro'd for brevity */ 115 116#define RXBUFSZ 2048 117#define TXBUFSZ 2048 118GLOBAL uint8_t g_rxbuf[RXBUFSZ]; /* fixed buffer we receive packets into */ 119GLOBAL uint8_t g_txbuf[TXBUFSZ]; /* fixed buffer we transmit packets from */ 120GLOBAL uint8_t g_re_txbuf[TXBUFSZ]; /* alternate tx buffer for retransmission from */ 121GLOBAL size_t g_rcvd_pkt_len; /* how many bytes of rxbuf are valid */ 122GLOBAL uint16_t g_rtxseqnum; /* which sequence number rtxbuf holds (or 0) */ 123GLOBAL size_t g_tx_len; /* how many bytes of txbuf were sent, sequenced or not */ 124GLOBAL size_t g_re_tx_len; /* how many bytes of rtxbuf are valid - sequenced, only */ 125GLOBAL uint8_t g_re_tx_opcode; /* last sequenced-request opcode */ 126GLOBAL int g_rcvd_icon_len; /* Yau add how many bytes of icon are saved */ 127GLOBAL int g_discover_count; /* Yau add to exit if no response */ 128GLOBAL FILE *g_icon_fd; /* Yau Add to store icon */ 129 130/* packet pointers and information, hoisted here for fast access */ 131GLOBAL topo_ether_header_t *g_ethernet_hdr; /* pointer to ethernet header in rxbuf */ 132GLOBAL topo_base_header_t *g_base_hdr; /* pointer to base header in rxbuf */ 133GLOBAL topo_discover_header_t *g_discover_hdr; /* pointer to discover header in rxbuf */ 134GLOBAL topo_hello_header_t *g_hello_hdr; /* pointer to hello header in rxbuf */ 135GLOBAL topo_qltlv_header_t *g_qltlv_hdr; /* pointer to query-large-tlv header in rxbuf */ 136 137GLOBAL uint16_t g_generation; /* generation we've sent in Hello, or learnt */ 138GLOBAL uint16_t g_sequencenum; /* sequence number from base hdr in rxbuf */ 139GLOBAL uint g_opcode; /* opcode from base header in rxbuf, expanded to uint */ 140 141/* Porting note: When the program was moved to a WRT54GS v4 box, it could no longer do the 142 * fopen() call in the get_hostid() routine (in osl-linux), and would hang there... 143 * subsequent testing showed that fopen would hang anywhere inside the main select loop. 144 * To fix this, we simply moved the fopen into the initialization in main.c, and left the 145 * stream pointer in the global (g_procnetdev) shown below. */ 146#if CAN_FOPEN_IN_SELECT_LOOP 147 /* then we don't need a global to keep the stream open all the time...*/ 148#else 149GLOBAL FILE *g_procnetdev; 150#endif 151 152 /* Current Transmit Credit (CTC), and needs for this event's response */ 153GLOBAL uint32_t g_ctc_packets; 154GLOBAL uint32_t g_ctc_bytes; 155GLOBAL uint32_t g_totalPause; 156GLOBAL uint32_t g_neededPackets; 157GLOBAL uint32_t g_neededBytes; 158 159 160 /* Emit state */ 161GLOBAL uint8_t g_emitbuf[RXBUFSZ]; /* buffer to hold emitee_descs */ 162GLOBAL uint16_t g_emit_remaining; /* number of emitee_descs left in buf */ 163GLOBAL uint16_t g_emit_seqnum; /* seqnum for ACK when all done */ 164GLOBAL topo_emitee_desc_t *g_emitdesc; /* next emitee_desc to process */ 165 166 /* circular buffer of recvee_desc_t */ 167GLOBAL topo_seeslist_t *g_sees; 168 169 /* timers; NULL if not running */ 170GLOBAL event_t *g_block_timer; 171GLOBAL event_t *g_charge_timer; 172GLOBAL event_t *g_emit_timer; 173GLOBAL event_t *g_hello_timer; 174 175/* flags for subsystems to trace: */ 176#define TRC_BAND 0x01 177#define TRC_PACKET 0x02 178#define TRC_CHARGE 0x04 179#define TRC_TLVINFO 0x08 180#define TRC_STATE 0x10 181#define TRC_QOS 0x20 182 183#define TRACE(x) (g_trace_flags & x) 184 185#ifdef __DEBUG__ 186#define IF_TRACED(f) if(g_trace_flags & f){ 187#else 188#define IF_TRACED(f) if (0){ 189#endif 190#define END_TRACE } 191 192#ifdef __DEBUG__ 193#define DEBUG(x) x 194 195#define IF_DEBUG { 196#else 197#define DEBUG(x) 198#define IF_DEBUG if (0){ 199#endif 200#define END_DEBUG } 201 202/************************************** Q O S G l o b a l s **************************************/ 203#include "qosglobals.h" 204 205#endif /*** GLOBALS_H ***/ 206