選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

netdev_settings.c 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include <string.h>
  19. #include <errno.h>
  20. #include <gpxe/dhcp.h>
  21. #include <gpxe/settings.h>
  22. #include <gpxe/netdevice.h>
  23. /** @file
  24. *
  25. * Network device configuration settings
  26. *
  27. */
  28. /**
  29. * Store value of network device setting
  30. *
  31. * @v settings Settings block
  32. * @v tag Setting tag number
  33. * @v data Setting data, or NULL to clear setting
  34. * @v len Length of setting data
  35. * @ret rc Return status code
  36. */
  37. static int netdev_store ( struct settings *settings, unsigned int tag,
  38. const void *data, size_t len ) {
  39. struct net_device *netdev = container_of ( settings, struct net_device,
  40. settings.settings );
  41. switch ( tag ) {
  42. case DHCP_EB_MAC:
  43. if ( len != netdev->ll_protocol->ll_addr_len )
  44. return -EINVAL;
  45. memcpy ( netdev->ll_addr, data, len );
  46. return 0;
  47. default :
  48. return simple_settings_store ( settings, tag, data, len );
  49. }
  50. }
  51. /**
  52. * Fetch value of network device setting
  53. *
  54. * @v settings Settings block
  55. * @v tag Setting tag number
  56. * @v data Setting data, or NULL to clear setting
  57. * @v len Length of setting data
  58. * @ret rc Return status code
  59. */
  60. static int netdev_fetch ( struct settings *settings, unsigned int tag,
  61. void *data, size_t len ) {
  62. struct net_device *netdev = container_of ( settings, struct net_device,
  63. settings.settings );
  64. switch ( tag ) {
  65. case DHCP_EB_MAC:
  66. if ( len > netdev->ll_protocol->ll_addr_len )
  67. len = netdev->ll_protocol->ll_addr_len;
  68. memcpy ( data, netdev->ll_addr, len );
  69. return netdev->ll_protocol->ll_addr_len;
  70. default :
  71. return simple_settings_fetch ( settings, tag, data, len );
  72. }
  73. }
  74. /** Network device configuration settings operations */
  75. struct settings_operations netdev_settings_operations = {
  76. .store = netdev_store,
  77. .fetch = netdev_fetch,
  78. };
  79. /** Network device named settings */
  80. struct named_setting netdev_named_settings[] __named_setting = {
  81. {
  82. .name = "mac",
  83. .description = "MAC address",
  84. .tag = DHCP_EB_MAC,
  85. .type = &setting_type_hex,
  86. },
  87. };