Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
card10
firmware
Commits
3a8c85fc
Commit
3a8c85fc
authored
4 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
feat(ble): Always overwrite the oldest pairing
parent
368343cd
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!405
feat(ble): Always overwrite the oldest pairing
Pipeline
#4737
passed
4 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
epicardium/ble/bondings.c
+31
-12
31 additions, 12 deletions
epicardium/ble/bondings.c
with
31 additions
and
12 deletions
epicardium/ble/bondings.c
+
31
−
12
View file @
3a8c85fc
...
...
@@ -70,6 +70,8 @@
#define APP_DB_NVM_HDL_LIST_ID 19
#define APP_DB_NVM_DISC_STATUS_ID 20
#define APP_DB_NVM_SEQUENCE_NUMBER_ID 100
/**************************************************************************************************
Data Types
**************************************************************************************************/
...
...
@@ -104,6 +106,8 @@ typedef struct
/*! for ATT client */
uint16_t
hdlList
[
APP_DB_HDL_LIST_LEN
];
/*! Cached handle list */
uint8_t
discStatus
;
/*! Service discovery and configuration status */
uint32_t
sequenceNumber
;
}
appDbRec_t
;
...
...
@@ -114,9 +118,6 @@ typedef struct
/*! Database */
static
appDbRec_t
records
[
APP_DB_NUM_RECS
];
/*! When all records are allocated use this index to determine which to overwrite */
static
appDbRec_t
*
pAppDbNewRec
=
records
;
/* clang-format on */
/* Translate a pointer to a record into the filename to be used for it. */
static
int
record_to_filename
(
appDbRec_t
*
record
,
char
*
buf
,
size_t
buf_size
)
...
...
@@ -129,6 +130,28 @@ static int record_to_filename(appDbRec_t *record, char *buf, size_t buf_size)
return
ret
;
}
static
appDbRec_t
*
record_with_highest_seq_number
()
{
appDbRec_t
*
r
=
&
records
[
0
];
for
(
int
i
=
0
;
i
<
APP_DB_NUM_RECS
;
i
++
)
{
if
(
records
[
i
].
sequenceNumber
>
r
->
sequenceNumber
)
{
r
=
&
records
[
i
];
}
}
return
r
;
}
static
appDbRec_t
*
record_with_lowest_seq_number
()
{
appDbRec_t
*
r
=
&
records
[
0
];
for
(
int
i
=
0
;
i
<
APP_DB_NUM_RECS
;
i
++
)
{
if
(
records
[
i
].
sequenceNumber
<
r
->
sequenceNumber
)
{
r
=
&
records
[
i
];
}
}
return
r
;
}
/* Write a TLV to a file. */
static
int
write_tlv
(
int
fd
,
uint32_t
t
,
uint32_t
l
,
void
*
v
)
{
...
...
@@ -218,6 +241,7 @@ static int write_bond_to_file(appDbRec_t *r, char *filename)
write_element
(
APP_DB_NVM_PEER_SIGN_CTR_ID
,
peerSignCounter
);
write_element
(
APP_DB_NVM_HDL_LIST_ID
,
hdlList
);
write_element
(
APP_DB_NVM_DISC_STATUS_ID
,
discStatus
);
write_element
(
APP_DB_NVM_SEQUENCE_NUMBER_ID
,
sequenceNumber
);
write_element
(
APP_DB_NVM_VALID_ID
,
valid
);
#undef write_element
...
...
@@ -265,6 +289,7 @@ static int read_bond_from_file(appDbRec_t *r, char *filename)
read_element
(
APP_DB_NVM_PEER_SIGN_CTR_ID
,
peerSignCounter
);
read_element
(
APP_DB_NVM_HDL_LIST_ID
,
hdlList
);
read_element
(
APP_DB_NVM_DISC_STATUS_ID
,
discStatus
);
read_element
(
APP_DB_NVM_SEQUENCE_NUMBER_ID
,
sequenceNumber
);
read_element
(
APP_DB_NVM_VALID_ID
,
valid
);
#undef read_element
...
...
@@ -337,15 +362,8 @@ appDbHdl_t AppDbNewRecord(uint8_t addrType, uint8_t *pAddr)
/* if all records were allocated */
if
(
i
==
0
)
{
/* overwrite a record */
pRec
=
pAppDbNewRec
;
/* get next record to overwrite */
pAppDbNewRec
++
;
if
(
pAppDbNewRec
==
&
records
[
APP_DB_NUM_RECS
])
{
pAppDbNewRec
=
records
;
}
/* overwrite the oldest record */
pRec
=
record_with_lowest_seq_number
();
}
/* initialize record */
...
...
@@ -355,6 +373,7 @@ appDbHdl_t AppDbNewRecord(uint8_t addrType, uint8_t *pAddr)
BdaCpy
(
pRec
->
peerAddr
,
pAddr
);
pRec
->
peerAddedToRl
=
FALSE
;
pRec
->
peerRpao
=
FALSE
;
pRec
->
sequenceNumber
=
record_with_highest_seq_number
()
->
sequenceNumber
+
1
;
return
(
appDbHdl_t
)
pRec
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment