static void resp_handler(struct spi_wifi_eth *wifi_device, struct spi_wifi_resp *resp) { struct spi_wifi_resp *resp_return; switch (resp->cmd) { case SPI_WIFI_CMD_INIT: WIFI_DEBUG("resp_handler SPI_WIFI_CMD_INIT\n"); resp_return = (struct spi_wifi_resp *)rt_malloc(sizeof(struct spi_wifi_resp)); //TODO: memcpy(resp_return, resp, 10); rt_mb_send(&wifi_device->spi_wifi_cmd_mb, (rt_uint32_t)resp_return); break; case SPI_WIFI_CMD_SCAN: WIFI_DEBUG("resp_handler SPI_WIFI_CMD_SCAN\n"); break; case SPI_WIFI_CMD_JOIN: WIFI_DEBUG("resp_handler SPI_WIFI_CMD_JOIN\n"); wifi_device->active = 1; eth_device_linkchange(&wifi_device->parent, RT_TRUE); break; default: WIFI_DEBUG("resp_handler %d\n", resp->cmd); break; } }
void rt_wlan_linkchange(rt_bool_t enable) { eth_device_linkchange(&(wlan_eth.parent), enable); }
static rt_err_t mrvl_wlan_associate(struct rt_wlan_device* device) { WlanCard *card; rt_err_t result = RT_EOK; WlanConfig *config; RT_ASSERT(device != RT_NULL); card = WLAN_CARD(device); if (device->ssid[0] == '\0') return -RT_ERROR; /* set mode */ if (device->mode == WLAN_MODE_INFRA) card->InfrastructureMode = Wlan802_11Infrastructure; else card->InfrastructureMode = Wlan802_11IBSS; wlan_set_infrastructure(card); config = (WlanConfig*) rt_calloc(1, sizeof(WlanConfig)); if (config == RT_NULL) return -RT_ENOMEM; config->channel = device->channel; /* copy SSID and base station address */ rt_strncpy(config->SSID, device->ssid, SSID_NAME_MAX); memcpy(config->MacAddr, device->bs_addr, MAC_LENGTH_MAX); if (device->password[0] == '\0') config->security = NoSecurity; else { switch (device->security) { case WLAN_SECURITY_WEP: config->security = WEP; break; case WLAN_SECURITY_WPA: config->security = WPA_PSK; break; case WLAN_SECURITY_WPA2: config->security = WPA2_PSK; break; default: config->security = 0; break; } rt_strncpy(config->password, device->password, PASSWORD_LENGTH_MAX); } if (device->channel == 0xff) { /* try to scan AP */ mrvl_scan_card(device, config); } if (config->channel == 0xff) { rt_kprintf("not found AP\n"); return -RT_ERROR; } /* set wlan status */ device->status = WLAN_STATUS_CONNECTING; result = wlan_cmd_802_11_associate_cfg(card, config); if (result != WLAN_STATUS_SUCCESS) { /* try to scan AP */ mrvl_scan_card(device, config); /* associate again */ result = wlan_cmd_802_11_associate_cfg(card, config); } if (card->MediaConnectStatus == WlanMediaStateConnected) device->status = WLAN_STATUS_CONNECTED; else device->status = WLAN_STATUS_IDLE; /* save information on the wlan device */ device->channel = config->channel; device->security = config->security; memcpy(device->bs_addr, config->MacAddr, sizeof(device->bs_addr)); rt_free(config); if (device->status == WLAN_STATUS_CONNECTED) { eth_device_linkchange(&device->parent, RT_TRUE); return RT_EOK; } return -RT_ERROR; }
int rt_hw_eth_init(void) { u64 base_addr = Gmac_base; struct synopGMACNetworkAdapter *synopGMACadapter; static u8 mac_addr0[6] = DEFAULT_MAC_ADDRESS; int index; rt_sem_init(&sem_ack, "tx_ack", 1, RT_IPC_FLAG_FIFO); rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO); for (index = 21; index <= 30; index++) { pin_set_purpose(index, PIN_PURPOSE_OTHER); pin_set_remap(index, PIN_REMAP_DEFAULT); } pin_set_purpose(35, PIN_PURPOSE_OTHER); pin_set_remap(35, PIN_REMAP_DEFAULT); *((volatile unsigned int *)0xbfd00424) &= ~(7 << 28); *((volatile unsigned int *)0xbfd00424) |= (1 << 30); //wl rmii memset(ð_dev, 0, sizeof(eth_dev)); synopGMACadapter = (struct synopGMACNetworkAdapter *)plat_alloc_memory(sizeof(struct synopGMACNetworkAdapter)); if (!synopGMACadapter) { rt_kprintf("Error in Memory Allocataion, Founction : %s \n", __FUNCTION__); } memset((char *)synopGMACadapter, 0, sizeof(struct synopGMACNetworkAdapter)); synopGMACadapter->synopGMACdev = NULL; synopGMACadapter->synopGMACdev = (synopGMACdevice *) plat_alloc_memory(sizeof(synopGMACdevice)); if (!synopGMACadapter->synopGMACdev) { rt_kprintf("Error in Memory Allocataion, Founction : %s \n", __FUNCTION__); } memset((char *)synopGMACadapter->synopGMACdev, 0, sizeof(synopGMACdevice)); /* * Attach the device to MAC struct This will configure all the required base addresses * such as Mac base, configuration base, phy base address(out of 32 possible phys) * */ synopGMAC_attach(synopGMACadapter->synopGMACdev, (regbase + MACBASE), regbase + DMABASE, DEFAULT_PHY_BASE, mac_addr0); init_phy(synopGMACadapter->synopGMACdev); synopGMAC_reset(synopGMACadapter->synopGMACdev); /* MII setup */ synopGMACadapter->mii.phy_id_mask = 0x1F; synopGMACadapter->mii.reg_num_mask = 0x1F; synopGMACadapter->mii.dev = synopGMACadapter; synopGMACadapter->mii.mdio_read = mdio_read; synopGMACadapter->mii.mdio_write = mdio_write; synopGMACadapter->mii.phy_id = synopGMACadapter->synopGMACdev->PhyBase; synopGMACadapter->mii.supports_gmii = mii_check_gmii_support(&synopGMACadapter->mii); eth_dev.iobase = base_addr; eth_dev.name = "e0"; eth_dev.priv = synopGMACadapter; eth_dev.dev_addr[0] = mac_addr0[0]; eth_dev.dev_addr[1] = mac_addr0[1]; eth_dev.dev_addr[2] = mac_addr0[2]; eth_dev.dev_addr[3] = mac_addr0[3]; eth_dev.dev_addr[4] = mac_addr0[4]; eth_dev.dev_addr[5] = mac_addr0[5]; eth_dev.parent.parent.type = RT_Device_Class_NetIf; eth_dev.parent.parent.init = eth_init; eth_dev.parent.parent.open = eth_open; eth_dev.parent.parent.close = eth_close; eth_dev.parent.parent.read = eth_read; eth_dev.parent.parent.write = eth_write; eth_dev.parent.parent.control = eth_control; eth_dev.parent.parent.user_data = RT_NULL; eth_dev.parent.eth_tx = rt_eth_tx; eth_dev.parent.eth_rx = rt_eth_rx; eth_device_init(&(eth_dev.parent), "e0"); eth_device_linkchange(ð_dev.parent, RT_TRUE); //linkup the e0 for lwip to check return 0; }