dhcpmgmt.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 #include <string.h>
00022 #include <stdio.h>
00023 #include <errno.h>
00024 #include <gpxe/netdevice.h>
00025 #include <gpxe/dhcp.h>
00026 #include <gpxe/monojob.h>
00027 #include <gpxe/process.h>
00028 #include <usr/ifmgmt.h>
00029 #include <usr/dhcpmgmt.h>
00030 
00031 #define LINK_WAIT_MS    15000
00032 
00033 /** @file
00034  *
00035  * DHCP management
00036  *
00037  */
00038 
00039 int dhcp ( struct net_device *netdev ) {
00040         uint8_t *chaddr;
00041         uint8_t hlen;
00042         uint16_t flags;
00043         int rc;
00044 
00045         /* Check we can open the interface first */
00046         if ( ( rc = ifopen ( netdev ) ) != 0 )
00047                 return rc;
00048 
00049         /* Wait for link-up */
00050         if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 )
00051                 return rc;
00052 
00053         /* Perform DHCP */
00054         chaddr = dhcp_chaddr ( netdev, &hlen, &flags );
00055         printf ( "DHCP (%s ", netdev->name );
00056         while ( hlen-- )
00057                 printf ( "%02x%c", *(chaddr++), ( hlen ? ':' : ')' ) );
00058 
00059         if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 ) {
00060                 rc = monojob_wait ( "" );
00061         } else if ( rc > 0 ) {
00062                 printf ( " using cached\n" );
00063                 rc = 0;
00064         }
00065 
00066         return rc;
00067 }
00068 
00069 int pxebs ( struct net_device *netdev, unsigned int pxe_type ) {
00070         int rc;
00071 
00072         /* Perform PXE Boot Server Discovery */
00073         printf ( "PXEBS (%s type %d)", netdev->name, pxe_type );
00074         if ( ( rc = start_pxebs ( &monojob, netdev, pxe_type ) ) == 0 )
00075                 rc = monojob_wait ( "" );
00076 
00077         return rc;
00078 }

Generated on Tue Apr 6 20:01:11 2010 for gPXE by  doxygen 1.5.7.1