1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License, Version 1.0 only
   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <sys/types.h>
  30 #include <dhcp_impl.h>
  31 #include <sys/promif.h>
  32 #include <strings.h>
  33 #include <sys/salib.h>
  34 #include <dhcpv4.h>
  35 #include <bootinfo.h>
  36 #include <bootinfo_aux.h>
  37 
  38 /*
  39  * Functions dealing with bootinfo initialization/cleanup.
  40  * Both no-ops in the standalone.
  41  */
  42 boolean_t
  43 bi_init_bootinfo(void)
  44 {
  45         return (B_TRUE);
  46 }
  47 
  48 void
  49 bi_end_bootinfo(void)
  50 {
  51 }
  52 
  53 /*
  54  * Functions dealing with /chosen data.
  55  */
  56 boolean_t
  57 bi_get_chosen_prop(const char *name, void *valbuf, size_t *vallenp)
  58 {
  59         static pnode_t  chosen;
  60         int             len;
  61 
  62         /*
  63          * The standalone helpfully provides a function for getting a
  64          * handle on /chosen; it prom_panic()'s if /chosen doesn't exist.
  65          */
  66         if (chosen == OBP_NONODE) {
  67                 chosen = prom_chosennode();
  68         }
  69 
  70         /*
  71          * Check for the existence/size of a property with name 'name';
  72          * if found, and the receiving buffer is big enough, copy its value.
  73          * If not, return the length of the buffer that would be needed
  74          * to fullfill the request.
  75          */
  76         if ((len = prom_getproplen(chosen, (char *)name)) == -1) {
  77                 return (B_FALSE);
  78         }
  79         if (len <= *vallenp) {
  80                 if (prom_getprop(chosen, (char *)name, (caddr_t)valbuf) == -1) {
  81                         return (B_FALSE);
  82                 }
  83         }
  84         *vallenp = len;
  85 
  86         return (B_TRUE);
  87 }
  88 
  89 boolean_t
  90 bi_put_chosen_prop(const char *name, const void *valbuf, size_t vallen,
  91     boolean_t bytes)
  92 {
  93         /*
  94          * Add this property to /chosen.
  95          */
  96         prom_create_encoded_prop((char *)name, (void *)valbuf, vallen,
  97             (bytes ? ENCODE_BYTES : ENCODE_STRING));
  98 
  99         return (B_TRUE);
 100 }
 101 
 102 /*
 103  * Function dealing with DHCP data.
 104  */
 105 boolean_t
 106 bi_get_dhcp_info(uchar_t optcat, uint16_t optcode, uint16_t optsize,
 107     void *valbuf, size_t *vallenp)
 108 {
 109         return (dhcp_getinfo_pl(state_pl, optcat, optcode, optsize, valbuf,
 110             vallenp));
 111 }