-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.c
94 lines (81 loc) · 3.24 KB
/
core.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
85
86
87
88
89
90
91
92
93
94
/* Copyright (c) 2015 Antumbra
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "libantumbra.h"
#include <string.h>
AnError AnCore_Echo_S(AnCtx *ctx, AnDevice *dev,
const void *outdata, unsigned int outdata_sz,
void *indata, unsigned int indata_sz)
{
return AnCmd_Invoke_S(ctx, dev, AnCore_API, AnCore_CMD_ECHO, outdata, outdata_sz, indata, indata_sz);
}
AnError AnCore_Ask_S(AnCtx *ctx, AnDevice *dev,
uint32_t api, bool *supp)
{
uint8_t apienc[4] = {api >> 24,
api >> 16 & 0xff,
api >> 8 & 0xff,
api & 0xff};
uint8_t supbyte;
AnError err = AnCmd_Invoke_S(ctx, dev,
AnCore_API, AnCore_CMD_ASK,
apienc, sizeof apienc,
&supbyte, 1);
if (!err)
*supp = supbyte != 0;
return err;
}
AnError AnCore_Diagnostic_S(AnCtx *ctx, AnDevice *dev,
void *diagdata, unsigned int diagdata_sz)
{
return AnCmd_Invoke_S(ctx, dev, AnCore_API, AnCore_CMD_DIAGNOSTIC, NULL, 0, diagdata, diagdata_sz);
}
#define MIN(a_, b_) ({typeof (a_) a = (a_); typeof (b_) b = (b_); (a < b) ? a : b;})
AnError AnCore_ImplementationId_S(AnCtx *ctx, AnDevice *dev,
char *idstr, unsigned int idstr_sz)
{
char idbuf[57];
AnError err = AnCmd_Invoke_S(ctx, dev, AnCore_API, AnCore_CMD_IMPLEMENTATIONID,
NULL, 0, idbuf, sizeof idbuf - 1);
idbuf[sizeof idbuf - 1] = 0;
if (!err) {
unsigned int ncopy = MIN(strlen(idbuf) + 1, idstr_sz);
memcpy(idstr, idbuf, ncopy);
if (ncopy > 0)
idstr[ncopy - 1] = 0;
}
return err;
}
AnError AnCore_DeviceId_S(AnCtx *ctx, AnDevice *dev,
void *idout, unsigned int idout_sz)
{
return AnCmd_Invoke_S(ctx, dev, AnCore_API, AnCore_CMD_DEVICEID, NULL, 0, idout, idout_sz);
}
AnError AnCore_HardwareId_S(AnCtx *ctx, AnDevice *dev,
char *idstr, unsigned int idstr_sz)
{
char idbuf[57];
AnError err = AnCmd_Invoke_S(ctx, dev, AnCore_API, AnCore_CMD_HARDWAREID,
NULL, 0, idbuf, sizeof idbuf - 1);
idbuf[sizeof idbuf - 1] = 0;
if (!err) {
unsigned int ncopy = MIN(strlen(idbuf) + 1, idstr_sz);
memcpy(idstr, idbuf, ncopy);
if (ncopy > 0)
idstr[ncopy - 1] = 0;
}
return err;
}
AnError AnCore_Reset_S(AnCtx *ctx, AnDevice *dev)
{
return AnCmd_Invoke_S(ctx, dev, AnCore_API, AnCore_CMD_RESET,
NULL, 0, NULL, 0);
}