Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

hitachi.c

Go to the documentation of this file.
00001 /*! \file hitachi.c
00002     This file implements special Hitachi's MAC address processing.
00003  */
00004 
00005 
00006 #include <string.h>
00007 
00008 
00009 /*! \brief Subtract 4 from a given digit.
00010     \author Denis BEURIVE
00011     \param car Hexadecimal character that represents the digit.
00012     \param carry Pointer to an integer that will be used to signal a possible crry. The value
00013                  pointed by "carry" can be:
00014                  <ul>
00015                     <li>0: no carry.
00016                     <li>1: carry.
00017                  </ul>
00018     \return The function returns the value "car-4" in hexadecimal.
00019  */
00020 
00021 
00022 static char minus4 (char car, int *carry)
00023 {
00024   switch (car)
00025   {
00026     case 'F': *carry=0; return 'B';
00027     case 'E': *carry=0; return 'A';
00028     case 'D': *carry=0; return '9';
00029     case 'C': *carry=0; return '8';
00030     case 'B': *carry=0; return '7';
00031     case 'A': *carry=0; return '6';
00032     case '9': *carry=0; return '5';
00033     case '8': *carry=0; return '4';
00034     case '7': *carry=0; return '3';
00035     case '6': *carry=0; return '2';
00036     case '5': *carry=0; return '1';
00037     case '4': *carry=0; return '0';
00038     case '3': *carry=1; return 'F';
00039     case '2': *carry=1; return 'E';
00040     case '1': *carry=1; return 'D';
00041     case '0': *carry=1; return 'C';
00042   }
00043 
00044   *carry=0;
00045   return 'X';
00046 }
00047 
00048 /*! \brief Subtract 1 from a given digit.
00049     \author Denis BEURIVE
00050     \param car Hexadecimal character that represents the digit.
00051     \param carry Pointer to an integer that will be used to signal a possible crry. The value
00052                  pointed by "carry" can be:
00053                  <ul>
00054                     <li>0: no carry.
00055                     <li>1: carry.
00056                  </ul>
00057     \return The function returns the value "car-1" in hexadecimal.
00058  */
00059 
00060 static char minus1 (char car, int *carry)
00061 {
00062   switch (car)
00063   {
00064     case 'F': *carry=0; return 'E';
00065     case 'E': *carry=0; return 'D';
00066     case 'D': *carry=0; return 'C';
00067     case 'C': *carry=0; return 'B';
00068     case 'B': *carry=0; return 'A';
00069     case 'A': *carry=0; return '9';
00070     case '9': *carry=0; return '8';
00071     case '8': *carry=0; return '7';
00072     case '7': *carry=0; return '6';
00073     case '6': *carry=0; return '5';
00074     case '5': *carry=0; return '4';
00075     case '4': *carry=0; return '3';
00076     case '3': *carry=0; return '2';
00077     case '2': *carry=0; return '1';
00078     case '1': *carry=0; return '0';
00079     case '0': *carry=1; return 'F';
00080   }
00081 
00082   *carry=0;
00083   return 'X';
00084 }
00085 
00086 /*! \brief Subtract 4 from a given number writen in hexadecimal.
00087     \author Denis BEURIVE
00088     \param haddr Pointer to a zero terminated string of characters that represents the number
00089                  writen in hexadecimal base.
00090     \return The function returns a pointer to "haddr". The string "haddr" now represents the
00091             value "haddr-4".
00092     \warning This function modifies the content of the string pointed by "haddr"). If macro "USE_PLUGINS" is defined, then
00093              the function returns a pointer to a statically allocated buffer. Otherwize, the function returns "haddr" itself.
00094     \remark This function should be used to calculate the MAC address of an HITACHI modem.
00095  */
00096 
00097 char* calculate_mac (char *haddr)
00098 {
00099   int  i, carry, lastid;
00100   char r;
00101 
00102   #ifdef USE_PLUGINS
00103      static char new_mac[128];
00104      memset((void*)new_mac, 0, 128*sizeof(char));
00105   #endif
00106 
00107   lastid = strlen(haddr)-1;
00108 
00109   r = minus4 (haddr[lastid], &carry);
00110   haddr[lastid] = r;
00111 
00112   lastid--;
00113   for (i=lastid; ((i>=0) && carry); i--)
00114   {
00115     r = minus1 (haddr[i], &carry);
00116     haddr[i] = r;
00117   }
00118 
00119   #ifndef USE_PLUGINS
00120      return haddr;
00121   #else
00122      strncpy (new_mac, haddr, 127);
00123      return new_mac;
00124   #endif
00125 }
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 

Generated on Mon Jun 19 12:31:05 2006 for MyDhcp_V2 by doxygen1.2.15