]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/SnpDxe/Station_address.c
sync comments, fix function header, rename variable name to follow coding style.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Station_address.c
index e4c268f575ff108261825c8ba56f5dc695b71319..07df584a07cb88c998ac50425867f9f3b62da59b 100644 (file)
@@ -1,21 +1,15 @@
 /** @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
+    Implementation of reading the MAC address of a network adapter.\r
\r
+Copyright (c) 2004 - 2007, Intel Corporation. <BR> \r
+All rights reserved. This program and the accompanying materials are licensed \r
+and made available under the terms and conditions of the BSD License which \r
+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
@@ -25,45 +19,47 @@ Revision history:
   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
+  @param  Snp         pointer to snp driver structure.\r
+   \r
+  @retval EFI_SUCCESS       the MAC address of the NIC is read successfully.\r
+  @retval EFI_DEVICE_ERROR  failed to read the MAC address of the NIC.\r
 \r
 **/\r
 EFI_STATUS\r
-pxe_get_stn_addr (\r
-  SNP_DRIVER *snp\r
+PxeGetStnAddr (\r
+  SNP_DRIVER *Snp\r
   )\r
 {\r
-  PXE_DB_STATION_ADDRESS  *db;\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
+  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
+  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
+  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
+  Snp->Cdb.StatCode   = PXE_STATCODE_INITIALIZE;\r
+  Snp->Cdb.StatFlags  = PXE_STATFLAGS_INITIALIZE;\r
+  Snp->Cdb.IFnum      = Snp->IfNum;\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
+  (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);\r
 \r
-  if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\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
+      Snp->Cdb.StatFlags,\r
+      Snp->Cdb.StatCode)\r
       );\r
 \r
     return EFI_DEVICE_ERROR;\r
@@ -72,21 +68,21 @@ pxe_get_stn_addr (
   // 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
+    &(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
+    &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
+    &Snp->Mode.PermanentAddress,\r
+    &Db->PermanentAddr,\r
+    Snp->Mode.HwAddressSize\r
     );\r
 \r
   return EFI_SUCCESS;\r
@@ -96,7 +92,7 @@ pxe_get_stn_addr (
 /**\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  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
@@ -104,55 +100,55 @@ pxe_get_stn_addr (
 \r
 **/\r
 EFI_STATUS\r
-pxe_set_stn_addr (\r
-  SNP_DRIVER      *snp,\r
+PxeSetStnAddr (\r
+  SNP_DRIVER      *Snp,\r
   EFI_MAC_ADDRESS *NewMacAddr\r
   )\r
 {\r
-  PXE_CPB_STATION_ADDRESS *cpb;\r
-  PXE_DB_STATION_ADDRESS  *db;\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
+  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
+    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
+    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
+    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
+    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
+  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
+  Snp->Cdb.StatCode   = PXE_STATCODE_INITIALIZE;\r
+  Snp->Cdb.StatFlags  = PXE_STATFLAGS_INITIALIZE;\r
+  Snp->Cdb.IFnum      = Snp->IfNum;\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
+  (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);\r
 \r
-  if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) {\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
+      Snp->Cdb.StatFlags,\r
+      Snp->Cdb.StatCode)\r
       );\r
 \r
     //\r
@@ -163,54 +159,72 @@ pxe_set_stn_addr (
   //\r
   // read the changed address and save it in SNP->Mode structure\r
   //\r
-  pxe_get_stn_addr (snp);\r
+  PxeGetStnAddr (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
+  Modifies or resets the current station address, if supported.\r
+  \r
+  This function modifies or resets the current station address of a network \r
+  interface, if supported. If Reset is TRUE, then the current station address is\r
+  set to the network interface’s permanent address. If Reset is FALSE, and the \r
+  network interface allows its station address to be modified, then the current \r
+  station address is changed to the address specified by New. If the network \r
+  interface does not allow its station address to be modified, then \r
+  EFI_INVALID_PARAMETER will be returned. If the station address is successfully\r
+  updated on the network interface, EFI_SUCCESS will be returned. If the driver\r
+  has not been initialized, EFI_DEVICE_ERROR will be returned.\r
+\r
+  @param This  A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
+  @param Reset Flag used to reset the station address to the network interface’s \r
+               permanent address.\r
+  @param New   New station address to be used for the network interface.\r
+\r
+\r
+  @retval EFI_SUCCESS           The network interface’s station address was updated.\r
+  @retval EFI_NOT_STARTED       The Simple Network Protocol interface has not been \r
+                                started by calling Start().\r
+  @retval EFI_INVALID_PARAMETER The New station address was not accepted by the NIC.\r
+  @retval EFI_INVALID_PARAMETER Reset is FALSE and New is NULL.\r
+  @retval EFI_DEVICE_ERROR      The Simple Network Protocol interface has not \r
+                                been initialized by calling Initialize().\r
+  @retval EFI_DEVICE_ERROR      An error occurred attempting to set the new \r
+                                station address.\r
+  @retval EFI_UNSUPPORTED       The NIC does not support changing the network \r
+                                interface’s station address.\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
+SnpUndi32StationAddress (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
+  IN BOOLEAN                     Reset,\r
+  IN EFI_MAC_ADDRESS             *New OPTIONAL\r
   )\r
 {\r
-  SNP_DRIVER  *snp;\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
+  if ((This == NULL) ||\r
+    (!Reset && (New == NULL))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);\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
+  switch (Snp->Mode.State) {\r
   case EfiSimpleNetworkInitialized:\r
     break;\r
 \r
@@ -223,10 +237,10 @@ snp_undi32_station_address (
     goto ON_EXIT;\r
   }\r
 \r
-  if (ResetFlag) {\r
-    Status = pxe_set_stn_addr (snp, NULL);\r
+  if (Reset) {\r
+    Status = PxeSetStnAddr (Snp, NULL);\r
   } else {\r
-    Status = pxe_set_stn_addr (snp, NewMacAddr);\r
+    Status = PxeSetStnAddr (Snp, New);\r
   }\r
 \r
 ON_EXIT:\r