bootinfo.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <dhcp_impl.h>
#include <netinet/inetutil.h>
#include <strings.h>
#if defined(_BOOT)
#include <ipv4.h>
#include <dhcpv4.h>
#endif /* defined(_BOOT) */
#include <bootinfo.h>
#include <bootinfo_aux.h>
/*
* Declarations and definitions describing parameters which may be known by
* a bootconf name, a property of /chosen, a DHCP option or a 'bootmisc' name.
*/
typedef struct {
const char *opt_name; /* DHCP option name */
} bi_dhcpopt_t;
/*
* Possible values for the 'bi_flags' field below.
*/
typedef struct {
const char *bi_name; /* parameter name */
int bi_repository; /* entry's repository(s) */
int bi_flags; /* BI_F_BYTES or zero */
} bi_param_t;
/*
* DHCP options which have bootinfo equivalents, and the information
* necessary to retrieve their values via dhcp_getinfo(). The 'type'
* is necessary so that all values may be converted to ascii strings.
*/
static bi_dhcpopt_t Yiaddr = {
};
static bi_dhcpopt_t Subnet = {
};
static bi_dhcpopt_t Router = {
};
static bi_dhcpopt_t Hostname = {
};
static bi_dhcpopt_t ClientID = {
};
static bi_dhcpopt_t SHTTPproxy = {
};
#if defined(_BOOT)
static bi_dhcpopt_t BootFile = {
};
static bi_dhcpopt_t SbootURI = {
};
#else
static bi_dhcpopt_t SsysidCF = {
};
static bi_dhcpopt_t SjumpsCF = {
};
#endif /* defined(_BOOT) */
/*
* bootinfo's main data structure.
*/
static bi_param_t bi_params[] = {
/*
* Parameters from /chosen or DHCP:
*/
0, &Yiaddr },
0, &Subnet },
0, &Router },
0, &Hostname },
BI_F_BYTES, &ClientID },
0, &SHTTPproxy },
#if defined(_BOOT)
/*
* Parameters from /chosen or DHCP:
*/
0, &SbootURI },
/*
* Parameters from DHCP only:
*/
0, &BootFile },
/*
* Parameters from /chosen only:
*/
BI_F_BYTES, NULL },
0, NULL },
/*
* Parameters from 'bootmisc' only:
*/
0, NULL },
BI_F_BYTES, NULL },
BI_F_BYTES, NULL },
BI_F_BYTES, NULL },
#else
/*
* Parameters from DHCP only:
*/
0, &SsysidCF },
0, &SjumpsCF },
/*
* Parameters from /chosen or 'bootmisc':
*/
0, NULL },
/*
* Parameters from 'bootmisc' only:
*/
0, NULL },
0, NULL },
#endif /* defined(_BOOT) */
};
/*
* Bootmisc data is handled internally as a nvpair list.
*/
/*
* Scan our parameter table to see whether 'name' matches any entry.
*/
static bi_param_t *
bi_find_param(const char *name)
{
return (bip);
}
}
return (NULL);
}
/*
* Functions for retrieving /chosen, DHCP and bootmisc data.
*/
static int
{
return (BI_E_NOVAL);
return (BI_E_BUF2SMALL);
}
return (BI_E_SUCCESS);
}
static int
{
void *val;
} else {
}
return (BI_E_NOVAL);
}
case DSYM_IP:
return (BI_E_BUF2SMALL);
}
break;
case DSYM_ASCII:
return (BI_E_BUF2SMALL);
break;
}
return (BI_E_SUCCESS);
}
static int
{
return (BI_E_NOVAL);
return (BI_E_BUF2SMALL);
}
return (BI_E_SUCCESS);
}
/*
* This is also called from the userland bootinfo_aux.c to initialize
* its bootmisc data.
*/
{
}
#if defined(_BOOT)
/*
* Functions for storing /chosen and bootmisc data.
*/
static int
{
}
static int
{
? BI_E_SUCCESS : BI_E_ERROR);
}
#endif /* defined(_BOOT) */
/*
* Deallocate resources, etc. after accessing bootinfo.
*/
void
bootinfo_end(void)
{
}
}
/*
* Perform bootinfo initialization.
*/
bootinfo_init(void)
{
if (!bi_init_bootinfo()) {
}
}
}
/*
* bootinfo_get(const char *name, void *valbuf, size_t *vallenp,
* int *repository);
*
* Obtain a value for a named boot parameter from one of a number of possible
* repositories:
*
* - stored properties under /chosen in the device tree;
* - returned DHCP data;
* - miscellaneous boot information, determined from the standalone or
* the kernel (depending on whether we're in the standalone or userland).
*
* These repositories are interrogated in the order listed above; the first
* one to match is value returned.
*
* Returns:
* 0 => successful, value copied to valbuf, length assigned to *vallen.
* >0 => error (BI_E_* codes defined in bootinfo.h)
*/
int *repositoryp)
{
int repositories;
int err;
/*
* Check whether we were successfully initialized.
*/
return (BI_E_ERROR);
}
/*
* Determine which repositories might be accessed; a NULL pointer
* means to (possibly) access them all.
*/
if (repositoryp != NULL) {
*repositoryp = 0;
} else {
}
/*
* Check that we know about this name in one or more of the
* requested repositories.
*/
return (BI_E_ILLNAME);
}
if (repositories == 0) {
return (BI_E_ILLNAME);
}
/*
* The caller may simply be enquiring whether a value is present:
*
* bootinfo_get(name, NULL, NULL, repository) == BI_E_BUF2SMALL
*
* indicates that there is a value, but doesn't fetch it.
*/
}
/*
* To retrieve a value, try the various repositories in order.
*/
if ((repositories & BI_R_CHOSEN) != 0 &&
if (repositoryp != NULL) {
}
return (err);
}
if ((repositories & BI_R_DHCPOPT) != 0 &&
if (repositoryp != NULL) {
}
return (err);
}
if ((repositories & BI_R_BOOTMISC) != 0 &&
if (repositoryp != NULL) {
}
return (err);
}
/*
* No-one has a value for 'name'.
*/
return (BI_E_NOVAL);
}
#if defined(_BOOT)
/*
* bootinfo_put(const char *name, char *valbuf, int vallen,
* int repository);
*
*
* Returns:
* 0 => successful, valbuf[0..vallen-1] bytes stored in repository
* >0 => error (BI_E_* codes defined in bootinfo.h)
*/
int
int repository)
{
/*
* Check whether we were successfully initialized.
*/
return (BI_E_ERROR);
}
/*
* Determine which repositories might be accessed; a zero value
* means to (possibly) access them all.
*/
if (repository == 0) {
}
/*
* Check that we know about this name in the specified repository,
* and that it may be written (note that DHCP options cannot be
* written).
*/
return (BI_E_ILLNAME);
}
return (BI_E_RDONLY);
}
/*
* To put the value, try the various repositories in order.
*/
}
}
return (BI_E_ERROR);
}
#endif /* defined(_BOOT) */