You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

netdev_settings.c 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <string.h>
  20. #include <errno.h>
  21. #include <gpxe/dhcp.h>
  22. #include <gpxe/settings.h>
  23. #include <gpxe/netdevice.h>
  24. /** @file
  25. *
  26. * Network device configuration settings
  27. *
  28. */
  29. /** Network device named settings */
  30. struct setting mac_setting __setting = {
  31. .name = "mac",
  32. .description = "MAC address",
  33. .type = &setting_type_hex,
  34. };
  35. /**
  36. * Store value of network device setting
  37. *
  38. * @v settings Settings block
  39. * @v setting Setting to store
  40. * @v data Setting data, or NULL to clear setting
  41. * @v len Length of setting data
  42. * @ret rc Return status code
  43. */
  44. static int netdev_store ( struct settings *settings, struct setting *setting,
  45. const void *data, size_t len ) {
  46. struct net_device *netdev = container_of ( settings, struct net_device,
  47. settings.settings );
  48. if ( setting_cmp ( setting, &mac_setting ) == 0 ) {
  49. if ( len != netdev->ll_protocol->ll_addr_len )
  50. return -EINVAL;
  51. memcpy ( netdev->ll_addr, data, len );
  52. return 0;
  53. }
  54. return generic_settings_store ( settings, setting, data, len );
  55. }
  56. /**
  57. * Fetch value of network device setting
  58. *
  59. * @v settings Settings block
  60. * @v setting Setting to fetch
  61. * @v data Setting data, or NULL to clear setting
  62. * @v len Length of setting data
  63. * @ret rc Return status code
  64. */
  65. static int netdev_fetch ( struct settings *settings, struct setting *setting,
  66. void *data, size_t len ) {
  67. struct net_device *netdev = container_of ( settings, struct net_device,
  68. settings.settings );
  69. if ( setting_cmp ( setting, &mac_setting ) == 0 ) {
  70. if ( len > netdev->ll_protocol->ll_addr_len )
  71. len = netdev->ll_protocol->ll_addr_len;
  72. memcpy ( data, netdev->ll_addr, len );
  73. return netdev->ll_protocol->ll_addr_len;
  74. }
  75. return generic_settings_fetch ( settings, setting, data, len );
  76. }
  77. /**
  78. * Clear network device settings
  79. *
  80. * @v settings Settings block
  81. */
  82. static void netdev_clear ( struct settings *settings ) {
  83. generic_settings_clear ( settings );
  84. }
  85. /** Network device configuration settings operations */
  86. struct settings_operations netdev_settings_operations = {
  87. .store = netdev_store,
  88. .fetch = netdev_fetch,
  89. .clear = netdev_clear,
  90. };