⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ray_cs.c

📁 内核linux2.4.20,可跟rtlinux3.2打补丁 组成实时linux系统,编译内核
💻 C
📖 第 1 页 / 共 5 页
字号:
    }    local->card_status = CARD_DL_PARAM;    /* Start kernel timer to wait for dl startup to complete. */    local->timer.expires = jiffies + HZ/2;    local->timer.data = (long)local;    local->timer.function = &verify_dl_startup;    add_timer(&local->timer);    DEBUG(2,"ray_cs dl_startup_params started timer for verify_dl_startup\n");    return 0;} /* dl_startup_params *//*===========================================================================*/static void init_startup_params(ray_dev_t *local){    int i;     if (country > JAPAN_TEST) country = USA;    else        if (country < USA) country = USA;    /* structure for hop time and beacon period is defined here using      * New 802.11D6.1 format.  Card firmware is still using old format     * until version 6.     *    Before                    After     *    a_hop_time ms byte        a_hop_time ms byte     *    a_hop_time 2s byte        a_hop_time ls byte     *    a_hop_time ls byte        a_beacon_period ms byte     *    a_beacon_period           a_beacon_period ls byte     *     *    a_hop_time = uS           a_hop_time = KuS     *    a_beacon_period = hops    a_beacon_period = KuS     */                             /* 64ms = 010000 */    if (local->fw_ver == 0x55)  {        memcpy((UCHAR *)&local->sparm.b4, b4_default_startup_parms,                sizeof(struct b4_startup_params));        /* Translate sane kus input values to old build 4/5 format */        /* i = hop time in uS truncated to 3 bytes */        i = (hop_dwell * 1024) & 0xffffff;        local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;        local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;        local->sparm.b4.a_beacon_period[0] = 0;        local->sparm.b4.a_beacon_period[1] =            ((beacon_period/hop_dwell) - 1) & 0xff;        local->sparm.b4.a_curr_country_code = country;        local->sparm.b4.a_hop_pattern_length =             hop_pattern_length[(int)country] - 1;        if (bc)        {            local->sparm.b4.a_ack_timeout = 0x50;            local->sparm.b4.a_sifs = 0x3f;        }    }    else {    /* Version 5 uses real kus values */        memcpy((UCHAR *)&local->sparm.b5, b5_default_startup_parms,                sizeof(struct b5_startup_params));        local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;        local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;        local->sparm.b5.a_beacon_period[0] = (beacon_period >> 8) & 0xff;        local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;        if (psm)            local->sparm.b5.a_power_mgt_state = 1;        local->sparm.b5.a_curr_country_code = country;        local->sparm.b5.a_hop_pattern_length =             hop_pattern_length[(int)country];    }        local->sparm.b4.a_network_type = net_type & 0x01;    local->sparm.b4.a_acting_as_ap_status = TYPE_STA;    if (essid != NULL)        strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);} /* init_startup_params */ /*===========================================================================*/static void verify_dl_startup(u_long data){    ray_dev_t *local = (ray_dev_t *)data;    struct ccs *pccs = ((struct ccs *)(local->sram + CCS_BASE)) + local->dl_param_ccs;    UCHAR status;    dev_link_t *link = local->finder;    if (!(link->state & DEV_PRESENT)) {        DEBUG(2,"ray_cs verify_dl_startup - device not present\n");        return;    }#ifdef PCMCIA_DEBUG    if (pc_debug > 2) {    int i;    printk(KERN_DEBUG "verify_dl_startup parameters sent via ccs %d:\n",           local->dl_param_ccs);        for (i=0; i<sizeof(struct b5_startup_params); i++) {            printk(" %2x", (unsigned int) readb(local->sram + HOST_TO_ECF_BASE + i));        }    printk("\n");    }#endif    status = readb(&pccs->buffer_status);    if (status!= CCS_BUFFER_FREE)    {        printk(KERN_INFO "Download startup params failed.  Status = %d\n",           status);        local->card_status = CARD_DL_PARAM_ERROR;        return;    }    if (local->sparm.b4.a_network_type == ADHOC)        start_net((u_long)local);    else        join_net((u_long)local);    return;} /* end verify_dl_startup *//*===========================================================================*//* Command card to start a network */static void start_net(u_long data){    ray_dev_t *local = (ray_dev_t *)data;    struct ccs *pccs;    int ccsindex;    dev_link_t *link = local->finder;    if (!(link->state & DEV_PRESENT)) {        DEBUG(2,"ray_cs start_net - device not present\n");        return;    }    /* Fill in the CCS fields for the ECF */    if ((ccsindex = get_free_ccs(local)) < 0) return;    pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;    writeb(CCS_START_NETWORK, &pccs->cmd);    writeb(0, &pccs->var.start_network.update_param);    /* Interrupt the firmware to process the command */    if (interrupt_ecf(local, ccsindex)) {        DEBUG(1,"ray start net failed - card not ready for intr\n");        writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);        return;    }    local->card_status = CARD_DOING_ACQ;    return;} /* end start_net *//*===========================================================================*//* Command card to join a network */static void join_net(u_long data){    ray_dev_t *local = (ray_dev_t *)data;    struct ccs *pccs;    int ccsindex;    dev_link_t *link = local->finder;        if (!(link->state & DEV_PRESENT)) {        DEBUG(2,"ray_cs join_net - device not present\n");        return;    }    /* Fill in the CCS fields for the ECF */    if ((ccsindex = get_free_ccs(local)) < 0) return;    pccs = ((struct ccs *)(local->sram + CCS_BASE)) + ccsindex;    writeb(CCS_JOIN_NETWORK, &pccs->cmd);    writeb(0, &pccs->var.join_network.update_param);    writeb(0, &pccs->var.join_network.net_initiated);    /* Interrupt the firmware to process the command */    if (interrupt_ecf(local, ccsindex)) {        DEBUG(1,"ray join net failed - card not ready for intr\n");        writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);        return;    }    local->card_status = CARD_DOING_ACQ;    return;}/*============================================================================    After a card is removed, ray_release() will unregister the net    device, and release the PCMCIA configuration.  If the device is    still open, this will be postponed until it is closed.=============================================================================*/static void ray_release(u_long arg){    dev_link_t *link = (dev_link_t *)arg;    struct net_device *dev = link->priv;     ray_dev_t *local = dev->priv;    int i;        DEBUG(1, "ray_release(0x%p)\n", link);    /* If the device is currently in use, we won't release until it      is actually closed.    */    if (link->open) {        DEBUG(1, "ray_cs: release postponed, '%s' still open\n",              link->dev->dev_name);        link->state |= DEV_STALE_CONFIG;        return;    }    del_timer(&local->timer);    link->state &= ~DEV_CONFIG;    iounmap(local->sram);    iounmap(local->rmem);    iounmap(local->amem);    /* Do bother checking to see if these succeed or not */    i = pcmcia_release_window(link->win);    if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(link->win) ret = %x\n",i);    i = pcmcia_release_window(local->amem_handle);    if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i);    i = pcmcia_release_window(local->rmem_handle);    if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i);    i = pcmcia_release_configuration(link->handle);    if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseConfiguration ret = %x\n",i);    i = pcmcia_release_irq(link->handle, &link->irq);    if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseIRQ ret = %x\n",i);    DEBUG(2,"ray_release ending\n");} /* ray_release *//*=============================================================================    The card status event handler.  Mostly, this schedules other    stuff to run after an event is received.  A CARD_REMOVAL event    also sets some flags to discourage the net drivers from trying    to talk to the card any more.    When a CARD_REMOVAL event is received, we immediately set a flag    to block future accesses to this device.  All the functions that    actually access the device should check this flag to make sure    the card is still present.=============================================================================*/static int ray_event(event_t event, int priority,                     event_callback_args_t *args){    dev_link_t *link = args->client_data;    struct net_device *dev = link->priv;    ray_dev_t *local = (ray_dev_t *)dev->priv;    DEBUG(1, "ray_event(0x%06x)\n", event);        switch (event) {    case CS_EVENT_CARD_REMOVAL:        link->state &= ~DEV_PRESENT;        netif_device_detach(dev);        if (link->state & DEV_CONFIG) {            mod_timer(&link->release, jiffies + HZ/20);            del_timer(&local->timer);        }        break;    case CS_EVENT_CARD_INSERTION:        link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;        ray_config(link);        break;    case CS_EVENT_PM_SUSPEND:        link->state |= DEV_SUSPEND;        /* Fall through... */    case CS_EVENT_RESET_PHYSICAL:        if (link->state & DEV_CONFIG) {            if (link->open)            	netif_device_detach(dev);            pcmcia_release_configuration(link->handle);        }        break;    case CS_EVENT_PM_RESUME:        link->state &= ~DEV_SUSPEND;        /* Fall through... */    case CS_EVENT_CARD_RESET:        if (link->state & DEV_CONFIG) {            pcmcia_request_configuration(link->handle, &link->conf);            if (link->open) {                ray_reset(dev);		netif_device_attach(dev);            }        }        break;    }    return 0;    DEBUG(2,"ray_event ending\n");} /* ray_event *//*===========================================================================*/int ray_dev_init(struct net_device *dev){    int i;    ray_dev_t *local = dev->priv;    dev_link_t *link = local->finder;    DEBUG(1,"ray_dev_init(dev=%p)\n",dev);    if (!(link->state & DEV_PRESENT)) {        DEBUG(2,"ray_dev_init - device not present\n");        return -1;    }    /* Download startup parameters */    if ( (i = dl_startup_params(dev)) < 0)    {        printk(KERN_INFO "ray_dev_init dl_startup_params failed - "           "returns 0x%x\n",i);        return -1;    }        /* copy mac and broadcast addresses to linux device */    memcpy(&dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);    memset(dev->broadcast, 0xff, ETH_ALEN);    DEBUG(2,"ray_dev_init ending\n");    return 0;}/*===========================================================================*/static int ray_dev_config(struct net_device *dev, struct ifmap *map){    ray_dev_t *local = dev->priv;    dev_link_t *link = local->finder;    /* Dummy routine to satisfy device structure */    DEBUG(1,"ray_dev_config(dev=%p,ifmap=%p)\n",dev,map);    if (!(link->state & DEV_PRESENT)) {        DEBUG(2,"ray_dev_config - device not present\n");        return -1;    }    return 0;}/*===========================================================================*/static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev){    ray_dev_t *local = dev->priv;    dev_link_t *link = local->finder;    short length;    if (!(link->state & DEV_PRESENT)) {        DEBUG(2,"ray_dev_start_xmit - device not present\n");        return -1;    }    DEBUG(3,"ray_dev_start_xmit(skb=%p, dev=%p)\n",skb,dev);    if (local->authentication_state == NEED_TO_AUTH) {        DEBUG(0,"ray_cs Sending authentication request.\n");        if (!build_auth_frame (local, local->auth_id, OPEN_AUTH_REQUEST)) {            local->authentication_state = AUTHENTICATED;            netif_stop_queue(dev);            return 1;        }    }    length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;    switch (ray_hw_xmit( skb->data, length, dev, DATA_TYPE)) {        case XMIT_NO_CCS:        case XMIT_NEED_AUTH:	    netif_stop_queue(dev);            return 1;        case XMIT_NO_INTR:        case XMIT_MSG_BAD:        case XMIT_OK:        default:            dev->trans_start = jiffies;            dev_kfree_skb(skb);            return 0;    }    return 0;} /* ray_dev_start_xmit *//*===========================================================================*/static int ray_hw_xmit(unsigned char* data, int len, struct net_device* dev,                 UCHAR msg_type){    ray_dev_t *local = (ray_dev_t *)dev->priv;    struct ccs *pccs;    int ccsindex;    int offset;    struct tx_msg *ptx; /* Address of xmit buffer in PC space */    short int addr;     /* Address of xmit buffer in card space */        DEBUG(3,"ray_hw_xmit(data=%p, len=%d, dev=%p)\n",data,len,dev);    if (len + TX_HEADER_LENGTH > TX_BUF_SIZE)    {        printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",len);        return XMIT_MSG_BAD;    }	switch (ccsindex = get_free_tx_ccs(local)) {	case ECCSBUSY:		DEBUG(2,"ray_hw_xmit tx_ccs table busy\n");	case ECCSFULL:        DEBUG(2,"ray_hw_xmit No free tx ccs\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -