Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
François Revol
firmware
Commits
8aa8c31f
Commit
8aa8c31f
authored
Aug 21, 2019
by
schneider
Browse files
feat(ble): Store bondings
parent
5e5c7a4f
Changes
1
Hide whitespace changes
Inline
Side-by-side
epicardium/ble/app/common/app_db.c
View file @
8aa8c31f
...
...
@@ -24,7 +24,6 @@
*/
/* clang-format off */
/* clang-formet turned off for easier diffing against orginal file */
#include
<string.h>
#include
"wsf_types.h"
#include
"wsf_assert.h"
#include
"util/bda.h"
...
...
@@ -33,6 +32,10 @@
#include
"app_db.h"
#include
"app_cfg.h"
#include
"epicardium.h"
#include
<string.h>
#include
<stdio.h>
/**************************************************************************************************
Data Types
**************************************************************************************************/
...
...
@@ -96,7 +99,24 @@ static appDbRec_t *pAppDbNewRec = appDb.rec;
/*************************************************************************************************/
void
AppDbInit
(
void
)
{
return
;
int
fd
=
epic_file_open
(
"pairings.bin"
,
"r"
);
if
(
fd
>=
0
)
{
if
(
epic_file_read
(
fd
,
&
appDb
,
sizeof
(
appDb
))
!=
sizeof
(
appDb
))
{
memset
(
&
appDb
,
0
,
sizeof
(
appDb
));
}
epic_file_close
(
fd
);
}
}
static
void
store
(
void
)
{
int
fd
=
epic_file_open
(
"pairings.bin"
,
"w"
);
if
(
fd
>=
0
)
{
if
(
epic_file_write
(
fd
,
&
appDb
,
sizeof
(
appDb
))
!=
sizeof
(
appDb
))
{
}
epic_file_close
(
fd
);
}
}
/*************************************************************************************************/
...
...
@@ -145,6 +165,7 @@ appDbHdl_t AppDbNewRecord(uint8_t addrType, uint8_t *pAddr)
pRec
->
peerAddedToRl
=
FALSE
;
pRec
->
peerRpao
=
FALSE
;
store
();
return
(
appDbHdl_t
)
pRec
;
}
...
...
@@ -209,6 +230,7 @@ appDbHdl_t AppDbGetNextRecord(appDbHdl_t hdl)
void
AppDbDeleteRecord
(
appDbHdl_t
hdl
)
{
((
appDbRec_t
*
)
hdl
)
->
inUse
=
FALSE
;
store
();
}
/*************************************************************************************************/
...
...
@@ -226,6 +248,7 @@ void AppDbValidateRecord(appDbHdl_t hdl, uint8_t keyMask)
{
((
appDbRec_t
*
)
hdl
)
->
valid
=
TRUE
;
((
appDbRec_t
*
)
hdl
)
->
keyValidMask
=
keyMask
;
store
();
}
/*************************************************************************************************/
...
...
@@ -315,6 +338,7 @@ void AppDbDeleteAllRecords(void)
{
pRec
->
inUse
=
FALSE
;
}
store
();
}
/*************************************************************************************************/
...
...
@@ -461,6 +485,7 @@ void AppDbSetKey(appDbHdl_t hdl, dmSecKeyIndEvt_t *pKey)
default:
break
;
}
store
();
}
/*************************************************************************************************/
...
...
@@ -493,6 +518,7 @@ void AppDbSetCccTblValue(appDbHdl_t hdl, uint16_t idx, uint16_t value)
WSF_ASSERT
(
idx
<
APP_DB_NUM_CCCD
);
((
appDbRec_t
*
)
hdl
)
->
cccTbl
[
idx
]
=
value
;
store
();
}
/*************************************************************************************************/
...
...
@@ -522,6 +548,7 @@ uint8_t AppDbGetDiscStatus(appDbHdl_t hdl)
void
AppDbSetDiscStatus
(
appDbHdl_t
hdl
,
uint8_t
status
)
{
((
appDbRec_t
*
)
hdl
)
->
discStatus
=
status
;
store
();
}
/*************************************************************************************************/
...
...
@@ -551,6 +578,7 @@ uint16_t *AppDbGetHdlList(appDbHdl_t hdl)
void
AppDbSetHdlList
(
appDbHdl_t
hdl
,
uint16_t
*
pHdlList
)
{
memcpy
(((
appDbRec_t
*
)
hdl
)
->
hdlList
,
pHdlList
,
sizeof
(((
appDbRec_t
*
)
hdl
)
->
hdlList
));
store
();
}
/*************************************************************************************************/
...
...
@@ -593,6 +621,7 @@ void AppDbSetDevName(uint8_t len, char *pStr)
len
=
(
len
<=
sizeof
(
appDb
.
devName
))
?
len
:
sizeof
(
appDb
.
devName
);
memcpy
(
appDb
.
devName
,
pStr
,
len
);
store
();
}
/*************************************************************************************************/
...
...
@@ -622,6 +651,7 @@ bool_t AppDbGetPeerAddrRes(appDbHdl_t hdl)
void
AppDbSetPeerAddrRes
(
appDbHdl_t
hdl
,
uint8_t
addrRes
)
{
((
appDbRec_t
*
)
hdl
)
->
peerAddrRes
=
addrRes
;
store
();
}
/*************************************************************************************************/
...
...
@@ -651,6 +681,7 @@ uint32_t AppDbGetPeerSignCounter(appDbHdl_t hdl)
void
AppDbSetPeerSignCounter
(
appDbHdl_t
hdl
,
uint32_t
signCounter
)
{
((
appDbRec_t
*
)
hdl
)
->
peerSignCounter
=
signCounter
;
store
();
}
/*************************************************************************************************/
...
...
@@ -680,6 +711,7 @@ bool_t AppDbGetPeerAddedToRl(appDbHdl_t hdl)
void
AppDbSetPeerAddedToRl
(
appDbHdl_t
hdl
,
bool_t
peerAddedToRl
)
{
((
appDbRec_t
*
)
hdl
)
->
peerAddedToRl
=
peerAddedToRl
;
store
();
}
/*************************************************************************************************/
...
...
@@ -709,5 +741,6 @@ bool_t AppDbGetPeerRpao(appDbHdl_t hdl)
void
AppDbSetPeerRpao
(
appDbHdl_t
hdl
,
bool_t
peerRpao
)
{
((
appDbRec_t
*
)
hdl
)
->
peerRpao
=
peerRpao
;
store
();
}
/* clang-format on */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment