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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
 
#include <stddef.h>
#include <errno.h>
#include <string.h>
#include "testutil/testutil.h"
#include "nimble/hci_common.h"
#include "host/ble_hs_adv.h"
#include "ble_hs_test.h"
#include "ble_hs_test_util.h"
 
static int
ble_hs_id_test_util_infer_auto(int privacy, uint8_t *own_addr_type)
{
    int rc;
 
    rc = ble_hs_id_infer_auto(privacy, own_addr_type);
 
    return rc;
}
 
TEST_CASE_SELF(ble_hs_id_test_case_auto_none)
{
    uint8_t own_addr_type;
    int rc;
 
    ble_hs_test_util_init();
 
    /* Clear public address. */
    ble_hs_id_set_pub((uint8_t[6]){ 0, 0, 0, 0, 0, 0 });
 
    rc = ble_hs_id_test_util_infer_auto(0, &own_addr_type);
    TEST_ASSERT_FATAL(rc == BLE_HS_ENOADDR);
 
    ble_hs_test_util_assert_mbufs_freed(NULL);
}
 
TEST_CASE_SELF(ble_hs_id_test_case_auto_public)
{
    uint8_t own_addr_type;
    int rc;
 
    ble_hs_test_util_init();
 
    rc = ble_hs_id_test_util_infer_auto(0, &own_addr_type);
    TEST_ASSERT_FATAL(rc == 0);
    TEST_ASSERT(own_addr_type == BLE_OWN_ADDR_PUBLIC);
 
    ble_hs_test_util_assert_mbufs_freed(NULL);
}
 
TEST_CASE_SELF(ble_hs_id_test_case_auto_random)
{
    uint8_t own_addr_type;
    int rc;
 
    ble_hs_test_util_init();
 
    /* Configure a random address. */
    ble_hs_test_util_set_static_rnd_addr((uint8_t[6]){ 1, 2, 3, 4, 5, 0xc0 });
 
    rc = ble_hs_id_test_util_infer_auto(0, &own_addr_type);
    TEST_ASSERT_FATAL(rc == 0);
    TEST_ASSERT(own_addr_type == BLE_OWN_ADDR_RANDOM);
 
    ble_hs_test_util_assert_mbufs_freed(NULL);
}
 
TEST_CASE_SELF(ble_hs_id_test_case_auto_rpa_pub)
{
    uint8_t own_addr_type;
    int rc;
 
    ble_hs_test_util_init();
 
    rc = ble_hs_id_test_util_infer_auto(1, &own_addr_type);
    TEST_ASSERT_FATAL(rc == 0);
    TEST_ASSERT(own_addr_type == BLE_OWN_ADDR_RPA_PUBLIC_DEFAULT);
 
    ble_hs_test_util_assert_mbufs_freed(NULL);
}
 
TEST_CASE_SELF(ble_hs_id_test_case_auto_rpa_rnd)
{
    uint8_t own_addr_type;
    int rc;
 
    ble_hs_test_util_init();
 
    /* Configure a random address. */
    ble_hs_test_util_set_static_rnd_addr((uint8_t[6]){ 1, 2, 3, 4, 5, 0xc0 });
 
    rc = ble_hs_id_test_util_infer_auto(1, &own_addr_type);
    TEST_ASSERT_FATAL(rc == 0);
    TEST_ASSERT(own_addr_type == BLE_OWN_ADDR_RPA_RANDOM_DEFAULT);
 
    ble_hs_test_util_assert_mbufs_freed(NULL);
}
 
TEST_SUITE(ble_hs_id_test_suite_auto)
{
    ble_hs_id_test_case_auto_none();
    ble_hs_id_test_case_auto_public();
    ble_hs_id_test_case_auto_random();
    ble_hs_id_test_case_auto_rpa_pub();
    ble_hs_id_test_case_auto_rpa_rnd();
}