3 * @author David Llewellyn-Jones
11 * @section DESCRIPTION
24 #include <openssl/crypto.h>
25 #include <openssl/hmac.h>
26 #include <openssl/err.h>
28 #include "contrac/contrac.h"
29 #include "contrac/utils.h"
30 #include "contrac/log.h"
31 #include "contrac/rpi_list.h"
32 #include "contrac/dtk_list.h"
34 #include "contrac/match.h"
40 struct _MatchListItem
{
42 uint8_t time_interval_number
;
49 MatchListItem
* first
;
53 // Function prototypes
55 MatchListItem
* match_list_item_new();
56 void match_list_item_delete(MatchListItem
* data
);
57 void match_list_append(MatchList
* data
, MatchListItem
* item
);
59 // Function definitions
61 MatchList
* match_list_new() {
64 data
= calloc(sizeof(MatchList
), 1);
69 void match_list_delete(MatchList
* data
) {
71 match_list_clear(data
);
77 MatchListItem
* match_list_item_new() {
80 data
= calloc(sizeof(MatchListItem
), 1);
85 void match_list_item_delete(MatchListItem
* data
) {
91 void match_list_clear(MatchList
* data
) {
98 match_list_item_delete(item
);
107 size_t match_list_count(MatchList
* data
) {
111 MatchListItem
const * match_list_first(MatchList
const * data
) {
115 MatchListItem
const * match_list_next(MatchListItem
const * data
) {
120 uint32_t match_list_get_day_number(MatchListItem
const * data
) {
121 return data
->day_number
;
124 uint8_t match_list_get_time_interval_number(MatchListItem
const * data
) {
125 return data
->time_interval_number
;
128 void match_list_append(MatchList
* data
, MatchListItem
* item
) {
129 if (data
->last
== NULL
) {
134 data
->last
->next
= item
;
140 void match_list_find_matches(MatchList
* data
, RpiList
* beacons
, DtkList
* diagnosis_keys
) {
141 // For each diagnosis key, generate the RPIs and compare them against the captured RPI beacons
142 DtkListItem
const * dtk_item
;
143 RpiListItem
const * rpi_item
;
147 MatchListItem
* match
;
148 Dtk
const * diagnosis_key
;
151 dtk_item
= dtk_list_first(diagnosis_keys
);
152 generated
= rpi_new();
154 while (dtk_item
!= NULL
) {
155 diagnosis_key
= dtk_list_get_dtk(dtk_item
);
156 // Generate all possible RPIs for this dtk and compare agsinst the beacons
157 for (interval
= 0; interval
< RPI_INTERVAL_MAX
; ++interval
) {
158 result
= rpi_generate_proximity_id(generated
, diagnosis_key
, interval
);
160 // Check against all beacons
161 rpi_item
= rpi_list_first(beacons
);
162 while (rpi_item
!= NULL
) {
163 rpi
= rpi_list_get_rpi(rpi_item
);
164 result
= rpi_compare(rpi
, generated
);
167 if (interval
!= rpi_get_time_interval_number(rpi
)) {
169 LOG(LOG_DEBUG
, "Matched beacons don't match intervals\n");
174 match
= match_list_item_new();
175 match
->day_number
= dtk_get_day_number(diagnosis_key
);
176 match
->time_interval_number
= interval
;
177 match_list_append(data
, match
);
180 rpi_item
= rpi_list_next(rpi_item
);
185 dtk_item
= dtk_list_next(dtk_item
);
188 rpi_delete(generated
);