012-serial-ether-addr.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. Index: linux-2.6.21.7/drivers/usb/gadget/ether.c
  2. ===================================================================
  3. --- linux-2.6.21.7.orig/drivers/usb/gadget/ether.c
  4. +++ linux-2.6.21.7/drivers/usb/gadget/ether.c
  5. @@ -2249,6 +2249,38 @@ static u8 __devinit nibble (unsigned cha
  6. return 0;
  7. }
  8. +static inline unsigned int is_gumstix_oui(u8 *addr)
  9. +{
  10. + return (addr[0] == 0x00 && addr[1] == 0x15 && addr[2] == 0xC9);
  11. +}
  12. +
  13. +/**
  14. + * gen_serial_ether_addr - Generate software assigned Ethernet address
  15. + * based on the system_serial number
  16. + * @addr: Pointer to a six-byte array containing the Ethernet address
  17. + *
  18. + * Generate an Ethernet address (MAC) that is not multicast
  19. + * and has the local assigned bit set, keyed on the system_serial
  20. + */
  21. +static inline void gen_serial_ether_addr(u8 *addr)
  22. +{
  23. + static u8 ether_serial_digit = 0;
  24. + addr [0] = system_serial_high >> 8;
  25. + addr [1] = system_serial_high;
  26. + addr [2] = system_serial_low >> 24;
  27. + addr [3] = system_serial_low >> 16;
  28. + addr [4] = system_serial_low >> 8;
  29. + addr [5] = (system_serial_low & 0xc0) | /* top bits are from system serial */
  30. + (2 << 4) | /* 2 bits identify interface type 1=ether, 2=usb, 3&4 undef */
  31. + ((ether_serial_digit++) & 0x0f); /* 15 possible interfaces of each type */
  32. +
  33. + if(!is_gumstix_oui(addr))
  34. + {
  35. + addr [0] &= 0xfe; /* clear multicast bit */
  36. + addr [0] |= 0x02; /* set local assignment bit (IEEE802) */
  37. + }
  38. +}
  39. +
  40. static int __devinit get_ether_addr(const char *str, u8 *dev_addr)
  41. {
  42. if (str) {
  43. @@ -2266,8 +2298,16 @@ static int __devinit get_ether_addr(cons
  44. if (is_valid_ether_addr (dev_addr))
  45. return 0;
  46. }
  47. - random_ether_addr(dev_addr);
  48. - return 1;
  49. + if(system_serial_high | system_serial_low)
  50. + {
  51. + gen_serial_ether_addr(dev_addr);
  52. + return 0;
  53. + }
  54. + else
  55. + {
  56. + random_ether_addr(dev_addr);
  57. + return 1;
  58. + }
  59. }
  60. static int __devinit