xref: /onnv-gate/usr/src/stand/lib/wanboot/bootinfo_aux.c (revision 789:b348f31ed315)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*789Sahrens  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <dhcp_impl.h>
310Sstevel@tonic-gate #include <sys/promif.h>
320Sstevel@tonic-gate #include <strings.h>
330Sstevel@tonic-gate #include <sys/salib.h>
340Sstevel@tonic-gate #include <dhcpv4.h>
350Sstevel@tonic-gate #include <bootinfo.h>
360Sstevel@tonic-gate #include <bootinfo_aux.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /*
390Sstevel@tonic-gate  * Functions dealing with bootinfo initialization/cleanup.
400Sstevel@tonic-gate  * Both no-ops in the standalone.
410Sstevel@tonic-gate  */
420Sstevel@tonic-gate boolean_t
bi_init_bootinfo(void)430Sstevel@tonic-gate bi_init_bootinfo(void)
440Sstevel@tonic-gate {
450Sstevel@tonic-gate 	return (B_TRUE);
460Sstevel@tonic-gate }
470Sstevel@tonic-gate 
480Sstevel@tonic-gate void
bi_end_bootinfo(void)490Sstevel@tonic-gate bi_end_bootinfo(void)
500Sstevel@tonic-gate {
510Sstevel@tonic-gate }
520Sstevel@tonic-gate 
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate  * Functions dealing with /chosen data.
550Sstevel@tonic-gate  */
560Sstevel@tonic-gate boolean_t
bi_get_chosen_prop(const char * name,void * valbuf,size_t * vallenp)570Sstevel@tonic-gate bi_get_chosen_prop(const char *name, void *valbuf, size_t *vallenp)
580Sstevel@tonic-gate {
59*789Sahrens 	static pnode_t	chosen;
600Sstevel@tonic-gate 	int		len;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	/*
630Sstevel@tonic-gate 	 * The standalone helpfully provides a function for getting a
640Sstevel@tonic-gate 	 * handle on /chosen; it prom_panic()'s if /chosen doesn't exist.
650Sstevel@tonic-gate 	 */
660Sstevel@tonic-gate 	if (chosen == OBP_NONODE) {
670Sstevel@tonic-gate 		chosen = prom_chosennode();
680Sstevel@tonic-gate 	}
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	/*
710Sstevel@tonic-gate 	 * Check for the existence/size of a property with name 'name';
720Sstevel@tonic-gate 	 * if found, and the receiving buffer is big enough, copy its value.
730Sstevel@tonic-gate 	 * If not, return the length of the buffer that would be needed
740Sstevel@tonic-gate 	 * to fullfill the request.
750Sstevel@tonic-gate 	 */
760Sstevel@tonic-gate 	if ((len = prom_getproplen(chosen, (char *)name)) == -1) {
770Sstevel@tonic-gate 		return (B_FALSE);
780Sstevel@tonic-gate 	}
790Sstevel@tonic-gate 	if (len <= *vallenp) {
800Sstevel@tonic-gate 		if (prom_getprop(chosen, (char *)name, (caddr_t)valbuf) == -1) {
810Sstevel@tonic-gate 			return (B_FALSE);
820Sstevel@tonic-gate 		}
830Sstevel@tonic-gate 	}
840Sstevel@tonic-gate 	*vallenp = len;
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 	return (B_TRUE);
870Sstevel@tonic-gate }
880Sstevel@tonic-gate 
890Sstevel@tonic-gate boolean_t
bi_put_chosen_prop(const char * name,const void * valbuf,size_t vallen,boolean_t bytes)900Sstevel@tonic-gate bi_put_chosen_prop(const char *name, const void *valbuf, size_t vallen,
910Sstevel@tonic-gate     boolean_t bytes)
920Sstevel@tonic-gate {
930Sstevel@tonic-gate 	/*
940Sstevel@tonic-gate 	 * Add this property to /chosen.
950Sstevel@tonic-gate 	 */
960Sstevel@tonic-gate 	prom_create_encoded_prop((char *)name, (void *)valbuf, vallen,
970Sstevel@tonic-gate 	    (bytes ? ENCODE_BYTES : ENCODE_STRING));
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	return (B_TRUE);
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * Function dealing with DHCP data.
1040Sstevel@tonic-gate  */
1050Sstevel@tonic-gate boolean_t
bi_get_dhcp_info(uchar_t optcat,uint16_t optcode,uint16_t optsize,void * valbuf,size_t * vallenp)1060Sstevel@tonic-gate bi_get_dhcp_info(uchar_t optcat, uint16_t optcode, uint16_t optsize,
1070Sstevel@tonic-gate     void *valbuf, size_t *vallenp)
1080Sstevel@tonic-gate {
1090Sstevel@tonic-gate 	return (dhcp_getinfo_pl(state_pl, optcat, optcode, optsize, valbuf,
1100Sstevel@tonic-gate 	    vallenp));
1110Sstevel@tonic-gate }
112