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.

pxeparent_dhcp.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 2009 Joshua Oreman <oremanj@rwcr.net>.
  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 <ipxe/dhcp.h>
  21. #include <ipxe/netdevice.h>
  22. #include <undipreload.h>
  23. #include <pxeparent.h>
  24. #include <realmode.h>
  25. #include <pxe_api.h>
  26. /**
  27. * Present cached DHCP packet if it exists
  28. */
  29. void get_cached_dhcpack ( void ) {
  30. struct undi_device *undi;
  31. struct s_PXENV_GET_CACHED_INFO get_cached_info;
  32. int rc;
  33. /* Use preloaded UNDI device to get at PXE entry point */
  34. undi = &preloaded_undi;
  35. if ( ! undi->entry.segment ) {
  36. DBG ( "PXEDHCP no preloaded UNDI device found\n" );
  37. return;
  38. }
  39. /* Check that stack is available to get cached info */
  40. if ( ! ( undi->flags & UNDI_FL_KEEP_ALL ) ) {
  41. DBG ( "PXEDHCP stack was unloaded, no cache available\n" );
  42. return;
  43. }
  44. /* Obtain cached DHCP packet */
  45. memset ( &get_cached_info, 0, sizeof ( get_cached_info ) );
  46. get_cached_info.PacketType = PXENV_PACKET_TYPE_DHCP_ACK;
  47. if ( ( rc = pxeparent_call ( undi->entry, PXENV_GET_CACHED_INFO,
  48. &get_cached_info,
  49. sizeof ( get_cached_info ) ) ) != 0 ) {
  50. DBG ( "PXEDHCP GET_CACHED_INFO failed: %s\n", strerror ( rc ) );
  51. return;
  52. }
  53. DBG ( "PXEDHCP got cached info at %04x:%04x length %d\n",
  54. get_cached_info.Buffer.segment, get_cached_info.Buffer.offset,
  55. get_cached_info.BufferSize );
  56. /* Present cached DHCP packet */
  57. store_cached_dhcpack ( real_to_user ( get_cached_info.Buffer.segment,
  58. get_cached_info.Buffer.offset ),
  59. get_cached_info.BufferSize );
  60. }