📄 intprismbridge.c
字号:
/* intPrismBridge.c - Simple bridging code for WLAN APs *//* Copyright 2002-2003 Wind River Systems, Inc. *//*modification history--------------------01k,09may03,rb Removed warnings caused by IPv6 integration01j,29apr03,rb Demoted error message for dot1X rejections01i,26feb03,ss Fixed diab compiler warnings01h,17may02,rb Fixed bug preventing FTP to bridge01g,16may02,rb Demoted INFO messages to FLOOD01f,06may02,rb More comment fixes01e,03may02,rb Updated comments as per doc review01d,27mar02,rb Moved EAPOL code from wired to wireless rx rtn01c,26mar02,rb Added code to pass EAPOL packets up the RX stack01b,21mar02,rb Removed restriction against Stormpad since problem fixed in Host AP01a,11mar02,rb Created*//*DESCRIPTIONThis library contains a basic bridge. It is not a learning bridge, such as may be found in Tornado for Home Gateways, but rather implements a more basic algorithm that allows bridging of packets from wired to wireless. Any more advanced filtering, such as that required by IEEE 802.11b Section 5.4.1.1 isperformed by the AP at this time (see intPrismHostAp.c or Intersil Driver Programmers Manual)The operation of the bridge is very basic. It maintains two interfaces, a wired and a wireless interface. If a packet comes in on the wireless interface, it is bridged (copied) to the wired interface. Likewise, if a packet comes in on the wired interface, it is copied to the wireless interface. The exception to this is that if an IP or ARP packet is received from either interface, the destination IP address is examined to determineif it is meant for the bridge itself. If it is, it is passed up the MUX receive stack without being copied to the other interface. Replies to messages directed at the bridge are simply sent out both interfaces - to determine which interface to send to would require developing a learning bridge.To achieve this functionality, three protocols must be implemented. The firsttwo are SNARF protocols on both the wired and wireless that intercept packetsreceived on the interface they're attached to, and send it to the other interface unless it is desined for the bridge. The third is an output protocol that examines outgoing IP and ARP packets. If the source IP address is that of the bridge, then the packet is copied to the wireless send as well.RESTRICTIONThe interface refered to as "wired" must be attached to the IP stack, while the interface refered to as "wireless" must NOT be attached to the IP stack*/#include <vxWorks.h>#include <semLib.h>#include <logLib.h>#include <netLib.h> #include <stdio.h>#include <end.h> /* Common END structures. */#include <endLib.h>#include <inetLib.h>#include <netinet/if_ether.h>#include <ifLib.h>#include <string.h>/* Custom header files */#include "wrn/wlan/wlanEnd.h"#include "wrn/wlan/intPrismHw.h"/* These global variables store the pCookie returned by muxBind to each interface. These are needed to send data to the interfaces. */LOCAL void * pIPBWirelessCookie = NULL;LOCAL void * pIPBWiredCookie = NULL;LOCAL END_OBJ * pWiredEnd; /* Store the IP address of the bridge */LOCAL char IPBWiredIPAddr[INET_ADDR_LEN];LOCAL char IPBWiredMACAddr[WLAN_ENET_ADDR_LEN];LOCAL char IPBWirelessMACAddr[WLAN_ENET_ADDR_LEN];LOCAL BOOL intPrismBridgeWiredTxRtn (void * pCookie, long type, M_BLK_ID pNetBuffer, LL_HDR_INFO * pLinkHeader, void * pSpare );LOCAL BOOL intPrismBridgeWiredRcvRtn (void * pCookie, long type, M_BLK_ID pNetBuffer, LL_HDR_INFO * pLinkHeader, void * pSpare );LOCAL BOOL intPrismBridgeWirelessRcvRtn (void * pCookie, long type, M_BLK_ID pNetBuffer, LL_HDR_INFO * pLinkHeader, void * pSpare );LOCAL void intPrismBridgeErrorRtn (END_OBJ * pEnd, END_ERR * pError, void * pSpare);LOCAL STATUS intPrismBridgeRestartRtn (void * pCookie, void * pSpare);LOCAL STATUS intPrismBridgeShutdownRtn (void * pCookie, void * pSpare);#define WLAN_ETHERTYPE_OFFSET 2 * WLAN_ENET_ADDR_LEN#define WLAN_SRC_IP_OFFSET WLAN_EH_SIZE + 12#define WLAN_DST_IP_OFFSET WLAN_EH_SIZE + 16#define WLAN_SRC_MAC_OFFSET WLAN_ENET_ADDR_LEN#define WLAN_DST_MAC_OFFSET 0#define WLAN_ARP_TGT_OFFSET WLAN_EH_SIZE + 24/******************************************************************************* intPrismBridgeOn - turn on network interface bridging* * This routine will perform a muxBind to the wired interface and the* wireless interface. This will effectively* allow all network traffic received by the two interfaces to be copied to* this module** RETURNS: OK if the bind calls were successful, else ERROR* ERRNRO: N/A*/STATUS intPrismBridgeOn ( char * wirelessIf, /* Text name of wireless interface */ int wirelessIfnum, /* Unit number of WLAN driver to use */ char * wiredIf, /* Text name of wireless interface */ int wiredIfnum /* Unit number of WLAN driver to use */ ) { char temp[256]; /* Buffer for concatenating strings */ char ipAddr[INET_ADDR_LEN]; if ((wirelessIf == NULL) || (wirelessIf[0] == 0x00) || (wiredIf == NULL) || (wiredIf[0] == 0x00) ) { WLAN_DEBUG(DEBUG_ERROR, ("intPrismBridgeOn: NULL interface name\n")); return ERROR; } /* Try getting the IP address of the wireless interface. This should return ERROR, since we don't want the wireless interface to be attached to the IP stack */ sprintf(temp, "%s%d", wirelessIf, wirelessIfnum); if (ifAddrGet(temp, ipAddr) != ERROR) { WLAN_DEBUG(DEBUG_ERROR, ("intPrismBridgeOn: Wireless interface should" " not be attached to the IP stack for basic " "bridging. Use ipDetach() to remove it\n")); return ERROR; } /* Now verify that the wired interface IS attached to the IP stack, and save the address as the address of the bridge */ sprintf(temp, "%s%d", wiredIf, wiredIfnum); if (ifAddrGet(temp, IPBWiredIPAddr) == ERROR) { WLAN_DEBUG(DEBUG_ERROR, ("intPrismBridgeOn: Wired interface should" " be attached to the IP stack for basic " "bridging. Use ipAttach() to add it\n")); return ERROR; } /* bind a set of routines to the wireless interface */ pIPBWirelessCookie = muxBind(wirelessIf, wirelessIfnum, (FUNCPTR) intPrismBridgeWirelessRcvRtn, (FUNCPTR) intPrismBridgeShutdownRtn, (FUNCPTR) intPrismBridgeRestartRtn, (VOIDFUNCPTR) intPrismBridgeErrorRtn, MUX_PROTO_SNARF, "intPrism Bridge: Wireless", NULL); if (pIPBWirelessCookie == NULL) { WLAN_DEBUG(DEBUG_ERROR, ("intPrismBridgeOn: muxBind to wireless " "interface failed\n")); return ERROR; } /* bind a set of routines to the wiredinterface */ pIPBWiredCookie = muxBind(wiredIf, wiredIfnum, (FUNCPTR)intPrismBridgeWiredRcvRtn, (FUNCPTR)intPrismBridgeShutdownRtn, (FUNCPTR)intPrismBridgeRestartRtn, (VOIDFUNCPTR)intPrismBridgeErrorRtn, MUX_PROTO_SNARF, "intPrism Bridge: Wired", NULL); if (pIPBWiredCookie == NULL) { WLAN_DEBUG(DEBUG_ERROR, ("intPrismBridgeOn: muxBind to %s failed\n", wiredIf)); /* Packet not consumed - pass up stack */ return ERROR; } if (muxBind(wiredIf, wiredIfnum, (FUNCPTR)intPrismBridgeWiredTxRtn, (FUNCPTR)intPrismBridgeShutdownRtn, (FUNCPTR)intPrismBridgeRestartRtn, (VOIDFUNCPTR)intPrismBridgeErrorRtn, MUX_PROTO_OUTPUT, "intPrism Bridge: Wired output filter", NULL) == NULL) { WLAN_DEBUG(DEBUG_ERROR, ("intPrismBridgeOn: muxBind for wiredTx" " failed")); return ERROR; } /* place the wired interface into promiscuous mode */ sprintf(temp, "%s%d", wiredIf, wiredIfnum); ifFlagChange(temp, IFF_PROMISC, TRUE); sprintf(temp, "%s%d", wirelessIf, wirelessIfnum); ifFlagChange(temp, IFF_PROMISC, TRUE); pWiredEnd = endFindByName(wiredIf,wiredIfnum); /* Get the MAC address of the wired side */ muxIoctl(pIPBWiredCookie, EIOCGADDR, IPBWiredMACAddr); /* Get the MAC address of the wireless side */ muxIoctl(pIPBWirelessCookie, EIOCGADDR, IPBWirelessMACAddr); WLAN_DEBUG(DEBUG_ERROR, ("intPrismBridgeOn: Basic bridge enabled with IP" " address %s. Wired I/F = %s%d Wireless I/F " "= %s%d\n", IPBWiredIPAddr, wiredIf, wiredIfnum, wirelessIf, wirelessIfnum)); return OK; }/******************************************************************************* intPrismBridgeWiredTxRtn- Transmit filter for wired device* * This protocol sniffs packets being transmitted by the wired device, * immediatly before they are sent to the device's transmit routine. If the* source address is that of the bridge, then the packets are also copied to * the wireless device's send routine.* * ** RETURNS: TRUE if the packet was successfully sent onto the wired interface* ERRNO: N/A*/LOCAL BOOL intPrismBridgeWiredTxRtn ( void * pCookie, /* returned by muxBind() */ long type, /* from RFC1700, or user-defined */ M_BLK_ID pNetBuffer, /* packet with link-level info */ LL_HDR_INFO * pLinkHeader, /* link-level header info structure */ void * pSpare /* defined on a per-protocol basis */ ) { UINT8 * pPacket; M_BLK_ID pPacketCopy = NULL; if ( (pIPBWiredCookie == NULL) || (pIPBWirelessCookie == NULL) ) { WLAN_DEBUG(DEBUG_ERROR, ("intPrismBridgeWiredTxRtn: Error - no" " ref to wired or wireless cookie\n")); return FALSE; } pPacket = (UINT8 *)pNetBuffer->mBlkHdr.mData; /* Traffic from the bridge should be copied to both interfaces, since we
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -