1203181Smarcel/*- 2203181Smarcel * Copyright (c) 2010 Marcel Moolenaar 3203181Smarcel * All rights reserved. 4203181Smarcel * 5203181Smarcel * Redistribution and use in source and binary forms, with or without 6203181Smarcel * modification, are permitted provided that the following conditions 7203181Smarcel * are met: 8203181Smarcel * 1. Redistributions of source code must retain the above copyright 9203181Smarcel * notice, this list of conditions and the following disclaimer. 10203181Smarcel * 2. Redistributions in binary form must reproduce the above copyright 11203181Smarcel * notice, this list of conditions and the following disclaimer in the 12203181Smarcel * documentation and/or other materials provided with the distribution. 13203181Smarcel * 14203181Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15203181Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16203181Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17203181Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18203181Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19203181Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20203181Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21203181Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22203181Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23203181Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24203181Smarcel * SUCH DAMAGE. 25203181Smarcel */ 26203181Smarcel 27203181Smarcel#include <sys/cdefs.h> 28203181Smarcel__FBSDID("$FreeBSD$"); 29203181Smarcel 30203181Smarcel#include <libefi.h> 31203181Smarcel#include <stdlib.h> 32203181Smarcel 33203181Smarcel#include "libefi_int.h" 34203181Smarcel 35203181Smarcel/* 36203181Smarcel * EFI_STATUS 37203181Smarcel * SetVariable( 38203181Smarcel * IN CHAR16 *VariableName, 39203181Smarcel * IN EFI_GUID *VendorGuid, 40203181Smarcel * IN UINT32 Attributes, 41203181Smarcel * IN UINTN DataSize, 42203181Smarcel * IN VOID *Data 43203181Smarcel * ); 44203181Smarcel */ 45203181Smarcel 46203181Smarcelint 47203181Smarcelefi_setvar(char *name, uuid_t *vendor, uint32_t attrib, size_t datasize, 48203181Smarcel void *data) 49203181Smarcel{ 50203181Smarcel struct iodev_efivar_req req; 51203181Smarcel int error; 52203181Smarcel 53203181Smarcel req.namesize = 0; 54203181Smarcel error = libefi_utf8_to_ucs2(name, &req.namesize, &req.name); 55203181Smarcel if (error) 56203181Smarcel return (error); 57203181Smarcel 58203181Smarcel req.vendor = *vendor; 59203181Smarcel req.attrib = attrib; 60203181Smarcel req.datasize = datasize; 61203181Smarcel req.data = data; 62203181Smarcel req.access = IODEV_EFIVAR_SETVAR; 63203181Smarcel error = libefi_efivar(&req); 64203181Smarcel free(req.name); 65203181Smarcel return (error); 66203181Smarcel} 67