| 1 |
// Copyright (c) Microsoft. All rights reserved. |
| 2 |
// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 |
|
| 4 |
// MBED seems to not implement size_t properly within their cstddef.h header, and builds will fail if stddef.h is not included by the projects. |
| 5 |
#include <stddef.h> |
| 6 |
#include "azure_c_shared_utility/platform.h" |
| 7 |
#include "EthernetInterface.h" |
| 8 |
#include "NTPClient.h" |
| 9 |
#include "azure_c_shared_utility/optimize_size.h" |
| 10 |
#include "azure_c_shared_utility/xio.h" |
| 11 |
#include "azure_c_shared_utility/tlsio_wolfssl.h" |
| 12 |
|
| 13 |
int setupRealTime(void) |
| 14 |
{ |
| 15 |
int result; |
| 16 |
|
| 17 |
if (EthernetInterface::connect()) |
| 18 |
{ |
| 19 |
result = MU_FAILURE; |
| 20 |
} |
| 21 |
else |
| 22 |
{ |
| 23 |
NTPClient ntp; |
| 24 |
if (ntp.setTime("0.pool.ntp.org") != 0) |
| 25 |
{ |
| 26 |
result = MU_FAILURE; |
| 27 |
} |
| 28 |
else |
| 29 |
{ |
| 30 |
result = 0; |
| 31 |
} |
| 32 |
EthernetInterface::disconnect(); |
| 33 |
} |
| 34 |
|
| 35 |
return result; |
| 36 |
} |
| 37 |
|
| 38 |
int platform_init(void) |
| 39 |
{ |
| 40 |
int result; |
| 41 |
|
| 42 |
if (EthernetInterface::init()) |
| 43 |
{ |
| 44 |
result = MU_FAILURE; |
| 45 |
} |
| 46 |
else if (setupRealTime() != 0) |
| 47 |
{ |
| 48 |
result = MU_FAILURE; |
| 49 |
} |
| 50 |
else if (EthernetInterface::connect()) |
| 51 |
{ |
| 52 |
result = MU_FAILURE; |
| 53 |
} |
| 54 |
else |
| 55 |
{ |
| 56 |
result = 0; |
| 57 |
} |
| 58 |
|
| 59 |
return result; |
| 60 |
} |
| 61 |
|
| 62 |
const IO_INTERFACE_DESCRIPTION* platform_get_default_tlsio(void) |
| 63 |
{ |
| 64 |
return tlsio_wolfssl_get_interface_description(); |
| 65 |
} |
| 66 |
|
| 67 |
STRING_HANDLE platform_get_platform_info(PLATFORM_INFO_OPTION options) |
| 68 |
{ |
| 69 |
// No applicable options, so ignoring parameter |
| 70 |
(void)options; |
| 71 |
|
| 72 |
// Expected format: "(<runtime name>; <operating system name>; <platform>)" |
| 73 |
|
| 74 |
return STRING_construct("(native; mbed; undefined)"); |
| 75 |
} |
| 76 |
|
| 77 |
void platform_deinit(void) |
| 78 |
{ |
| 79 |
EthernetInterface::disconnect(); |
| 80 |
} |