#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/promimpl.h>
#ifdef PROM_32BIT_ADDRS
#include <sys/sunddi.h>
#endif
int
prom_set_security_key(char *keyname, caddr_t buf, int buflen, int *reslen,
int *status)
{
int rv;
cell_t ci[7];
int result;
#ifdef PROM_32BIT_ADDRS
char *okeyname = NULL;
char *obuf = NULL;
size_t keynamelen;
if ((uintptr_t)keyname > (uint32_t)-1) {
okeyname = keyname;
keynamelen = prom_strlen(okeyname) + 1;
keyname = promplat_alloc(keynamelen);
if (keyname == NULL)
return (-1);
(void) prom_strcpy(keyname, okeyname);
}
if (buflen > 0 && ((uintptr_t)buf > (uint32_t)-1)) {
obuf = buf;
buf = promplat_alloc(buflen);
if ((buf == NULL) && (okeyname != NULL)) {
promplat_free(keyname, keynamelen);
return (-1);
}
promplat_bcopy(obuf, buf, buflen);
}
#endif
ci[0] = p1275_ptr2cell("SUNW,set-security-key");
ci[1] = 3;
ci[2] = 1;
ci[3] = p1275_ptr2cell(keyname);
ci[4] = p1275_ptr2cell(buf);
ci[5] = p1275_uint2cell(buflen);
promif_preprom();
rv = p1275_cif_handler(ci);
promif_postprom();
#ifdef PROM_32BIT_ADDRS
if (okeyname != NULL)
promplat_free(keyname, keynamelen);
if (obuf != NULL)
promplat_free(buf, buflen);
#endif
if (rv != 0)
return (-1);
result = p1275_cell2int(ci[6]);
if (result >= 0) {
*reslen = result;
*status = 0;
} else {
*reslen = 0;
*status = result;
}
return (0);
}
int
prom_get_security_key(char *keyname, caddr_t buf, int buflen, int *keylen,
int *status)
{
int rv;
cell_t ci[7];
int result;
#ifdef PROM_32BIT_ADDRS
char *okeyname = NULL;
char *obuf = NULL;
size_t keynamelen;
if ((uintptr_t)keyname > (uint32_t)-1) {
okeyname = keyname;
keynamelen = prom_strlen(okeyname) + 1;
keyname = promplat_alloc(keynamelen);
if (keyname == NULL)
return (-1);
(void) prom_strcpy(keyname, okeyname);
}
if ((uintptr_t)buf > (uint32_t)-1) {
obuf = buf;
buf = promplat_alloc(buflen);
if ((buf == NULL) && (okeyname != NULL)) {
promplat_free(keyname, keynamelen);
return (-1);
}
}
#endif
ci[0] = p1275_ptr2cell("SUNW,get-security-key");
ci[1] = 3;
ci[2] = 1;
ci[3] = p1275_ptr2cell(keyname);
ci[4] = p1275_ptr2cell(buf);
ci[5] = p1275_uint2cell(buflen);
promif_preprom();
rv = p1275_cif_handler(ci);
promif_postprom();
#ifdef PROM_32BIT_ADDRS
if (okeyname != NULL)
promplat_free(keyname, keynamelen);
if (obuf != NULL) {
promplat_bcopy(buf, obuf, buflen);
promplat_free(buf, buflen);
}
#endif
if (rv != 0)
return (-1);
result = p1275_cell2int(ci[6]);
if (result > 0) {
*keylen = result;
*status = 0;
} else {
*keylen = 0;
*status = result;
}
return (0);
}