static int vlan_dev_init(struct net_device *dev) { struct net_device *real_dev = vlan_dev_priv(dev)->real_dev; netif_carrier_off(dev); /* IFF_BROADCAST|IFF_MULTICAST; ??? */ dev->flags = real_dev->flags & ~(IFF_UP | IFF_PROMISC | IFF_ALLMULTI | IFF_MASTER | IFF_SLAVE); dev->state = (real_dev->state & ((1<<__LINK_STATE_NOCARRIER) | (1<<__LINK_STATE_DORMANT))) | (1<<__LINK_STATE_PRESENT); dev->hw_features = NETIF_F_ALL_CSUM | NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_GSO_SOFTWARE | NETIF_F_HIGHDMA | NETIF_F_SCTP_CSUM | NETIF_F_ALL_FCOE; dev->features |= real_dev->vlan_features | NETIF_F_LLTX | NETIF_F_GSO_SOFTWARE; dev->gso_max_size = real_dev->gso_max_size; if (dev->features & NETIF_F_VLAN_FEATURES) netdev_warn(real_dev, "VLAN features are set incorrectly. Q-in-Q configurations may not work correctly.\n"); dev->vlan_features = real_dev->vlan_features & ~NETIF_F_ALL_FCOE; /* ipv6 shared card related stuff */ dev->dev_id = real_dev->dev_id; if (is_zero_ether_addr(dev->dev_addr)) eth_hw_addr_inherit(dev, real_dev); if (is_zero_ether_addr(dev->broadcast)) memcpy(dev->broadcast, real_dev->broadcast, dev->addr_len); #if IS_ENABLED(CONFIG_FCOE) dev->fcoe_ddp_xid = real_dev->fcoe_ddp_xid; #endif dev->needed_headroom = real_dev->needed_headroom; if (vlan_hw_offload_capable(real_dev->features, vlan_dev_priv(dev)->vlan_proto)) { dev->header_ops = &vlan_passthru_header_ops; dev->hard_header_len = real_dev->hard_header_len; } else { dev->header_ops = &vlan_header_ops; dev->hard_header_len = real_dev->hard_header_len + VLAN_HLEN; } dev->netdev_ops = &vlan_netdev_ops; SET_NETDEV_DEVTYPE(dev, &vlan_type); vlan_dev_set_lockdep_class(dev, vlan_dev_get_lock_subclass(dev)); vlan_dev_priv(dev)->vlan_pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats); if (!vlan_dev_priv(dev)->vlan_pcpu_stats) return -ENOMEM; return 0; }
static int wpa_init_wpadev(PSDevice pDevice) { PSDevice wpadev_priv; struct net_device *dev = pDevice->dev; int ret = 0; pDevice->wpadev = alloc_netdev(sizeof(PSDevice), "vntwpa", wpadev_setup); if (pDevice->wpadev == NULL) return -ENOMEM; wpadev_priv = netdev_priv(pDevice->wpadev); *wpadev_priv = *pDevice; eth_hw_addr_inherit(pDevice->wpadev, dev); pDevice->wpadev->base_addr = dev->base_addr; pDevice->wpadev->irq = dev->irq; pDevice->wpadev->mem_start = dev->mem_start; pDevice->wpadev->mem_end = dev->mem_end; ret = register_netdev(pDevice->wpadev); if (ret) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdev(WPA) failed!\n", dev->name); free_netdev(pDevice->wpadev); return -1; } if (pDevice->skb == NULL) { pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); if (pDevice->skb == NULL) return -ENOMEM; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdev %s for WPA management\n", dev->name, pDevice->wpadev->name); return 0; }
static int wpa_init_wpadev(struct vnt_private *pDevice) { struct vnt_private *wpadev_priv; struct net_device *dev = pDevice->dev; int ret = 0; pDevice->wpadev = alloc_netdev(sizeof(*wpadev_priv), "vntwpa", NET_NAME_UNKNOWN, wpadev_setup); if (pDevice->wpadev == NULL) return -ENOMEM; wpadev_priv = netdev_priv(pDevice->wpadev); *wpadev_priv = *pDevice; eth_hw_addr_inherit(pDevice->wpadev, dev); pDevice->wpadev->base_addr = dev->base_addr; pDevice->wpadev->irq = dev->irq; pDevice->wpadev->mem_start = dev->mem_start; pDevice->wpadev->mem_end = dev->mem_end; ret = register_netdev(pDevice->wpadev); if (ret) { pr_debug("%s: register_netdev(WPA) failed!\n", dev->name); free_netdev(pDevice->wpadev); return -1; } if (pDevice->skb == NULL) { pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); if (pDevice->skb == NULL) return -ENOMEM; } pr_debug("%s: Registered netdev %s for WPA management\n", dev->name, pDevice->wpadev->name); return 0; }
int dsa_slave_create(struct dsa_switch *ds, struct device *parent, int port, char *name) { struct net_device *master = ds->dst->master_netdev; struct net_device *slave_dev; struct dsa_slave_priv *p; int ret; slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), name, NET_NAME_UNKNOWN, ether_setup); if (slave_dev == NULL) return -ENOMEM; slave_dev->features = master->vlan_features; slave_dev->ethtool_ops = &dsa_slave_ethtool_ops; eth_hw_addr_inherit(slave_dev, master); slave_dev->priv_flags |= IFF_NO_QUEUE; slave_dev->netdev_ops = &dsa_slave_netdev_ops; slave_dev->switchdev_ops = &dsa_slave_switchdev_ops; SET_NETDEV_DEVTYPE(slave_dev, &dsa_type); netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one, NULL); SET_NETDEV_DEV(slave_dev, parent); slave_dev->dev.of_node = ds->pd->port_dn[port]; slave_dev->vlan_features = master->vlan_features; p = netdev_priv(slave_dev); p->dev = slave_dev; p->parent = ds; p->port = port; switch (ds->dst->tag_protocol) { #ifdef CONFIG_NET_DSA_TAG_DSA case DSA_TAG_PROTO_DSA: p->xmit = dsa_netdev_ops.xmit; break; #endif #ifdef CONFIG_NET_DSA_TAG_EDSA case DSA_TAG_PROTO_EDSA: p->xmit = edsa_netdev_ops.xmit; break; #endif #ifdef CONFIG_NET_DSA_TAG_TRAILER case DSA_TAG_PROTO_TRAILER: p->xmit = trailer_netdev_ops.xmit; break; #endif #ifdef CONFIG_NET_DSA_TAG_BRCM case DSA_TAG_PROTO_BRCM: p->xmit = brcm_netdev_ops.xmit; break; #endif default: p->xmit = dsa_slave_notag_xmit; break; } p->old_pause = -1; p->old_link = -1; p->old_duplex = -1; ds->ports[port] = slave_dev; ret = register_netdev(slave_dev); if (ret) { netdev_err(master, "error %d registering interface %s\n", ret, slave_dev->name); ds->ports[port] = NULL; free_netdev(slave_dev); return ret; } netif_carrier_off(slave_dev); ret = dsa_slave_phy_setup(p, slave_dev); if (ret) { netdev_err(master, "error %d setting up slave phy\n", ret); unregister_netdev(slave_dev); free_netdev(slave_dev); return ret; } return 0; }
struct net_device * dsa_slave_create(struct dsa_switch *ds, struct device *parent, int port, char *name) { struct net_device *master = ds->dst->master_netdev; struct net_device *slave_dev; struct dsa_slave_priv *p; int ret; slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), name, NET_NAME_UNKNOWN, ether_setup); if (slave_dev == NULL) return slave_dev; slave_dev->features = master->vlan_features; slave_dev->ethtool_ops = &dsa_slave_ethtool_ops; eth_hw_addr_inherit(slave_dev, master); slave_dev->tx_queue_len = 0; slave_dev->netdev_ops = &dsa_slave_netdev_ops; SET_NETDEV_DEV(slave_dev, parent); slave_dev->dev.of_node = ds->pd->port_dn[port]; slave_dev->vlan_features = master->vlan_features; p = netdev_priv(slave_dev); p->dev = slave_dev; p->parent = ds; p->port = port; switch (ds->dst->tag_protocol) { #ifdef CONFIG_NET_DSA_TAG_DSA case DSA_TAG_PROTO_DSA: p->xmit = dsa_netdev_ops.xmit; break; #endif #ifdef CONFIG_NET_DSA_TAG_EDSA case DSA_TAG_PROTO_EDSA: p->xmit = edsa_netdev_ops.xmit; break; #endif #ifdef CONFIG_NET_DSA_TAG_TRAILER case DSA_TAG_PROTO_TRAILER: p->xmit = trailer_netdev_ops.xmit; break; #endif #ifdef CONFIG_NET_DSA_TAG_BRCM case DSA_TAG_PROTO_BRCM: p->xmit = brcm_netdev_ops.xmit; break; #endif default: p->xmit = dsa_slave_notag_xmit; break; } p->old_pause = -1; p->old_link = -1; p->old_duplex = -1; ret = dsa_slave_phy_setup(p, slave_dev); if (ret) { free_netdev(slave_dev); return NULL; } ret = register_netdev(slave_dev); if (ret) { netdev_err(master, "error %d registering interface %s\n", ret, slave_dev->name); phy_disconnect(p->phy); free_netdev(slave_dev); return NULL; } netif_carrier_off(slave_dev); return slave_dev; }
/* slave device setup *******************************************************/ struct net_device * dsa_slave_create(struct dsa_switch *ds, struct device *parent, int port, char *name) { struct net_device *master = ds->dst->master_netdev; struct net_device *slave_dev; struct dsa_slave_priv *p; int ret; slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), name, ether_setup); if (slave_dev == NULL) return slave_dev; slave_dev->features = master->vlan_features; SET_ETHTOOL_OPS(slave_dev, &dsa_slave_ethtool_ops); eth_hw_addr_inherit(slave_dev, master); slave_dev->tx_queue_len = 0; switch (ds->dst->tag_protocol) { #ifdef CONFIG_NET_DSA_TAG_DSA case htons(ETH_P_DSA): slave_dev->netdev_ops = &dsa_netdev_ops; break; #endif #ifdef CONFIG_NET_DSA_TAG_EDSA case htons(ETH_P_EDSA): slave_dev->netdev_ops = &edsa_netdev_ops; break; #endif #ifdef CONFIG_NET_DSA_TAG_TRAILER case htons(ETH_P_TRAILER): slave_dev->netdev_ops = &trailer_netdev_ops; break; #endif default: BUG(); } SET_NETDEV_DEV(slave_dev, parent); slave_dev->vlan_features = master->vlan_features; p = netdev_priv(slave_dev); p->dev = slave_dev; p->parent = ds; p->port = port; p->phy = ds->slave_mii_bus->phy_map[port]; ret = register_netdev(slave_dev); if (ret) { printk(KERN_ERR "%s: error %d registering interface %s\n", master->name, ret, slave_dev->name); free_netdev(slave_dev); return NULL; } netif_carrier_off(slave_dev); if (p->phy != NULL) { phy_attach(slave_dev, dev_name(&p->phy->dev), PHY_INTERFACE_MODE_GMII); p->phy->autoneg = AUTONEG_ENABLE; p->phy->speed = 0; p->phy->duplex = 0; p->phy->advertising = p->phy->supported | ADVERTISED_Autoneg; phy_start_aneg(p->phy); } return slave_dev; }
int private_ioctl(PSDevice pDevice, struct ifreq *rq) { PSCmdRequest pReq = (PSCmdRequest)rq; PSMgmtObject pMgmt = pDevice->pMgmt; int result = 0; PWLAN_IE_SSID pItemSSID; SCmdBSSJoin sJoinCmd; SCmdZoneTypeSet sZoneTypeCmd; SCmdScan sScanCmd; SCmdStartAP sStartAPCmd; SCmdSetWEP sWEPCmd; SCmdValue sValue; SBSSIDList sList; SNodeList sNodeList; PSBSSIDList pList; PSNodeList pNodeList; unsigned int cbListCount; PKnownBSS pBSS; PKnownNodeDB pNode; unsigned int ii, jj; unsigned char abySuppRates[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16}; unsigned char abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; unsigned long dwKeyIndex = 0; unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; long ldBm; pReq->wResult = 0; switch (pReq->wCmdCode) { case WLAN_CMD_BSS_SCAN: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_BSS_SCAN..begin\n"); if (copy_from_user(&sScanCmd, pReq->data, sizeof(SCmdScan))) { result = -EFAULT; break; } pItemSSID = (PWLAN_IE_SSID)sScanCmd.ssid; if (pItemSSID->len > WLAN_SSID_MAXLEN + 1) return -EINVAL; if (pItemSSID->len != 0) { memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); memcpy(abyScanSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN); } if (pDevice->bMACSuspend == true) { if (pDevice->bRadioOff == true) CARDbRadioPowerOn(pDevice); vMgrTimerInit(pDevice); MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE); add_timer(&pMgmt->sTimerSecondCallback); pDevice->bMACSuspend = false; } spin_lock_irq(&pDevice->lock); if (memcmp(pMgmt->abyCurrBSSID, &abyNullAddr[0], 6) == 0) BSSvClearBSSList((void *)pDevice, false); else BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass); if (pItemSSID->len != 0) bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID); else bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL); spin_unlock_irq(&pDevice->lock); break; case WLAN_CMD_ZONETYPE_SET: /* mike add :can't support. */ result = -EOPNOTSUPP; break; if (copy_from_user(&sZoneTypeCmd, pReq->data, sizeof(SCmdZoneTypeSet))) { result = -EFAULT; break; } if (sZoneTypeCmd.bWrite == true) { /* write zonetype */ if (sZoneTypeCmd.ZoneType == ZoneType_USA) { /* set to USA */ pr_debug("set_ZoneType:USA\n"); } else if (sZoneTypeCmd.ZoneType == ZoneType_Japan) { /* set to Japan */ pr_debug("set_ZoneType:Japan\n"); } else if (sZoneTypeCmd.ZoneType == ZoneType_Europe) { /* set to Europe */ pr_debug("set_ZoneType:Europe\n"); } } else { /* read zonetype */ unsigned char zonetype = 0; if (zonetype == 0x00) { /* USA */ sZoneTypeCmd.ZoneType = ZoneType_USA; } else if (zonetype == 0x01) { /* Japan */ sZoneTypeCmd.ZoneType = ZoneType_Japan; } else if (zonetype == 0x02) { /* Europe */ sZoneTypeCmd.ZoneType = ZoneType_Europe; } else { /* Unknown ZoneType */ pr_err("Error:ZoneType[%x] Unknown ???\n", zonetype); result = -EFAULT; break; } if (copy_to_user(pReq->data, &sZoneTypeCmd, sizeof(SCmdZoneTypeSet))) { result = -EFAULT; break; } } break; case WLAN_CMD_BSS_JOIN: if (pDevice->bMACSuspend == true) { if (pDevice->bRadioOff == true) CARDbRadioPowerOn(pDevice); vMgrTimerInit(pDevice); MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE); add_timer(&pMgmt->sTimerSecondCallback); pDevice->bMACSuspend = false; } if (copy_from_user(&sJoinCmd, pReq->data, sizeof(SCmdBSSJoin))) { result = -EFAULT; break; } pItemSSID = (PWLAN_IE_SSID)sJoinCmd.ssid; if (pItemSSID->len > WLAN_SSID_MAXLEN + 1) return -EINVAL; memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN); if (sJoinCmd.wBSSType == ADHOC) { pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to adhoc mode\n"); } else { pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to STA mode\n"); } if (sJoinCmd.bPSEnable == true) { pDevice->ePSMode = WMAC_POWER_FAST; pMgmt->wListenInterval = 2; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving On\n"); } else { pDevice->ePSMode = WMAC_POWER_CAM; pMgmt->wListenInterval = 1; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving Off\n"); } if (sJoinCmd.bShareKeyAuth == true) { pMgmt->bShareKeyAlgorithm = true; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key\n"); } else { pMgmt->bShareKeyAlgorithm = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System\n"); } pDevice->uChannel = sJoinCmd.uChannel; netif_stop_queue(pDevice->dev); spin_lock_irq(&pDevice->lock); pMgmt->eCurrState = WMAC_STATE_IDLE; bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID); bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL); spin_unlock_irq(&pDevice->lock); break; case WLAN_CMD_SET_WEP: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WEP Key.\n"); memset(&sWEPCmd, 0, sizeof(SCmdSetWEP)); if (copy_from_user(&sWEPCmd, pReq->data, sizeof(SCmdSetWEP))) { result = -EFAULT; break; } if (sWEPCmd.bEnableWep != true) { pDevice->bEncryptionEnable = false; pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; MACvDisableDefaultKey(pDevice->PortOffset); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WEP function disable.\n"); break; } for (ii = 0; ii < WLAN_WEP_NKEYS; ii++) { if (sWEPCmd.bWepKeyAvailable[ii]) { if (ii == sWEPCmd.byKeyIndex) dwKeyIndex = ii | (1 << 31); else dwKeyIndex = ii; KeybSetDefaultKey(&(pDevice->sKey), dwKeyIndex, sWEPCmd.auWepKeyLength[ii], NULL, (unsigned char *)&sWEPCmd.abyWepKey[ii][0], KEY_CTL_WEP, pDevice->PortOffset, pDevice->byLocalID); } } pDevice->byKeyIndex = sWEPCmd.byKeyIndex; pDevice->bTransmitKey = true; pDevice->bEncryptionEnable = true; pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; break; case WLAN_CMD_GET_LINK: { SCmdLinkStatus sLinkStatus; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_GET_LINK status.\n"); memset(&sLinkStatus, 0, sizeof(sLinkStatus)); if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) sLinkStatus.wBSSType = ADHOC; else sLinkStatus.wBSSType = INFRA; if (pMgmt->eCurrState == WMAC_STATE_JOINTED) sLinkStatus.byState = ADHOC_JOINTED; else sLinkStatus.byState = ADHOC_STARTED; sLinkStatus.uChannel = pMgmt->uCurrChannel; if (pDevice->bLinkPass == true) { sLinkStatus.bLink = true; pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID; memcpy(sLinkStatus.abySSID, pItemSSID->abySSID, pItemSSID->len); memcpy(sLinkStatus.abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN); sLinkStatus.uLinkRate = pMgmt->sNodeDBTable[0].wTxDataRate; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Link Success!\n"); } else { sLinkStatus.bLink = false; sLinkStatus.uLinkRate = 0; } if (copy_to_user(pReq->data, &sLinkStatus, sizeof(SCmdLinkStatus))) { result = -EFAULT; break; } break; } case WLAN_CMD_GET_LISTLEN: cbListCount = 0; pBSS = &(pMgmt->sBSSList[0]); for (ii = 0; ii < MAX_BSS_NUM; ii++) { pBSS = &(pMgmt->sBSSList[ii]); if (!pBSS->bActive) continue; cbListCount++; } sList.uItem = cbListCount; if (copy_to_user(pReq->data, &sList, sizeof(SBSSIDList))) { result = -EFAULT; break; } pReq->wResult = 0; break; case WLAN_CMD_GET_LIST: if (copy_from_user(&sList, pReq->data, sizeof(SBSSIDList))) { result = -EFAULT; break; } if (sList.uItem > (ULONG_MAX - sizeof(SBSSIDList)) / sizeof(SBSSIDItem)) { result = -EINVAL; break; } pList = (PSBSSIDList)kmalloc(sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)), GFP_ATOMIC); if (pList == NULL) { result = -ENOMEM; break; } pList->uItem = sList.uItem; pBSS = &(pMgmt->sBSSList[0]); for (ii = 0, jj = 0; jj < MAX_BSS_NUM; jj++) { pBSS = &(pMgmt->sBSSList[jj]); if (pBSS->bActive) { pList->sBSSIDList[ii].uChannel = pBSS->uChannel; pList->sBSSIDList[ii].wBeaconInterval = pBSS->wBeaconInterval; pList->sBSSIDList[ii].wCapInfo = pBSS->wCapInfo; RFvRSSITodBm(pDevice, (unsigned char)(pBSS->uRSSI), &ldBm); pList->sBSSIDList[ii].uRSSI = (unsigned int)ldBm; memcpy(pList->sBSSIDList[ii].abyBSSID, pBSS->abyBSSID, WLAN_BSSID_LEN); pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID; memset(pList->sBSSIDList[ii].abySSID, 0, WLAN_SSID_MAXLEN + 1); memcpy(pList->sBSSIDList[ii].abySSID, pItemSSID->abySSID, pItemSSID->len); if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) pList->sBSSIDList[ii].byNetType = INFRA; else pList->sBSSIDList[ii].byNetType = ADHOC; if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) pList->sBSSIDList[ii].bWEPOn = true; else pList->sBSSIDList[ii].bWEPOn = false; ii++; if (ii >= pList->uItem) break; } } if (copy_to_user(pReq->data, pList, sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)))) { result = -EFAULT; break; } kfree(pList); pReq->wResult = 0; break; case WLAN_CMD_GET_MIB: if (copy_to_user(pReq->data, &(pDevice->s802_11Counter), sizeof(SDot11MIBCount))) { result = -EFAULT; break; } break; case WLAN_CMD_GET_STAT: if (copy_to_user(pReq->data, &(pDevice->scStatistic), sizeof(SStatCounter))) { result = -EFAULT; break; } break; case WLAN_CMD_STOP_MAC: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_STOP_MAC\n"); netif_stop_queue(pDevice->dev); spin_lock_irq(&pDevice->lock); if (pDevice->bRadioOff == false) CARDbRadioPowerOff(pDevice); pDevice->bLinkPass = false; memset(pMgmt->abyCurrBSSID, 0, 6); pMgmt->eCurrState = WMAC_STATE_IDLE; del_timer(&pDevice->sTimerCommand); del_timer(&pMgmt->sTimerSecondCallback); pDevice->bCmdRunning = false; pDevice->bMACSuspend = true; MACvIntDisable(pDevice->PortOffset); spin_unlock_irq(&pDevice->lock); break; case WLAN_CMD_START_MAC: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_START_MAC\n"); if (pDevice->bMACSuspend == true) { if (pDevice->bRadioOff == true) CARDbRadioPowerOn(pDevice); vMgrTimerInit(pDevice); MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE); add_timer(&pMgmt->sTimerSecondCallback); pDevice->bMACSuspend = false; } break; case WLAN_CMD_SET_HOSTAPD: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD\n"); if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) { result = -EFAULT; break; } if (sValue.dwValue == 1) { if (vt6655_hostap_set_hostapd(pDevice, 1, 1) == 0) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HOSTAP\n"); } else { result = -EFAULT; break; } } else { vt6655_hostap_set_hostapd(pDevice, 0, 1); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HOSTAP\n"); } break; case WLAN_CMD_SET_HOSTAPD_STA: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD_STA\n"); break; case WLAN_CMD_SET_802_1X: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_802_1X\n"); if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) { result = -EFAULT; break; } if (sValue.dwValue == 1) { pDevice->bEnable8021x = true; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable 802.1x\n"); } else { pDevice->bEnable8021x = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable 802.1x\n"); } break; case WLAN_CMD_SET_HOST_WEP: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOST_WEP\n"); if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) { result = -EFAULT; break; } if (sValue.dwValue == 1) { pDevice->bEnableHostWEP = true; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HostWEP\n"); } else { pDevice->bEnableHostWEP = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HostWEP\n"); } break; case WLAN_CMD_SET_WPA: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WPA\n"); if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) { result = -EFAULT; break; } if (sValue.dwValue == 1) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "up wpadev\n"); eth_hw_addr_inherit(pDevice->wpadev, pDevice->dev); pDevice->bWPADEVUp = true; } else { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "close wpadev\n"); pDevice->bWPADEVUp = false; } break; case WLAN_CMD_AP_START: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_AP_START\n"); if (pDevice->bRadioOff == true) { CARDbRadioPowerOn(pDevice); vMgrTimerInit(pDevice); MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE); add_timer(&pMgmt->sTimerSecondCallback); } if (copy_from_user(&sStartAPCmd, pReq->data, sizeof(SCmdStartAP))) { result = -EFAULT; break; } if (sStartAPCmd.wBSSType == AP) { pMgmt->eConfigMode = WMAC_CONFIG_AP; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to AP mode\n"); } else { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct BSS type not set to AP mode\n"); result = -EFAULT; break; } if (sStartAPCmd.wBBPType == PHY80211g) pMgmt->byAPBBType = PHY_TYPE_11G; else if (sStartAPCmd.wBBPType == PHY80211a) pMgmt->byAPBBType = PHY_TYPE_11A; else pMgmt->byAPBBType = PHY_TYPE_11B; pItemSSID = (PWLAN_IE_SSID)sStartAPCmd.ssid; if (pItemSSID->len > WLAN_SSID_MAXLEN + 1) return -EINVAL; memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN); if ((sStartAPCmd.uChannel > 0) && (sStartAPCmd.uChannel <= 14)) pDevice->uChannel = sStartAPCmd.uChannel; if ((sStartAPCmd.uBeaconInt >= 20) && (sStartAPCmd.uBeaconInt <= 1000)) pMgmt->wIBSSBeaconPeriod = sStartAPCmd.uBeaconInt; else pMgmt->wIBSSBeaconPeriod = 100; if (sStartAPCmd.bShareKeyAuth == true) { pMgmt->bShareKeyAlgorithm = true; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key\n"); } else { pMgmt->bShareKeyAlgorithm = false; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System\n"); } memcpy(pMgmt->abyIBSSSuppRates, abySuppRates, 6); if (sStartAPCmd.byBasicRate & BIT3) { pMgmt->abyIBSSSuppRates[2] |= BIT7; pMgmt->abyIBSSSuppRates[3] |= BIT7; pMgmt->abyIBSSSuppRates[4] |= BIT7; pMgmt->abyIBSSSuppRates[5] |= BIT7; } else if (sStartAPCmd.byBasicRate & BIT2) { pMgmt->abyIBSSSuppRates[2] |= BIT7; pMgmt->abyIBSSSuppRates[3] |= BIT7; pMgmt->abyIBSSSuppRates[4] |= BIT7; } else if (sStartAPCmd.byBasicRate & BIT1) { pMgmt->abyIBSSSuppRates[2] |= BIT7; pMgmt->abyIBSSSuppRates[3] |= BIT7; } else if (sStartAPCmd.byBasicRate & BIT1) { pMgmt->abyIBSSSuppRates[2] |= BIT7; } else { /* default 1,2M */ pMgmt->abyIBSSSuppRates[2] |= BIT7; pMgmt->abyIBSSSuppRates[3] |= BIT7; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Support Rate= %*ph\n", 4, pMgmt->abyIBSSSuppRates + 2); netif_stop_queue(pDevice->dev); spin_lock_irq(&pDevice->lock); bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL); spin_unlock_irq(&pDevice->lock); break; case WLAN_CMD_GET_NODE_CNT: cbListCount = 0; pNode = &(pMgmt->sNodeDBTable[0]); for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) { pNode = &(pMgmt->sNodeDBTable[ii]); if (!pNode->bActive) continue; cbListCount++; } sNodeList.uItem = cbListCount; if (copy_to_user(pReq->data, &sNodeList, sizeof(SNodeList))) { result = -EFAULT; break; } pReq->wResult = 0; break; case WLAN_CMD_GET_NODE_LIST: if (copy_from_user(&sNodeList, pReq->data, sizeof(SNodeList))) { result = -EFAULT; break; } if (sNodeList.uItem > (ULONG_MAX - sizeof(SNodeList)) / sizeof(SNodeItem)) { result = -EINVAL; break; } pNodeList = (PSNodeList)kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)), GFP_ATOMIC); if (pNodeList == NULL) { result = -ENOMEM; break; } pNodeList->uItem = sNodeList.uItem; pNode = &(pMgmt->sNodeDBTable[0]); for (ii = 0, jj = 0; ii < (MAX_NODE_NUM + 1); ii++) { pNode = &(pMgmt->sNodeDBTable[ii]); if (pNode->bActive) { pNodeList->sNodeList[jj].wAID = pNode->wAID; memcpy(pNodeList->sNodeList[jj].abyMACAddr, pNode->abyMACAddr, WLAN_ADDR_LEN); pNodeList->sNodeList[jj].wTxDataRate = pNode->wTxDataRate; pNodeList->sNodeList[jj].wInActiveCount = (unsigned short)pNode->uInActiveCount; pNodeList->sNodeList[jj].wEnQueueCnt = (unsigned short)pNode->wEnQueueCnt; pNodeList->sNodeList[jj].wFlags = (unsigned short)pNode->dwFlags; pNodeList->sNodeList[jj].bPWBitOn = pNode->bPSEnable; pNodeList->sNodeList[jj].byKeyIndex = pNode->byKeyIndex; pNodeList->sNodeList[jj].wWepKeyLength = pNode->uWepKeyLength; memcpy(&(pNodeList->sNodeList[jj].abyWepKey[0]), &(pNode->abyWepKey[0]), WEP_KEYMAXLEN); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key= %2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", pNodeList->sNodeList[jj].abyWepKey[0], pNodeList->sNodeList[jj].abyWepKey[1], pNodeList->sNodeList[jj].abyWepKey[2], pNodeList->sNodeList[jj].abyWepKey[3], pNodeList->sNodeList[jj].abyWepKey[4]); pNodeList->sNodeList[jj].bIsInFallback = pNode->bIsInFallback; pNodeList->sNodeList[jj].uTxFailures = pNode->uTxFailures; pNodeList->sNodeList[jj].uTxAttempts = pNode->uTxAttempts; pNodeList->sNodeList[jj].wFailureRatio = (unsigned short)pNode->uFailureRatio; jj++; if (jj >= pNodeList->uItem) break; } } if (copy_to_user(pReq->data, pNodeList, sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)))) { result = -EFAULT; break; } kfree(pNodeList); pReq->wResult = 0; break; #ifdef WPA_SM_Transtatus case 0xFF: memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname)); wpa_Result.proto = 0; wpa_Result.key_mgmt = 0; wpa_Result.eap_type = 0; wpa_Result.authenticated = false; pDevice->fWPA_Authened = false; if (copy_from_user(&wpa_Result, pReq->data, sizeof(wpa_Result))) { result = -EFAULT; break; } if (wpa_Result.authenticated == true) { #ifdef SndEvt_ToAPI { union iwreq_data wrqu; pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID; memset(&wrqu, 0, sizeof(wrqu)); wrqu.data.flags = RT_WPACONNECTED_EVENT_FLAG; wrqu.data.length = pItemSSID->len; wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, pItemSSID->abySSID); } #endif pDevice->fWPA_Authened = true; /* is successful peer to wpa_Result.authenticated? */ } pReq->wResult = 0; break; #endif default: DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Private command not support..\n"); } return result; }
struct net_device * dsa_slave_create(struct dsa_switch *ds, struct device *parent, int port, char *name) { struct net_device *master = ds->dst->master_netdev; struct net_device *slave_dev; struct dsa_slave_priv *p; int ret; slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), name, NET_NAME_UNKNOWN, ether_setup); if (slave_dev == NULL) return slave_dev; slave_dev->features = master->vlan_features; slave_dev->ethtool_ops = &dsa_slave_ethtool_ops; eth_hw_addr_inherit(slave_dev, master); slave_dev->tx_queue_len = 0; slave_dev->netdev_ops = &dsa_slave_netdev_ops; SET_NETDEV_DEV(slave_dev, parent); slave_dev->dev.of_node = ds->pd->port_dn[port]; slave_dev->vlan_features = master->vlan_features; p = netdev_priv(slave_dev); p->dev = slave_dev; p->parent = ds; p->port = port; switch (ds->dst->tag_protocol) { #ifdef CONFIG_NET_DSA_TAG_DSA case DSA_TAG_PROTO_DSA: p->xmit = dsa_netdev_ops.xmit; break; #endif #ifdef CONFIG_NET_DSA_TAG_EDSA case DSA_TAG_PROTO_EDSA: p->xmit = edsa_netdev_ops.xmit; break; #endif #ifdef CONFIG_NET_DSA_TAG_TRAILER case DSA_TAG_PROTO_TRAILER: p->xmit = trailer_netdev_ops.xmit; break; #endif #ifdef CONFIG_NET_DSA_TAG_BRCM case DSA_TAG_PROTO_BRCM: p->xmit = brcm_netdev_ops.xmit; break; #endif default: p->xmit = dsa_slave_notag_xmit; break; } p->old_pause = -1; p->old_link = -1; p->old_duplex = -1; dsa_slave_phy_setup(p, slave_dev); ret = register_netdev(slave_dev); if (ret) { printk(KERN_ERR "%s: error %d registering interface %s\n", master->name, ret, slave_dev->name); free_netdev(slave_dev); return NULL; } netif_carrier_off(slave_dev); if (p->phy != NULL) { if (ds->drv->get_phy_flags) p->phy->dev_flags |= ds->drv->get_phy_flags(ds, port); phy_attach(slave_dev, dev_name(&p->phy->dev), PHY_INTERFACE_MODE_GMII); p->phy->autoneg = AUTONEG_ENABLE; p->phy->speed = 0; p->phy->duplex = 0; p->phy->advertising = p->phy->supported | ADVERTISED_Autoneg; } return slave_dev; }
static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked) { PSDevice apdev_priv; struct net_device *dev = pDevice->dev; int ret; const struct net_device_ops apdev_netdev_ops = { .ndo_start_xmit = pDevice->tx_80211, }; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name); pDevice->apdev = alloc_etherdev(sizeof(*apdev_priv)); if (pDevice->apdev == NULL) return -ENOMEM; apdev_priv = netdev_priv(pDevice->apdev); *apdev_priv = *pDevice; eth_hw_addr_inherit(pDevice->apdev, dev); pDevice->apdev->netdev_ops = &apdev_netdev_ops; pDevice->apdev->type = ARPHRD_IEEE80211; pDevice->apdev->base_addr = dev->base_addr; pDevice->apdev->irq = dev->irq; pDevice->apdev->mem_start = dev->mem_start; pDevice->apdev->mem_end = dev->mem_end; sprintf(pDevice->apdev->name, "%sap", dev->name); if (rtnl_locked) ret = register_netdevice(pDevice->apdev); else ret = register_netdev(pDevice->apdev); if (ret) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n", dev->name); free_netdev(pDevice->apdev); pDevice->apdev = NULL; return -1; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n", dev->name, pDevice->apdev->name); KeyvInitTable(&pDevice->sKey, pDevice->PortOffset); return 0; } /* * Description: * unregister net_device(AP) * * Parameters: * In: * pDevice - * rtnl_locked - * Out: * * Return Value: * */ static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name); if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) { if (rtnl_locked) unregister_netdevice(pDevice->apdev); else unregister_netdev(pDevice->apdev); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n", pDevice->dev->name, pDevice->apdev->name); } if (pDevice->apdev) free_netdev(pDevice->apdev); pDevice->apdev = NULL; pDevice->bEnable8021x = false; pDevice->bEnableHostWEP = false; pDevice->bEncryptionEnable = false; //4.2007-0118-03,<Add> by EinsnLiu //execute some clear work pDevice->pMgmt->byCSSPK = KEY_CTL_NONE; pDevice->pMgmt->byCSSGK = KEY_CTL_NONE; KeyvInitTable(&pDevice->sKey, pDevice->PortOffset); return 0; }
/** * lbs_add_mesh - add mshX interface * * @priv: A pointer to the &struct lbs_private structure * returns: 0 if successful, -X otherwise */ static int lbs_add_mesh(struct lbs_private *priv) { struct net_device *mesh_dev = NULL; struct wireless_dev *mesh_wdev; int ret = 0; /* Allocate a virtual mesh device */ mesh_wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL); if (!mesh_wdev) { lbs_deb_mesh("init mshX wireless device failed\n"); ret = -ENOMEM; goto done; } mesh_dev = alloc_netdev(0, "msh%d", NET_NAME_UNKNOWN, ether_setup); if (!mesh_dev) { lbs_deb_mesh("init mshX device failed\n"); ret = -ENOMEM; goto err_free_wdev; } mesh_wdev->iftype = NL80211_IFTYPE_MESH_POINT; mesh_wdev->wiphy = priv->wdev->wiphy; mesh_wdev->netdev = mesh_dev; mesh_dev->ml_priv = priv; mesh_dev->ieee80211_ptr = mesh_wdev; priv->mesh_dev = mesh_dev; mesh_dev->netdev_ops = &mesh_netdev_ops; mesh_dev->ethtool_ops = &lbs_ethtool_ops; eth_hw_addr_inherit(mesh_dev, priv->dev); SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent); mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST; /* Register virtual mesh interface */ ret = register_netdev(mesh_dev); if (ret) { pr_err("cannot register mshX virtual interface\n"); goto err_free_netdev; } ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group); if (ret) goto err_unregister; lbs_persist_config_init(mesh_dev); /* Everything successful */ ret = 0; goto done; err_unregister: unregister_netdev(mesh_dev); err_free_netdev: free_netdev(mesh_dev); err_free_wdev: kfree(mesh_wdev); done: return ret; }