Esempio n. 1
0
WI_FILE *
em_fopen(char * name, char * mode)
{
   em_file *   emf;
   EOFILE *    eofile;
   char *      cmpname = name;

   /* Search the efs a name matching the one passed. */
   for(emf = emfiles; emf; emf = emf->em_next)
   {
      if(emf->em_name[0] != *cmpname)  /* fast test of first char */
         continue;

      if(strcmp(emf->em_name, cmpname) == 0)
         break;
   }
   if(!emf)             /* If file not in list, return NULL */
      return NULL;

   if( *mode != 'r' )   /* All files are RO,otherwise return NULL */
      return NULL;

   /* We're going to open file. Allocate the transient control structure */
   eofile = (EOFILE *)wi_alloc(sizeof(EOFILE));
   if(!eofile)
      return NULL;
   eofile->eo_emfile = emf;
   eofile->eo_position = 0;

   /* Add new open struct to open files list */
   eofile->eo_next = em_openlist;
   em_openlist = eofile;

   return ( (WI_FILE*)eofile);
}
Esempio n. 2
0
static struct wif *obsd_open(char *iface)
{
	struct wif *wi;
	struct priv_obsd *po;
	int fd;

	/* setup wi struct */
	wi = wi_alloc(sizeof(*po));
	if (!wi)
		return NULL;
	wi->wi_read		= obsd_read;
	wi->wi_write		= obsd_write;
	wi->wi_set_channel	= obsd_set_channel;
	wi->wi_get_channel	= obsd_get_channel;
	wi->wi_close		= obsd_close;
	wi->wi_fd		= obsd_fd;
	wi->wi_get_mac		= obsd_get_mac;
	wi->wi_set_mac		= obsd_set_mac;
	wi->wi_get_rate		= obsd_get_rate;
	wi->wi_set_rate		= obsd_set_rate;
        wi->wi_get_monitor      = obsd_get_monitor;

	/* setup iface */
	fd = do_obsd_open(wi, iface);
	if (fd == -1) {
		do_free(wi);
		return NULL;
	}

	/* setup private state */
	po = wi_priv(wi);
	po->po_fd = fd;

	return wi;
}
Esempio n. 3
0
struct wif *file_open(char *iface)
{
	struct wif *wi;
	struct priv_file *pf;
	int fd;
        struct pcap_file_header pfh;
	int rc;

	if (strncmp(iface, "file://", 7) != 0)
		return NULL;

	/* setup wi struct */
	wi = wi_alloc(sizeof(*pf));
	if (!wi)
		return NULL;

	wi->wi_read		= file_read;
	wi->wi_write		= file_write;
	wi->wi_set_channel	= file_set_channel;
	wi->wi_get_channel	= file_get_channel;
        wi->wi_set_rate    	= file_set_rate;
	wi->wi_get_rate    	= file_get_rate;
	wi->wi_close		= file_close;
	wi->wi_fd		= file_fd;
	wi->wi_get_mac		= file_get_mac;
	wi->wi_get_monitor	= file_get_monitor;

        pf = wi_priv(wi);

	fd = open(iface + 7, O_RDONLY);
	if (fd == -1)
		err(1, "open()");

	pf->pf_fd = fd;

	if ((rc = read(fd, &pfh, sizeof(pfh))) != sizeof(pfh))
		goto __err;

	if (pfh.magic != TCPDUMP_MAGIC)
		goto __err;

	if (pfh.version_major != PCAP_VERSION_MAJOR
	    || pfh.version_minor != PCAP_VERSION_MINOR)
		goto __err;

	pf->pf_dtl = pfh.linktype;

	return wi;

__err:
	wi_close(wi);
	return (struct wif*) -1;
}
Esempio n. 4
0
File: freebsd.c Progetto: 0x0d/lrc
static struct wif *fbsd_open(char *iface)
{
	struct wif *wi;
	struct priv_fbsd *pf;
	int fd;

	/* setup wi struct */
	wi = wi_alloc(sizeof(*pf));
	if (!wi)
		return NULL;
	wi->wi_read		= fbsd_read;
	wi->wi_write		= fbsd_write;
	wi->wi_set_channel	= fbsd_set_channel;
	wi->wi_get_channel	= fbsd_get_channel;
	wi->wi_close		= fbsd_close;
	wi->wi_fd		= fbsd_fd;
	wi->wi_get_mac		= fbsd_get_mac;
	wi->wi_set_mac		= fbsd_set_mac;
	wi->wi_get_rate		= fbsd_get_rate;
	wi->wi_set_rate		= fbsd_set_rate;
	wi->wi_get_monitor	= fbsd_get_monitor;
	wi->wi_get_mtu		= fbsd_get_mtu;
	wi->wi_set_mtu		= fbsd_set_mtu;

	/* setup iface */
	fd = do_fbsd_open(wi, iface);
	if (fd == -1) {
		do_free(wi);
		return NULL;
	}

	/* setup private state */
	pf = wi_priv(wi);
	pf->pf_fd = fd;
        pf->pf_txparams.ibp_vers = IEEE80211_BPF_VERSION;
	pf->pf_txparams.ibp_len = sizeof(struct ieee80211_bpf_params) - 6;
	pf->pf_txparams.ibp_rate0 = 2;         /* 1 MB/s XXX */
	pf->pf_txparams.ibp_try0 = 1;          /* no retransmits */
	pf->pf_txparams.ibp_rate1 = 2;         /* 1 MB/s XXX */
	pf->pf_txparams.ibp_try1 = 1;          /* no retransmits */
	pf->pf_txparams.ibp_flags = IEEE80211_BPF_NOACK;
	pf->pf_txparams.ibp_power = 100;       /* nominal max */
	pf->pf_txparams.ibp_pri = WME_AC_VO;   /* high priority */

	return wi;
}
Esempio n. 5
0
static struct wif *cygwin_open(char *iface)
{
	struct wif *wi;
	struct priv_cygwin *priv;

	/* setup wi struct */
	wi = wi_alloc(sizeof(*priv));
	if (!wi)
		return NULL;
	wi->wi_read		= cygwin_read;
	wi->wi_write		= cygwin_write;
	wi->wi_set_channel	= cygwin_set_channel;
	wi->wi_get_channel	= cygwin_get_channel;
	wi->wi_close		= cygwin_close;
	wi->wi_fd		= cygwin_fd;
	wi->wi_get_mac		= cygwin_get_mac;
	wi->wi_set_mac		= cygwin_set_mac;
	wi->wi_get_rate		= cygwin_get_rate;
	wi->wi_set_rate		= cygwin_set_rate;
        wi->wi_get_monitor      = cygwin_get_monitor;

	/* setup iface */
	if (do_cygwin_open(wi, iface) == -1)
		goto err;

	/* setup private state */
	priv = wi_priv(wi);
	priv->pc_wi = wi;

	/* setup reader */
	if (pipe(priv->pc_pipe) == -1)
		goto err;
	priv->pc_running = 2;
	if (pthread_create(&priv->pc_reader, NULL, cygwin_reader, priv))
		goto err;
	priv->pc_running = 1;

	return wi;

err:
	do_free(wi);
	return NULL;
}
Esempio n. 6
0
wi_file *
wi_newfile(wi_filesys * fsys, wi_sess * sess, void * fd)
{
    wi_file *      newfile;

    newfile = (wi_file *)wi_alloc( sizeof(wi_file));
    if(!newfile)
        return NULL;

    newfile->wf_fd = fd;
    newfile->wf_routines = fsys;
    newfile->wf_sess = sess;

    /* Put new file at front of session file list */
    newfile->wf_next = sess->ws_filelist;
    sess->ws_filelist = newfile;

    return newfile;
}
Esempio n. 7
0
static int
wi_pccard_attach(device_t dev)
{
	struct wi_softc	*sc;
	int error;

	sc = device_get_softc(dev);
	sc->wi_gone = 0;
	sc->wi_bus_type = WI_BUS_PCCARD;

	error = wi_alloc(dev, 0);
	if (error == 0) {
		/* Make sure interrupts are disabled. */
		CSR_WRITE_2(sc, WI_INT_EN, 0);
		CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);

		error = wi_attach(dev);
		if (error != 0)
			wi_free(dev);
	}
	return error;
}
Esempio n. 8
0
txbuf *
wi_txalloc(wi_sess * websess)
{
    txbuf * newtx;

    newtx = (txbuf*)wi_alloc( sizeof(txbuf) );
    if(!newtx)
        return NULL;

    /* Install new TX buffer at end of session chain */
    if(websess->ws_txtail)
        websess->ws_txtail->tb_next = newtx;   /* add to existing tail */

    websess->ws_txtail = newtx;      /* new buffer is new tail */

    /* If empty, also make it head */
    if(websess->ws_txbufs == NULL)
        websess->ws_txbufs = newtx;

    newtx->tb_session = websess;     /* backpointer to session */

    return newtx;
}
Esempio n. 9
0
File: network.c Progetto: 0x0d/lrc
struct wif *net_open(char *iface)
{
	struct wif *wi;
	struct priv_net *pn;
	int s;

	/* setup wi struct */
	wi = wi_alloc(sizeof(*pn));
	if (!wi)
		return NULL;
	wi->wi_read		= net_read;
	wi->wi_write		= net_write;
	wi->wi_set_channel	= net_set_channel;
	wi->wi_get_channel	= net_get_channel;
        wi->wi_set_rate    	= net_set_rate;
	wi->wi_get_rate    	= net_get_rate;
	wi->wi_close		= net_close;
	wi->wi_fd		= net_fd;
	wi->wi_get_mac		= net_get_mac;
	wi->wi_get_monitor	= net_get_monitor;

	/* setup iface */
	s = do_net_open(iface);
	if (s == -1) {
		do_net_free(wi);
		return NULL;
	}

	/* setup private state */
	pn = wi_priv(wi);
	pn->pn_s = s;
	pn->pn_queue.q_next = pn->pn_queue.q_prev = &pn->pn_queue;
	pn->pn_queue_free.q_next = pn->pn_queue_free.q_prev
					= &pn->pn_queue_free;

	return wi;
}
Esempio n. 10
0
wi_sess *
wi_newsess(void)
{
    wi_sess * newsess;

    newsess = (wi_sess *)wi_alloc( sizeof(wi_sess) );
    if(!newsess)
    {
        dprintf("wi_newsess: out of memory.\n");
        return NULL;
    }
    newsess->ws_socket = INVALID_SOCKET;
    newsess->ws_state = WI_HEADER;
    newsess->ws_last = cticks;

    /* Add new session to master list */
    newsess->ws_next = wi_sessions;
    wi_sessions = newsess;

    /* All new sessions strt out ready to read their socket */
    newsess->ws_flags |= WF_READINGCMDS;

    return newsess;
}
Esempio n. 11
0
static int
wi_pci_attach(device_t dev)
{
    struct wi_softc		*sc;
    u_int32_t		command;
    u_int16_t		reg;
    int			error;
    int			timeout;

    sc = device_get_softc(dev);

    if (sc->wi_bus_type != WI_BUS_PCI_NATIVE) {
        error = wi_alloc(dev, WI_PCI_IORES);
        if (error)
            return (error);

        /* Make sure interrupts are disabled. */
        CSR_WRITE_2(sc, WI_INT_EN, 0);
        CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF);

        /* We have to do a magic PLX poke to enable interrupts */
        sc->local_rid = WI_PCI_LOCALRES;
        sc->local = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
                                           &sc->local_rid, RF_ACTIVE);
        sc->wi_localtag = rman_get_bustag(sc->local);
        sc->wi_localhandle = rman_get_bushandle(sc->local);
        command = bus_space_read_4(sc->wi_localtag, sc->wi_localhandle,
                                   WI_LOCAL_INTCSR);
        command |= WI_LOCAL_INTEN;
        bus_space_write_4(sc->wi_localtag, sc->wi_localhandle,
                          WI_LOCAL_INTCSR, command);
        bus_release_resource(dev, SYS_RES_IOPORT, sc->local_rid,
                             sc->local);
        sc->local = NULL;

        sc->mem_rid = WI_PCI_MEMRES;
        sc->mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
                                         &sc->mem_rid, RF_ACTIVE);
        if (sc->mem == NULL) {
            device_printf(dev, "couldn't allocate memory\n");
            wi_free(dev);
            return (ENXIO);
        }
        sc->wi_bmemtag = rman_get_bustag(sc->mem);
        sc->wi_bmemhandle = rman_get_bushandle(sc->mem);

        /*
         * Write COR to enable PC card
         * This is a subset of the protocol that the pccard bus code
         * would do.  In theory, we should parse the CIS to find the
         * COR offset.  In practice, the COR_OFFSET is always 0x3e0.
         */
        CSM_WRITE_1(sc, WI_COR_OFFSET, WI_COR_VALUE);
        reg = CSM_READ_1(sc, WI_COR_OFFSET);
        if (reg != WI_COR_VALUE) {
            device_printf(dev, "CSM_READ_1(WI_COR_OFFSET) "
                          "wanted %d, got %d\n", WI_COR_VALUE, reg);
            wi_free(dev);
            return (ENXIO);
        }
    } else {
        error = wi_alloc(dev, WI_PCI_LMEMRES);
        if (error)
            return (error);

        CSR_WRITE_2(sc, WI_PCICOR_OFF, WI_PCICOR_RESET);
        DELAY(250000);

        CSR_WRITE_2(sc, WI_PCICOR_OFF, 0x0000);
        DELAY(500000);

        timeout=2000000;
        while ((--timeout > 0) &&
                (CSR_READ_2(sc, WI_COMMAND) & WI_CMD_BUSY))
            DELAY(10);

        if (timeout == 0) {
            device_printf(dev, "couldn't reset prism pci core.\n");
            wi_free(dev);
            return(ENXIO);
        }
    }

    CSR_WRITE_2(sc, WI_HFA384X_SWSUPPORT0_OFF, WI_PRISM2STA_MAGIC);
    reg = CSR_READ_2(sc, WI_HFA384X_SWSUPPORT0_OFF);
    if (reg != WI_PRISM2STA_MAGIC) {
        device_printf(dev,
                      "CSR_READ_2(WI_HFA384X_SWSUPPORT0_OFF) "
                      "wanted %d, got %d\n", WI_PRISM2STA_MAGIC, reg);
        wi_free(dev);
        return (ENXIO);
    }

    error = wi_attach(dev);
    if (error != 0)
        wi_free(dev);
    return (error);
}