1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ESE_APP_WEAVER_H_
#define ESE_APP_WEAVER_H_ 1
#include <ese/ese.h>
#include <ese/log.h>
#include <ese/sysdeps.h>
#include <ese/app/result.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* EseWeaverSession carries the necessary start for interfacing
* with the methods below.
*
* Its usage follows a lifecycle like:
*
* EseAppResult res;
* EseWeaverSession session;
* ese_weaver_session_init(&session);
* res = ese_weaver_session_open(ese, &session);
* if (res != ESE_APP_RESULT_OK) {
* ... handle error (especially cooldown) ...
* }
* ... ese_weaver_* ...
* ese_weaver_session_close(&session);
*
*/
struct EseWeaverSession {
struct EseInterface *ese;
bool active;
uint8_t channel_id;
};
/** The keys are 16 bytes */
const uint8_t kEseWeaverKeySize = 16;
/** The values are 16 bytes */
const uint8_t kEseWeaverValueSize = 16;
const int ESE_WEAVER_READ_WRONG_KEY = ese_make_app_result(0x6a, 0x85);
const int ESE_WEAVER_READ_TIMEOUT = ese_make_app_result(0x6a, 0x87);
/**
* Initializes a pre-allocated |session| for use.
*/
void ese_weaver_session_init(struct EseWeaverSession *session);
/**
* Configures a communication session with the Storage applet using a logical
* channel on an already open |ese| object.
*
* @returns ESE_APP_RESULT_OK on success.
*/
EseAppResult ese_weaver_session_open(struct EseInterface *ese, struct EseWeaverSession *session);
/**
* Shuts down the logical channel with the Storage applet and invalidates
* the |session| internal state.
*
* @returns ESE_APP_RESULT_OK on success.
*/
EseAppResult ese_weaver_session_close(struct EseWeaverSession *session);
/**
* Retreives the number of slots available.
* @returns ESE_APP_RESULT_OK if |numSlots| contains a valid value.
*/
EseAppResult ese_weaver_get_num_slots(struct EseWeaverSession *session, uint32_t *numSlots);
/**
* Writes a new key-value pair into the slot.
*
* |key| and |value| must be buffers of sizes |kEseWeaverKeySize| and
* |kEseWeaverValueSize| respectively.
*
* @returns ESE_APP_RESULT_OK on success.
*/
EseAppResult ese_weaver_write(struct EseWeaverSession *session, uint32_t slotId,
const uint8_t *key, const uint8_t *value);
/**
* Reads the value in the slot provided the correct key was passed.
*
* |key| and |value| must be buffers of sizes |kEseWeaverKeySize| and
* |kEseWeaverValueSize| respectively.
*
* @returns ESE_APP_RESULT_OK if |value| was filled with the value.
* ESE_WEAVER_READ_WRONG_KEY if |key| was wrong and |timeout| contains
* a valid timeout.
* ESE_WEAVER_READ_TIMEOUT if Weaver is in backoff mode and |timeout|
* contains a valid timeout.
*/
EseAppResult ese_weaver_read(struct EseWeaverSession *session, uint32_t slotId,
const uint8_t *key, uint8_t *value, uint32_t *timeout);
/**
* Erase the value of a slot whilst maintaining the same key.
*
* @returns ESE_APP_RESULT_OK on success.
*/
EseAppResult ese_weaver_erase_value(struct EseWeaverSession *session, uint32_t slotId);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* ESE_APP_WEAVER_H_ */
|