diff options
Diffstat (limited to 'c/src/lib/libbsp/arm/nds/wifi')
-rw-r--r-- | c/src/lib/libbsp/arm/nds/wifi/compat.c | 219 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/nds/wifi/compat.h | 114 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/nds/wifi/wifi.c | 414 |
3 files changed, 0 insertions, 747 deletions
diff --git a/c/src/lib/libbsp/arm/nds/wifi/compat.c b/c/src/lib/libbsp/arm/nds/wifi/compat.c deleted file mode 100644 index 0509a1169e..0000000000 --- a/c/src/lib/libbsp/arm/nds/wifi/compat.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * RTEMS for Nintendo DS sgIP compatibility glue. - * - * Copyright (c) 2008 by Matthieu Bucchianeri <mbucchia@gmail.com> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * - * http://www.rtems.org/license/LICENSE - */ - -#include <rtems.h> -#include <stdlib.h> - -#include <sys/mbuf.h> -#undef malloc -#undef free - -#include "compat.h" - -unsigned long sgIP_timems = 0; -static sgIP_Hub_HWInterface hw; - -/* - * Dswifi stub functions - */ - -void * -sgIP_malloc (int size) -{ - return malloc (size); -} - -void -sgIP_free (void *ptr) -{ - free (ptr); -} - -/* - * called by dswifi on initialization - */ - -void -sgIP_Init (void) -{ -} - -/* - * network layer stack timer called periodically - */ - -void -sgIP_Timer (int num_ms) -{ - sgIP_timems += num_ms; -} - -/* - * add a new hardware interface - * should be called once - */ - -sgIP_Hub_HWInterface * -sgIP_Hub_AddHardwareInterface (int (*TransmitFunction) - (sgIP_Hub_HWInterface *, sgIP_memblock *), - int (*InterfaceInit) (sgIP_Hub_HWInterface *)) -{ - hw.TransmitFunction = TransmitFunction; - if (InterfaceInit) - InterfaceInit (&hw); - - return &hw; -} - -/* - * callback on packet reception - * translate memblock to mbuf - */ - -extern void wifi_signal (struct mbuf *); -int -sgIP_Hub_ReceiveHardwarePacket (sgIP_Hub_HWInterface * hw, - sgIP_memblock * packet) -{ - struct mbuf *m; - unsigned char *p; - - /* reserve the mbuf */ - MGETHDR (m, M_WAIT, MT_DATA); - MCLGET (m, M_WAIT); - - /* copy data to mbuf */ - p = mtod (m, unsigned char *); - m->m_len = m->m_pkthdr.len = packet->thislength; - memcpy (p, packet->datastart, packet->thislength); - - /* free the memblock */ - sgIP_memblock_free (packet); - - /* signal packet arrival to the driver */ - wifi_signal (m); - - return 0; -} - -/* - * function for sending a packet (translates mbuf to memblock) - */ - -void -compat_wifi_output (struct mbuf *m) -{ - sgIP_memblock *packet; - size_t size = 0; - struct mbuf *l; - - /* compute total size of the packet */ - for (l = m; l != NULL; l = l->m_next) - size += l->m_len; - - /* allocate memblock */ - packet = sgIP_memblock_allocHW (14, size - 14); - - /* copy data from mbuf to memblock */ - m_copydata (m, 0, size, packet->datastart); - - /* call TransmitFunction */ - hw.TransmitFunction (&hw, packet); - - /* free mbuf */ - m_freem (m); -} - -/* - * allocate a memblock - */ - -sgIP_memblock * -sgIP_memblock_allocHW (int headersize, int packetsize) -{ - sgIP_memblock *mb; - mb = - (sgIP_memblock *) sgIP_malloc (SGIP_MEMBLOCK_HEADERSIZE + - SGIP_MAXHWHEADER + packetsize); - if (!mb) - return 0; - mb->totallength = headersize + packetsize; - mb->thislength = mb->totallength; - mb->datastart = mb->reserved + SGIP_MAXHWHEADER - headersize; - mb->next = 0; - return mb; -} - -/* - * release a memblock - */ - -void -sgIP_memblock_free (sgIP_memblock * mb) -{ - sgIP_memblock *f; - return; - SGIP_INTR_PROTECT (); - while (mb) { - mb->totallength = 0; - mb->thislength = 0; - f = mb; - mb = mb->next; - - sgIP_free (f); - } - - SGIP_INTR_UNPROTECT (); -} - -/* - * start DHCP discovery - */ - -void -sgIP_DHCP_Start (sgIP_Hub_HWInterface * interface, int getDNS) -{ -} - -/* - * get DHCP state - */ - -int -sgIP_DHCP_Update (void) -{ - return SGIP_DHCP_STATUS_SUCCESS; -} - -/* ----------------- not my problem things ---------------- */ - -/* flush ARP table */ -void -sgIP_ARP_FlushInterface (sgIP_Hub_HWInterface * hw) -{ -} - -/* send a ARP new IP notification */ -int -sgIP_ARP_SendGratARP (sgIP_Hub_HWInterface * hw) -{ - return 0; -} - -/* ----------------- unused things ------------------------ */ - -sgIP_DNS_Record * -sgIP_DNS_GetUnusedRecord (void) -{ - static sgIP_DNS_Record rec; - - return &rec; /* we must return a valid record even if not used */ -} diff --git a/c/src/lib/libbsp/arm/nds/wifi/compat.h b/c/src/lib/libbsp/arm/nds/wifi/compat.h deleted file mode 100644 index 5dd7137ee5..0000000000 --- a/c/src/lib/libbsp/arm/nds/wifi/compat.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * RTEMS for Nintendo DS sgIP compatibility header. - * - * Copyright (c) 2008 by Matthieu Bucchianeri <mbucchia@gmail.com> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * - * http://www.rtems.org/license/LICENSE - */ - -#ifndef COMPAT_H_ -#define COMPAT_H_ - -#include <rtems.h> - -/* --------------- unused things --------------------- */ - -#define SGIP_DNS_FLAG_ACTIVE 1 -#define SGIP_DNS_FLAG_RESOLVED 2 -#define SGIP_DNS_FLAG_BUSY 4 -#define SGIP_DNS_MAXRECORDADDRS 4 -#define SGIP_DNS_MAXALIASES 4 - -typedef struct SGIP_DNS_RECORD -{ - char name[256]; - char aliases[SGIP_DNS_MAXALIASES][256]; - unsigned char addrdata[SGIP_DNS_MAXRECORDADDRS * 4]; - short addrlen; - short addrclass; - int numaddr, numalias; - int TTL; - int flags; -} sgIP_DNS_Record; - - -/* -------------------------- */ - -#define SGIP_DEBUG_MESSAGE(param) -#define SGIP_DEBUG_ERROR(param) - - - -#define SGIP_MAXHWADDRLEN 8 -#define SGIP_MEMBLOCK_DATASIZE 1600 - - - -#define SGIP_MAXHWHEADER 16 - - -#define SGIP_MEMBLOCK_HEADERSIZE 16 -#define SGIP_MEMBLOCK_INTERNALSIZE (SGIP_MEMBLOCK_DATASIZE-16) -#define SGIP_MEMBLOCK_FIRSTINTERNALSIZE (SGIP_MEMBLOCK_DATASIZE-16-SGIP_MAXHWHEADER) -#define SGIP_INTR_PROTECT() -#define SGIP_INTR_REPROTECT() -#define SGIP_INTR_UNPROTECT() -#define SGIP_WAITEVENT(); - -typedef struct SGIP_MEMBLOCK -{ - int totallength; - int thislength; - struct SGIP_MEMBLOCK *next; - char *datastart; - char reserved[SGIP_MEMBLOCK_DATASIZE - 16]; // assume the other 4 values are 16 bytes total in length. -} sgIP_memblock; - -typedef struct SGIP_HUB_HWINTERFACE -{ - unsigned short flags; - unsigned short hwaddrlen; - int MTU; - int (*TransmitFunction) (struct SGIP_HUB_HWINTERFACE *, sgIP_memblock *); - void *userdata; - unsigned long ipaddr, gateway, snmask, dns[3]; - unsigned char hwaddr[SGIP_MAXHWADDRLEN]; -} sgIP_Hub_HWInterface; - -enum SGIP_DHCP_STATUS -{ - SGIP_DHCP_STATUS_IDLE, - SGIP_DHCP_STATUS_WORKING, - SGIP_DHCP_STATUS_FAILED, - SGIP_DHCP_STATUS_SUCCESS -}; - -extern sgIP_Hub_HWInterface *wifi_hw; - - -/* prototypes */ - -sgIP_DNS_Record *sgIP_DNS_GetUnusedRecord (void); -void sgIP_DHCP_Start (sgIP_Hub_HWInterface * interface, int getDNS); -int sgIP_DHCP_Update (void); -int sgIP_ARP_SendGratARP (sgIP_Hub_HWInterface * hw); -void sgIP_Init (void); -void sgIP_Timer (int num_ms); -sgIP_Hub_HWInterface - *sgIP_Hub_AddHardwareInterface (int (*TransmitFunction) - (sgIP_Hub_HWInterface *, sgIP_memblock *), - int (*InterfaceInit) (sgIP_Hub_HWInterface - *)); - -int sgIP_Hub_ReceiveHardwarePacket (sgIP_Hub_HWInterface * hw, - sgIP_memblock * packet); -sgIP_memblock *sgIP_memblock_allocHW (int headersize, int packetsize); -void sgIP_memblock_free (sgIP_memblock * mb); -void sgIP_ARP_FlushInterface (sgIP_Hub_HWInterface * hw); - -extern unsigned long sgIP_timems; - -#endif diff --git a/c/src/lib/libbsp/arm/nds/wifi/wifi.c b/c/src/lib/libbsp/arm/nds/wifi/wifi.c deleted file mode 100644 index 791c1a9cf8..0000000000 --- a/c/src/lib/libbsp/arm/nds/wifi/wifi.c +++ /dev/null @@ -1,414 +0,0 @@ -/* - * RTEMS for Nintendo DS WiFi driver. - * - * Copyright (c) 2008 by Matthieu Bucchianeri <mbucchia@gmail.com> - * Benjamin Ratier <agho.pwn@gmail.com> - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * - * http://www.rtems.org/license/LICENSE - */ - -#include <bsp.h> - -#include <stdio.h> -#include <assert.h> -#include <errno.h> - -#include <rtems/error.h> -#include <rtems/rtems_bsdnet.h> - -#include <sys/param.h> -#include <sys/mbuf.h> -#include <sys/socket.h> -#include <sys/sockio.h> - -#include <net/if.h> - -#include <netinet/in.h> -#include <netinet/if_ether.h> - -#include <rtems/irq.h> - -#include <nds.h> -#include <dswifi9.h> - -/* - * RTEMS event number used by reception task to receive packet - */ - -#define RECEIVE_EVENT RTEMS_EVENT_1 - -/* - * RTEMS event number used to start the transmit daemon - */ - -#define TRANSMIT_EVENT RTEMS_EVENT_2 - -/* - * from compat.c - */ - -void compat_wifi_output (struct mbuf *m); - -/* - * wifi driver structure - */ - -static struct -{ - /* The bsdnet information structure */ - struct arpcom arpcom; - - /* indicate if the hwaddr is already set */ - uint8_t is_hwaddr_set; - - /* the thread ID of the transmit task */ - rtems_id tx_id; - /* the thread ID of the receive task */ - rtems_id rx_id; - - /* reception queue (filled in compat.c:ReceiveHardwarePacket) */ - struct ifqueue recvq; -} softc; - -static void -print_byte (unsigned char b) -{ - printk ("%x%x", b >> 4, b & 0x0f); -} - -/* - * wifi timer function, must be called every 50 ms - */ - -static void -Timer_50ms (void) -{ - Wifi_Timer (50); -} - -/* - * notification function to send fifo message to arm7 - */ - -static void -arm9_synctoarm7 (void) -{ - /* send fifo message */ - REG_IPC_FIFO_TX = 0x87654321; -} - -/* - * interrupt handler to receive fifo messages from arm7 - */ - -static void -arm9_fifo (void) -{ - u32 value = REG_IPC_FIFO_RX; - - /* check incoming fifo messages */ - if (value == 0x87654321) - Wifi_Sync (); -} - -/* - * signal an icoming packet - */ - -void -wifi_signal (struct mbuf *m) -{ - rtems_interrupt_level level; - - /* enqueue the incoming packet */ - rtems_interrupt_disable (level); - IF_ENQUEUE (&softc.recvq, m); - rtems_interrupt_enable (level); - - /* signal the rx daemon */ - rtems_bsdnet_event_send (softc.rx_id, RECEIVE_EVENT); -} - - -/* - * packet reception daemon - */ - -static void -wifi_rxd (void *arg) -{ - rtems_interrupt_level level; - struct ifnet *ifp = &softc.arpcom.ac_if; - - while (1) { - rtems_event_set events; - - rtems_bsdnet_event_receive (RECEIVE_EVENT, - RTEMS_WAIT | RTEMS_EVENT_ANY, - RTEMS_NO_TIMEOUT, &events); - - while (1) { - struct ether_header *eh; - struct mbuf *m; - - rtems_interrupt_disable (level); - if (softc.recvq.ifq_head == NULL) { - rtems_interrupt_enable (level); - break; - } - - /* get next packet */ - IF_DEQUEUE (&softc.recvq, m); - rtems_interrupt_enable (level); - if (m == NULL) { - panic ("wifi_rxd"); - } - - m->m_pkthdr.rcvif = ifp; - - /* extract ethernet header */ - eh = mtod (m, struct ether_header *); - m->m_data += sizeof (struct ether_header); - m->m_len = m->m_pkthdr.len = m->m_len - sizeof (struct ether_header); - - /* push the packet into the stack */ - ether_input (ifp, eh, m); - } - } -} - -/* - * packet sending daemon - */ - -static void -wifi_txd (void *arg) -{ - rtems_interrupt_level level; - struct ifnet *ifp = &softc.arpcom.ac_if; - - while (1) { - rtems_event_set events; - - rtems_bsdnet_event_receive (TRANSMIT_EVENT, - RTEMS_WAIT | RTEMS_EVENT_ANY, - RTEMS_NO_TIMEOUT, &events); - while (1) { - struct mbuf *m; - - rtems_interrupt_disable (level); - if (ifp->if_snd.ifq_head == NULL) { - ifp->if_flags &= ~IFF_OACTIVE; - rtems_interrupt_enable (level); - break; - } - - /* grab next packet */ - IF_DEQUEUE (&ifp->if_snd, m); - rtems_interrupt_enable (level); - - if (m == NULL) { - panic ("wifi_txd"); - } - - /* call compatibility glue to dswifi */ - compat_wifi_output (m); - } - } -} - -/* - * wifi device initialization procedure - */ - -static void -wifi_init (void *arg) -{ - struct ifnet *ifp = &softc.arpcom.ac_if; - int i; - - /* create the receive & send daemons */ - if (softc.tx_id == 0) { - Wifi_AutoConnect (); - - while (1) { - i = Wifi_AssocStatus (); - if (i == ASSOCSTATUS_ASSOCIATED) { - printk ("Connected successfully!\n"); - break; - } - if (i == ASSOCSTATUS_CANNOTCONNECT) { - printk ("Could not connect!\n"); - break; - } - } - - printk ("Starting daemon\n"); - softc.tx_id = rtems_bsdnet_newproc ("SCtx", 4096, wifi_txd, &softc); - softc.rx_id = rtems_bsdnet_newproc ("SCrx", 4096, wifi_rxd, &softc); - } - - ifp->if_flags |= IFF_RUNNING; -} - -/* - * wifi deactivation method. - */ - -static void -wifi_shutdown (void *arg) -{ - /* XXX */ -} - -/* - * ioctl hook function. - */ - -static int -wifi_ioctl (struct ifnet *ifp, ioctl_command_t command, caddr_t data) -{ - void *sc = ifp->if_softc; - - switch (command) { - case SIOCGIFADDR: - case SIOCSIFADDR: - return ether_ioctl (ifp, command, data); - - case SIOCSIFFLAGS: - switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) { - case IFF_RUNNING: - wifi_shutdown (sc); - break; - case IFF_UP: - wifi_init (sc); - break; - case IFF_UP | IFF_RUNNING: - wifi_shutdown (sc); - wifi_init (sc); - break; - default: - break; - } - return 0; - - default: - return EINVAL; - } -} - -/* - * function for sending a packet - */ - -static void -wifi_start (struct ifnet *ifp) -{ - /* wake up the send daemon */ - ifp->if_flags |= IFF_OACTIVE; - rtems_bsdnet_event_send (softc.tx_id, TRANSMIT_EVENT); -} - -/* - * RTEMS device attach method for wiwi driver - */ - -int -rtems_wifi_driver_attach (struct rtems_bsdnet_ifconfig *config, int attach) -{ - struct ifnet *ifp = &softc.arpcom.ac_if; - - printk ("wifi attach...\n"); - - /* initialize ifnet structure */ - memset (&softc, 0, sizeof (softc)); - ifp->if_softc = &softc; - ifp->if_unit = 0; - ifp->if_name = "dswifi"; - ifp->if_mtu = ETHERMTU; - ifp->if_init = wifi_init; - ifp->if_ioctl = wifi_ioctl; - ifp->if_watchdog = NULL; - ifp->if_start = wifi_start; - ifp->if_output = ether_output; - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; - if (ifp->if_snd.ifq_maxlen == 0) { - ifp->if_snd.ifq_maxlen = ifqmaxlen; - } - - if (config->mtu != 0) { - ifp->if_mtu = config->mtu; - } - - if (config->hardware_address != NULL) { - softc.is_hwaddr_set = 1; - memcpy (softc.arpcom.ac_enaddr, config->hardware_address, ETHER_ADDR_LEN); - } else { - softc.is_hwaddr_set = 0; - } - - u32 Wifi_pass; - int i; - - /* wifi hardware initialization took from dswifi example code */ - - /* send fifo message to initialize the arm7 wifi */ - REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR; - - Wifi_pass = - Wifi_Init (WIFIINIT_OPTION_USELED | WIFIINIT_OPTION_USECUSTOMALLOC); - REG_IPC_FIFO_TX = 0x12345678; - REG_IPC_FIFO_TX = Wifi_pass; - - /* setup fifo IRQ */ - irqSet (IRQ_FIFO_NOT_EMPTY, arm9_fifo); - irqEnable (IRQ_FIFO_NOT_EMPTY); - - /* enable FIFO IRQ */ - REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ; - - /* tell wifi lib to use our handler to notify arm7 */ - Wifi_SetSyncHandler (arm9_synctoarm7); - - /* set timer3 */ - TIMER3_DATA = -6553; // 6553.1 * 256 cycles = ~50ms; - TIMER3_CR = 0x00C2; // enable, irq, 1/256 clock - - /* setup timer IRQ */ - irqSet (IRQ_TIMER3, Timer_50ms); - irqEnable (IRQ_TIMER3); - - while (Wifi_CheckInit () == 0) { - /* wait for arm7 to be initted successfully */ - while (REG_VCOUNT > 192); - while (REG_VCOUNT < 192); - } - - /* wifi init complete - wifi lib can now be used! */ - - printk ("ok.\n"); - - /* retrieve MAC address if unspecified by the user */ - if (!softc.is_hwaddr_set) { - Wifi_GetData (WIFIGETDATA_MACADDRESS, ETHER_ADDR_LEN, - softc.arpcom.ac_enaddr); - } - - print_byte (softc.arpcom.ac_enaddr[0]); - for (i = 1; i < ETHER_ADDR_LEN; i++) { - printk (":"); - print_byte (softc.arpcom.ac_enaddr[i]); - } - printk ("\n"); - - /* attach the interface */ - if_attach (ifp); - ether_ifattach (ifp); - - printk ("network device '%s' initialized\n", config->name); - - return 0; -} |