--- /dev/null
+/** @file\r
+Copyright (c) 2004 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module name:\r
+ station_address.c\r
+\r
+Abstract:\r
+\r
+Revision history:\r
+ 2000-Feb-17 M(f)J Genesis.\r
+\r
+**/\r
+\r
+#include "Snp.h"\r
+\r
+\r
+/**\r
+ this routine calls undi to read the MAC address of the NIC and updates the\r
+ mode structure with the address.\r
+\r
+ @param snp pointer to snp driver structure\r
+\r
+\r
+**/\r
+EFI_STATUS\r
+pxe_get_stn_addr (\r
+ SNP_DRIVER *snp\r
+ )\r
+{\r
+ PXE_DB_STATION_ADDRESS *db;\r
+\r
+ db = snp->db;\r
+ snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;\r
+ snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;\r
+\r
+ snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
+ snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
+\r
+ snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS);\r
+ snp->cdb.DBaddr = (UINT64)(UINTN) db;\r
+\r
+ snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
+ snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
+ snp->cdb.IFnum = snp->if_num;\r
+ snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
+\r
+ //\r
+ // Issue UNDI command and check result.\r
+ //\r
+ DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() "));\r
+\r
+ (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r
+\r
+ if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\r
+ DEBUG (\r
+ (EFI_D_ERROR,\r
+ "\nsnp->undi.station_addr() %xh:%xh\n",\r
+ snp->cdb.StatFlags,\r
+ snp->cdb.StatCode)\r
+ );\r
+\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+ //\r
+ // Set new station address in SNP->Mode structure and return success.\r
+ //\r
+ CopyMem (\r
+ &(snp->mode.CurrentAddress),\r
+ &db->StationAddr,\r
+ snp->mode.HwAddressSize\r
+ );\r
+\r
+ CopyMem (\r
+ &snp->mode.BroadcastAddress,\r
+ &db->BroadcastAddr,\r
+ snp->mode.HwAddressSize\r
+ );\r
+\r
+ CopyMem (\r
+ &snp->mode.PermanentAddress,\r
+ &db->PermanentAddr,\r
+ snp->mode.HwAddressSize\r
+ );\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+ this routine calls undi to set a new MAC address for the NIC,\r
+\r
+ @param snp pointer to snp driver structure\r
+ @param NewMacAddr pointer to a mac address to be set for the nic, if this is\r
+ NULL then this routine resets the mac address to the NIC's\r
+ original address.\r
+\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+pxe_set_stn_addr (\r
+ SNP_DRIVER *snp,\r
+ EFI_MAC_ADDRESS *NewMacAddr\r
+ )\r
+{\r
+ PXE_CPB_STATION_ADDRESS *cpb;\r
+ PXE_DB_STATION_ADDRESS *db;\r
+\r
+ cpb = snp->cpb;\r
+ db = snp->db;\r
+ snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS;\r
+\r
+ if (NewMacAddr == NULL) {\r
+ snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_RESET;\r
+ snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
+ snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
+ } else {\r
+ snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ;\r
+ //\r
+ // even though the OPFLAGS are set to READ, supplying a new address\r
+ // in the CPB will make undi change the mac address to the new one.\r
+ //\r
+ CopyMem (&cpb->StationAddr, NewMacAddr, snp->mode.HwAddressSize);\r
+\r
+ snp->cdb.CPBsize = sizeof (PXE_CPB_STATION_ADDRESS);\r
+ snp->cdb.CPBaddr = (UINT64)(UINTN) cpb;\r
+ }\r
+\r
+ snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS);\r
+ snp->cdb.DBaddr = (UINT64)(UINTN) db;\r
+\r
+ snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
+ snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
+ snp->cdb.IFnum = snp->if_num;\r
+ snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
+\r
+ //\r
+ // Issue UNDI command and check result.\r
+ //\r
+ DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() "));\r
+\r
+ (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r
+\r
+ if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\r
+ DEBUG (\r
+ (EFI_D_ERROR,\r
+ "\nsnp->undi.station_addr() %xh:%xh\n",\r
+ snp->cdb.StatFlags,\r
+ snp->cdb.StatCode)\r
+ );\r
+\r
+ //\r
+ // UNDI command failed. Return UNDI status to caller.\r
+ //\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+ //\r
+ // read the changed address and save it in SNP->Mode structure\r
+ //\r
+ pxe_get_stn_addr (snp);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+ This is the SNP interface routine for changing the NIC's mac address.\r
+ This routine basically retrieves snp structure, checks the SNP state and\r
+ calls the above routines to actually do the work\r
+\r
+ @param this context pointer\r
+ @param NewMacAddr pointer to a mac address to be set for the nic, if this is\r
+ NULL then this routine resets the mac address to the NIC's\r
+ original address.\r
+ @param ResetFlag If true, the mac address will change to NIC's original\r
+ address\r
+\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+snp_undi32_station_address (\r
+ IN EFI_SIMPLE_NETWORK_PROTOCOL * this,\r
+ IN BOOLEAN ResetFlag,\r
+ IN EFI_MAC_ADDRESS * NewMacAddr OPTIONAL\r
+ )\r
+{\r
+ SNP_DRIVER *snp;\r
+ EFI_STATUS Status;\r
+ EFI_TPL OldTpl;\r
+\r
+ //\r
+ // Check for invalid parameter combinations.\r
+ //\r
+ if ((this == NULL) ||\r
+ (!ResetFlag && (NewMacAddr == NULL))) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);\r
+\r
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+ //\r
+ // Return error if the SNP is not initialized.\r
+ //\r
+ switch (snp->mode.State) {\r
+ case EfiSimpleNetworkInitialized:\r
+ break;\r
+\r
+ case EfiSimpleNetworkStopped:\r
+ Status = EFI_NOT_STARTED;\r
+ goto ON_EXIT;\r
+\r
+ default:\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto ON_EXIT;\r
+ }\r
+\r
+ if (ResetFlag) {\r
+ Status = pxe_set_stn_addr (snp, NULL);\r
+ } else {\r
+ Status = pxe_set_stn_addr (snp, NewMacAddr);\r
+ }\r
+\r
+ON_EXIT:\r
+ gBS->RestoreTPL (OldTpl);\r
+\r
+ return Status;\r
+}\r