• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 FILE_LICENCE ( GPL2_OR_LATER );
20 
21 #include <string.h>
22 #include <gpxe/dhcp.h>
23 #include <gpxe/netdevice.h>
24 #include <undipreload.h>
25 #include <pxeparent.h>
26 #include <realmode.h>
27 #include <pxe_api.h>
28 
29 /**
30  * Present cached DHCP packet if it exists
31  */
__weak_impl(get_cached_dhcpack)32 void __weak_impl ( get_cached_dhcpack ) ( void ) {
33 	struct undi_device *undi;
34 	struct s_PXENV_GET_CACHED_INFO get_cached_info;
35 	int rc;
36 
37 	/* Use preloaded UNDI device to get at PXE entry point */
38 	undi = &preloaded_undi;
39 	if ( ! undi->entry.segment ) {
40 		DBG ( "PXEDHCP no preloaded UNDI device found\n" );
41 		return;
42 	}
43 
44 	/* Check that stack is available to get cached info */
45 	if ( ! ( undi->flags & UNDI_FL_KEEP_ALL ) ) {
46 		DBG ( "PXEDHCP stack was unloaded, no cache available\n" );
47 		return;
48 	}
49 
50 	/* Obtain cached DHCP packet */
51 	memset ( &get_cached_info, 0, sizeof ( get_cached_info ) );
52 	get_cached_info.PacketType = PXENV_PACKET_TYPE_DHCP_ACK;
53 
54 	if ( ( rc = pxeparent_call ( undi->entry, PXENV_GET_CACHED_INFO,
55 				     &get_cached_info,
56 				     sizeof ( get_cached_info ) ) ) != 0 ) {
57 		DBG ( "PXEDHCP GET_CACHED_INFO failed: %s\n", strerror ( rc ) );
58 		return;
59 	}
60 
61 	DBG ( "PXEDHCP got cached info at %04x:%04x length %d\n",
62 	      get_cached_info.Buffer.segment, get_cached_info.Buffer.offset,
63 	      get_cached_info.BufferSize );
64 
65 	/* Present cached DHCP packet */
66 	store_cached_dhcpack ( real_to_user ( get_cached_info.Buffer.segment,
67 					      get_cached_info.Buffer.offset ),
68 			       get_cached_info.BufferSize );
69 }
70