Home | History | Annotate | Download | only in inc
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _EEDATA_H_
     18 #define _EEDATA_H_
     19 
     20 #include <stdbool.h>
     21 #include <stdint.h>
     22 
     23 /*
     24  * EEDATA allows storage of data in a persistent area that survives reboots and OS updates.
     25  * Each data piece has a name and stores 0..EE_DATA_LEN_MAX bytes of data. The name is a
     26  * non-zero number in the range 0..EE_DATA_NAME_MAX - 1. All names below EE_DATA_FIRST_USER
     27  * are reserved for OS purposes and are not accessible using the external-app-visible API.
     28  * To store an EEDATA item, use eeDataSet(). Setting the buffer to NULL will delete an
     29  * existing item and not replace it. Otherwise an item is replaced. Return value is success
     30  * (deleting a non-existent item always suceeds). You can use eeDataGet() to get items. It
     31  * will return true if an item exists. If called with buf set to NULL and szP not NULL,
     32  * *szP will be filled with its size. Else if buf and szP are both not NULL, up to *szP
     33  * bytes will be stored into buf, and *szP will be updated with the number of bytes written.
     34  * True is returned if the data item exists at all, else false is. For encryption keys, we
     35  * [ab]use eeDataGetAllVersions to get all keys (as each has the same name).
     36  */
     37 
     38 
     39 
     40 #define EE_DATA_NAME_MAX   0x000FFFFF
     41 #define EE_DATA_LEN_MAX    0x00000FFF //in bytes
     42 #define EE_DATA_FIRST_USER 0x00000100
     43 
     44 
     45 bool eeDataGet(uint32_t name, void *buf, uint32_t *szP);
     46 bool eeDataSet(uint32_t name, const void *buf, uint32_t len);
     47 
     48 uint32_t eeDataGetSize();
     49 uint32_t eeDataGetFree();
     50 
     51 //allow getting old "versions". Set state to NULL initially, call till you get NULL as return value
     52 void *eeDataGetAllVersions(uint32_t name, void *buf, uint32_t *szP, void **stateP);
     53 bool eeDataEraseOldVersion(uint32_t name, void *addr); // addr is non-NULL address returned by call to eeDataGetAllVersions
     54 
     55 //predefined key types
     56 
     57 #define EE_DATA_NAME_ENCR_KEY            1
     58 
     59 
     60 
     61 #endif
     62 
     63