-
Notifications
You must be signed in to change notification settings - Fork 2
/
ocf_mylight_security.c
84 lines (64 loc) · 1.55 KB
/
ocf_mylight_security.c
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "ocf_mylight.h"
#include <pinoxmcommon.h>
static FILE* on_open(const char *path, const char *mode)
{
DBG("open: path=%s, mode=%s", path, mode);
return fopen(path, mode);
}
static size_t on_read(void *ptr, size_t size, size_t nmemb, FILE *fp)
{
DBG("read: size=%zd, nmemb=%zd, fp=0x%p", size, nmemb, fp);
return fread(ptr, size, nmemb, fp);
}
static size_t on_write(const void *ptr, size_t size, size_t nmemb, FILE *fp)
{
DBG("write: size=%zd, nmemb=%zd, fp=0x%p", size, nmemb, fp);
return fwrite(ptr, size, nmemb, fp);
}
static int on_close(FILE *fp)
{
DBG("close: fp=0x%p", fp);
return fclose(fp);
}
static int on_unlink(const char *path)
{
DBG("unlink: path=%s", path);
return unlink(path);
}
static void on_display_pin(char *pin, size_t length, void *user_data _UNUSED_)
{
MSG("PIN CODE: '%s' (pin length=%zd)", pin, length);
}
static void on_close_pin(void)
{
MSG("PIN CLOSED");
}
OCPersistentStorage ps = {
.open = on_open,
.read = on_read,
.write = on_write,
.close = on_close,
.unlink = on_unlink
};
int ocf_mylight_security_init()
{
OCStackResult ret;
OCRegisterPersistentStorageHandler(&ps);
ret = SetDisplayPinWithContextCB(on_display_pin, NULL);
if (ret != OC_STACK_OK) {
DBG("SetDisplayPinWithContextCB failed! (ret=%d)", ret);
return -1;
}
SetClosePinDisplayCB(on_close_pin);
ret = SetRandomPinPolicy(8, NUM_PIN);
if (ret != OC_STACK_OK) {
DBG("SetRandomPinPolicy failed! (ret=%d)", ret);
return -1;
}
return 0;
}