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
0ed4a54d
Commit
0ed4a54d
authored
Aug 20, 2019
by
Martin Ling
Committed by
Martin Ling
Aug 20, 2019
Browse files
Randomly generate MAC address if not set.
parent
fdd88b2c
Changes
1
Hide whitespace changes
Inline
Side-by-side
epicardium/ble/ble.c
View file @
0ed4a54d
...
...
@@ -7,6 +7,7 @@
#include
"ble_api.h"
#include
"hci_vs.h"
#include
"att_api.h"
#include
"trng.h"
#include
"FreeRTOS.h"
#include
"timers.h"
...
...
@@ -92,8 +93,20 @@ static void setAddress(void)
uint8_t
bdAddr
[
6
]
=
{
0x02
,
0x02
,
0x44
,
0x8B
,
0x05
,
0x00
};
char
buf
[
32
];
fs_read_text_file
(
"mac.txt"
,
buf
,
sizeof
(
buf
));
APP_TRACE_INFO1
(
"mac file contents: %s"
,
buf
);
int
result
=
fs_read_text_file
(
"mac.txt"
,
buf
,
sizeof
(
buf
));
if
(
result
==
-
1
)
{
APP_TRACE_INFO0
(
"mac.txt not found, generating random MAC"
);
TRNG_Init
(
NULL
);
TRNG_Read
(
MXC_TRNG
,
bdAddr
,
sizeof
(
bdAddr
));
sprintf
(
buf
,
"%02x:%02x:%02x:%02x:%02x:%02x
\n
"
,
bdAddr
[
0
],
bdAddr
[
1
],
bdAddr
[
2
],
bdAddr
[
3
],
bdAddr
[
4
],
bdAddr
[
5
]);
fs_write_file
(
"mac.txt"
,
buf
,
strlen
(
buf
));
}
else
{
APP_TRACE_INFO1
(
"mac file contents: %s"
,
buf
);
}
int
a
,
b
,
c
,
d
,
e
,
f
;
if
(
sscanf
(
buf
,
"%x:%x:%x:%x:%x:%x"
,
&
a
,
&
b
,
&
c
,
&
d
,
&
e
,
&
f
)
==
6
)
{
bdAddr
[
0
]
=
f
;
...
...
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