mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2024-12-05 00:55:43 +01:00
Remove unneeded contacts code and cleanup gatt-service.h
This commit is contained in:
parent
b2d89d5d03
commit
1101dd950f
181
src/contacts.c
181
src/contacts.c
@ -23,14 +23,6 @@
|
||||
#include "contacts.h"
|
||||
#include "exposure-notification.h"
|
||||
#include "covid.h"
|
||||
#include "ens/storage.h"
|
||||
|
||||
static contact_t contacts[MAX_CONTACTS];
|
||||
static uint32_t contact_count = 0;
|
||||
|
||||
static period_contacts_t period_contacts[PERIODS];
|
||||
static int period_index;
|
||||
static int32_t next_infected_key_id = 0;
|
||||
|
||||
void print_key(_ENBaseKey* key){
|
||||
for( int i = 0; i < sizeof(key->b); i++){
|
||||
@ -49,176 +41,3 @@ void print_aem(associated_encrypted_metadata_t* aem){
|
||||
printk("%02x", aem->data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
contact_t* find_contact(rolling_proximity_identifier_t* rpi, associated_encrypted_metadata_t* aem){
|
||||
for( int i = 0; i < contact_count; i++ ){
|
||||
//print_rpi(&contacts[i].rolling_proximity_identifier);
|
||||
//print_aem(&contacts[i].associated_encrypted_metadata);
|
||||
if ( memcmp(&contacts[i].rolling_proximity_identifier, rpi, sizeof(rolling_proximity_identifier_t)) == 0 &&
|
||||
memcmp(&contacts[i].associated_encrypted_metadata, aem, sizeof(associated_encrypted_metadata_t)) == 0 ) {
|
||||
return &contacts[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int check_add_contact(uint32_t contact_time, rolling_proximity_identifier_t* rpi, associated_encrypted_metadata_t* aem, int8_t rssi){
|
||||
contact_t* contact = find_contact(rpi, aem);
|
||||
if( contact == NULL ){
|
||||
if( contact_count >= MAX_CONTACTS ){
|
||||
printk("out of contact buffers\n");
|
||||
return -1;
|
||||
}
|
||||
printk("adding contact: rpi ");
|
||||
print_rpi(rpi);
|
||||
printk(" aem ");
|
||||
print_aem(aem);
|
||||
printk(" rssi %i \n", rssi);
|
||||
|
||||
contacts[contact_count].most_recent_contact_time = contact_time;
|
||||
contacts[contact_count].first_contact_time = contact_time;
|
||||
contacts[contact_count].cnt = 1;
|
||||
contacts[contact_count].max_rssi = rssi;
|
||||
memcpy(&contacts[contact_count].rolling_proximity_identifier, rpi, sizeof(rolling_proximity_identifier_t));
|
||||
memcpy(&contacts[contact_count].associated_encrypted_metadata, aem, sizeof(associated_encrypted_metadata_t));
|
||||
contact_count++;
|
||||
} else {
|
||||
contact->most_recent_contact_time = contact_time;
|
||||
if( contacts->cnt < 0xFFFF ){ //avoid overflows
|
||||
contacts->cnt++;
|
||||
}
|
||||
if( rssi > contact->max_rssi ){
|
||||
contact->max_rssi = rssi;
|
||||
}
|
||||
// printk("update contact: rpi ");
|
||||
// print_rpi(rpi);
|
||||
// printk(" aem ");
|
||||
// print_aem(aem);
|
||||
// printk(" rssi %i, cnt %i \n", rssi, contacts->cnt);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//10 minutes are over and we got new keys. Time to also sort our short term contacts and move them to long-term log
|
||||
//TODO: move long-term storage to flash, as we have limited space in RAM
|
||||
void key_change(int current_period_index){
|
||||
if(current_period_index >= PERIODS){
|
||||
printk("error, current periods index %i too large", current_period_index);
|
||||
return;
|
||||
}
|
||||
if(current_period_index != period_index){
|
||||
//printk("new period index\n");
|
||||
period_index = current_period_index;
|
||||
period_contacts[period_index].cnt = 0;
|
||||
}
|
||||
|
||||
//check all short-term contacts (as long as we have space in our long-term storage)
|
||||
for( int i = 0; i < contact_count && period_contacts[period_index].cnt < MAX_PERIOD_CONTACTS; i++){
|
||||
//printk("check contact %i, duration %i\n", i, contacts[i].most_recent_contact_time - contacts[i].first_contact_time);
|
||||
int index = period_contacts[period_index].cnt;
|
||||
if( (contacts[i].most_recent_contact_time - contacts[i].first_contact_time) > (EN_INTERVAL_LENGTH / 2)){
|
||||
period_contacts[period_index].period_contacts[index].duration = contacts[i].most_recent_contact_time - contacts[i].first_contact_time;
|
||||
period_contacts[period_index].period_contacts[index].cnt = contacts[i].cnt;
|
||||
period_contacts[period_index].period_contacts[index].max_rssi = contacts[i].max_rssi;
|
||||
memcpy(&period_contacts[period_index].period_contacts[index].rolling_proximity_identifier, &contacts[i].rolling_proximity_identifier, sizeof(rolling_proximity_identifier_t));
|
||||
memcpy(&period_contacts[period_index].period_contacts[index].associated_encrypted_metadata, &contacts[i].associated_encrypted_metadata, sizeof(associated_encrypted_metadata_t));
|
||||
|
||||
printk("store contact %i as exposure %i: rpi ", i, period_contacts[period_index].cnt);
|
||||
print_rpi(&period_contacts[period_index].period_contacts[index].rolling_proximity_identifier);
|
||||
printk(" aem ");
|
||||
print_aem(&period_contacts[period_index].period_contacts[index].associated_encrypted_metadata);
|
||||
printk(" max rssi %i, cnt %u, duration %u\n", period_contacts[period_index].period_contacts[index].max_rssi, period_contacts[period_index].period_contacts[index].cnt, period_contacts[period_index].period_contacts[index].duration);
|
||||
period_contacts[period_index].cnt++;
|
||||
|
||||
printk("Attempting to store contact %i...\n", i);
|
||||
int rc = add_contact(&contacts[i]);
|
||||
if(rc) {
|
||||
printk("Failed to store contact %i! (err %d)\n", i, rc);
|
||||
} else {
|
||||
printk("Successfully stored contact %i!\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
contact_count = 0;
|
||||
}
|
||||
|
||||
/* The devicetree node identifier for the "led1" alias. */
|
||||
#define LED1_NODE DT_ALIAS(led1)
|
||||
|
||||
#if DT_NODE_HAS_STATUS(LED1_NODE, okay)
|
||||
#define LED1 DT_GPIO_LABEL(LED1_NODE, gpios)
|
||||
#define PIN DT_GPIO_PIN(LED1_NODE, gpios)
|
||||
#if DT_PHA_HAS_CELL(LED1_NODE, gpios, flags)
|
||||
#define FLAGS DT_GPIO_FLAGS(LED1_NODE, gpios)
|
||||
#endif
|
||||
#else
|
||||
/* A build error here means your board isn't set up to blink an LED. */
|
||||
#error "Unsupported board: led0 devicetree alias is not defined"
|
||||
#define LED1 ""
|
||||
#define PIN 0
|
||||
#endif
|
||||
|
||||
#ifndef FLAGS
|
||||
#define FLAGS 0
|
||||
#endif
|
||||
|
||||
struct device *dev;
|
||||
|
||||
void add_infected_key(period_t* period){
|
||||
|
||||
// TODO lome: Do we need it?
|
||||
|
||||
//printk("Interval: %u\n", period->periodInterval);
|
||||
//printk("RPI: "); print_rpi((rolling_proximity_identifier_t*)&period->periodKey); printk("\n");
|
||||
next_infected_key_id++;
|
||||
//find correct "day", TODO: also check a bit before and after
|
||||
int index = get_index_by_interval(period->periodInterval);
|
||||
if( index < 0 ){
|
||||
printk("Exposure check: period %i not found\n", period->periodInterval);
|
||||
return;
|
||||
}
|
||||
for( int i = 0; i < EN_TEK_ROLLING_PERIOD; i++){
|
||||
static ENIntervalIdentifier intervalIdentifier;
|
||||
en_derive_interval_identifier(&intervalIdentifier, &period->periodKey, period->periodInterval + i);
|
||||
//go through all long-term contacts for this day and check if I have seen the intervalIdentifier
|
||||
for( int j = 0; j < period_contacts[index].cnt; j++){
|
||||
int ret = memcmp(&period_contacts[index].period_contacts[j].rolling_proximity_identifier, &intervalIdentifier, sizeof(rolling_proximity_identifier_t));
|
||||
if( ret == 0 ){
|
||||
printk("Found exposure: rpi ");
|
||||
print_rpi(&period_contacts[index].period_contacts[j].rolling_proximity_identifier);
|
||||
printk(" aem ");
|
||||
print_aem(&period_contacts[index].period_contacts[j].associated_encrypted_metadata);
|
||||
printk(" max rssi %i, cnt %u, duration %u\n", period_contacts[index].period_contacts[j].max_rssi, period_contacts[index].period_contacts[j].cnt, period_contacts[index].period_contacts[j].duration);
|
||||
gpio_pin_set(dev, PIN, (int)1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint32_t get_next_infected_key_id(){
|
||||
return next_infected_key_id;
|
||||
}
|
||||
|
||||
void init_contacts(){
|
||||
contact_count = 0;
|
||||
period_index = 0;
|
||||
// period_index = get_current_period_nr();
|
||||
printk("Starting with period %d\n", period_index);
|
||||
|
||||
dev = device_get_binding(LED1);
|
||||
if (dev == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_pin_set(dev, PIN, (int)0);
|
||||
|
||||
}
|
||||
|
@ -12,51 +12,9 @@
|
||||
|
||||
#include "covid.h"
|
||||
#include "covid_types.h"
|
||||
#include "exposure-notification.h"
|
||||
|
||||
//short term contacts: number of people we meet in the 5 minute window. Records any contact, will later be checked whether this contact is longer than 5 minutes
|
||||
#ifndef MAX_CONTACTS
|
||||
#define MAX_CONTACTS 1000
|
||||
#endif
|
||||
|
||||
//number of contact during on day.
|
||||
#ifndef MAX_PERIOD_CONTACTS
|
||||
#define MAX_PERIOD_CONTACTS 400
|
||||
#endif
|
||||
|
||||
//number of perdios (=days) we record data for
|
||||
#ifndef PERIODS
|
||||
#define PERIODS 14
|
||||
#endif
|
||||
|
||||
typedef struct period_contact {
|
||||
uint32_t duration;
|
||||
uint16_t cnt;
|
||||
int8_t max_rssi; //TODO also store avg rssi?
|
||||
rolling_proximity_identifier_t rolling_proximity_identifier;
|
||||
associated_encrypted_metadata_t associated_encrypted_metadata;
|
||||
} period_contact_t;
|
||||
|
||||
typedef struct period_contacts {
|
||||
int cnt;
|
||||
period_contact_t period_contacts[MAX_PERIOD_CONTACTS];
|
||||
} period_contacts_t;
|
||||
|
||||
typedef struct contact {
|
||||
uint32_t most_recent_contact_time; //TODO: what is the correct type here?
|
||||
uint32_t first_contact_time; //TODO: what is the correct type here?
|
||||
uint16_t cnt;
|
||||
rssi_t max_rssi;
|
||||
rolling_proximity_identifier_t rolling_proximity_identifier;
|
||||
associated_encrypted_metadata_t associated_encrypted_metadata;
|
||||
} contact_t;
|
||||
|
||||
void init_contacts();
|
||||
int check_add_contact(uint32_t contact_time, rolling_proximity_identifier_t* rpi, associated_encrypted_metadata_t* aem, int8_t rssi);
|
||||
void key_change(int current_period_index);
|
||||
|
||||
void add_infected_key(period_t* period);
|
||||
uint32_t get_next_infected_key_id();
|
||||
|
||||
void print_key(_ENBaseKey* key);
|
||||
void print_rpi(rolling_proximity_identifier_t* rpi);
|
||||
void print_aem(associated_encrypted_metadata_t* aem);
|
||||
|
||||
|
@ -20,69 +20,6 @@
|
||||
#include "covid.h"
|
||||
#include "contacts.h"
|
||||
|
||||
//TODO: change device name in project conf, set id dynamicaally, so that not all devices have the same name...
|
||||
|
||||
// 0651C79E-ADA7-42EA-986A-9F69790D11F2
|
||||
static struct bt_uuid_128 covid_service_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0xF2);
|
||||
|
||||
static struct bt_uuid_128 next_key_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0xF3);
|
||||
|
||||
static struct bt_uuid_128 new_key_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0xF4);
|
||||
|
||||
static struct bt_uuid_128 infected_key_cnt_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0xF5);
|
||||
static struct bt_uuid_128 infected_key_0_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x00);
|
||||
static struct bt_uuid_128 infected_key_1_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x01);
|
||||
static struct bt_uuid_128 infected_key_2_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x02);
|
||||
static struct bt_uuid_128 infected_key_3_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x03);
|
||||
static struct bt_uuid_128 infected_key_4_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x04);
|
||||
static struct bt_uuid_128 infected_key_5_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x05);
|
||||
static struct bt_uuid_128 infected_key_6_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x06);
|
||||
static struct bt_uuid_128 infected_key_7_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x07);
|
||||
static struct bt_uuid_128 infected_key_8_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x08);
|
||||
static struct bt_uuid_128 infected_key_9_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x09);
|
||||
static struct bt_uuid_128 infected_key_10_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x0A);
|
||||
static struct bt_uuid_128 infected_key_11_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x0B);
|
||||
static struct bt_uuid_128 infected_key_12_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x0C);
|
||||
static struct bt_uuid_128 infected_key_13_uuid = BT_UUID_INIT_128(
|
||||
0x06, 0x51, 0xC7, 0x9E, 0xAD, 0xA7, 0x42, 0xEA,
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0x0D);
|
||||
|
||||
|
||||
|
||||
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
|
||||
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
|
||||
|
||||
@ -94,122 +31,19 @@ static const struct bt_data ad[] = {
|
||||
0x98, 0x6A, 0x9F, 0x69, 0x79, 0x0D, 0x11, 0xF2),
|
||||
};
|
||||
|
||||
static ssize_t read_next_key(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
uint32_t id = get_next_infected_key_id();
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &id, sizeof(id));
|
||||
}
|
||||
|
||||
static ssize_t read_key_cnt(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
unsigned int cnt = get_period_cnt_if_infected();
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &cnt, sizeof(unsigned int));
|
||||
}
|
||||
static ssize_t read_key_0(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(0, &size);
|
||||
// printk("read key 0, size %u, pointer %p\n", size, p);
|
||||
// printk("Interval: %u\n", p->periodInterval);
|
||||
// printk("RPI: "); print_rpi((rolling_proximity_identifier_t*)&p->periodKey); printk("\n");
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||
}
|
||||
static ssize_t read_key_1(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(1, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||
}
|
||||
static ssize_t read_key_2(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(2, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||
}
|
||||
static ssize_t read_key_3(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(3, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||
}
|
||||
static ssize_t read_key_4(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(4, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||
}
|
||||
static ssize_t read_key_5(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(5, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||
}
|
||||
static ssize_t read_key_6(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(6, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||
}
|
||||
static ssize_t read_key_7(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(7, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||
}
|
||||
static ssize_t read_key_8(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(8, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||
}
|
||||
static ssize_t read_key_9(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(9, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, p, size);
|
||||
}
|
||||
static ssize_t read_key_10(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(10, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
||||
}
|
||||
static ssize_t read_key_11(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(11, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
||||
}
|
||||
static ssize_t read_key_12(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(12, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
||||
}
|
||||
static ssize_t read_key_13(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset){
|
||||
size_t size = 0;
|
||||
period_t* p = get_period_if_infected(13, &size);
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &p, size);
|
||||
}
|
||||
|
||||
//TODO: copy more than one key
|
||||
static ssize_t write_new_key(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr,
|
||||
const void *buf, uint16_t len, uint16_t offset,
|
||||
uint8_t flags)
|
||||
{
|
||||
//printk("write key\n");
|
||||
if( offset != 0 ){
|
||||
printk("error: invalid offset %u\n", offset);
|
||||
return len;
|
||||
}
|
||||
if( len != sizeof(period_t) ){
|
||||
printk("error: invalid length %u (expected %u)\n", len, sizeof(period_t));
|
||||
return len;
|
||||
}
|
||||
period_t* period = (period_t*)buf;
|
||||
add_infected_key(period);
|
||||
return len;
|
||||
}
|
||||
|
||||
static void connected(struct bt_conn *conn, uint8_t err)
|
||||
{
|
||||
|
||||
if (err) {
|
||||
printk("Connection failed (err 0x%02x)\n", err);
|
||||
} else {
|
||||
//printk("Connected\n");
|
||||
printk("Connected\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void disconnected(struct bt_conn *conn, uint8_t reason)
|
||||
{
|
||||
//printk("Disconnected (reason 0x%02x)\n", reason);
|
||||
printk("Disconnected (reason 0x%02x)\n", reason);
|
||||
}
|
||||
|
||||
static struct bt_conn_cb conn_callbacks = {
|
||||
@ -259,45 +93,4 @@ int do_gatt(void){
|
||||
|
||||
//printk("gatt end\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
BT_GATT_SERVICE_DEFINE(covid_svc,
|
||||
|
||||
BT_GATT_PRIMARY_SERVICE(&covid_service_uuid),
|
||||
//TODO: switch on crypto and switch to signed keys
|
||||
BT_GATT_CHARACTERISTIC(&next_key_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_next_key, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&new_key_uuid.uuid, BT_GATT_CHRC_WRITE,
|
||||
BT_GATT_PERM_WRITE, NULL, write_new_key, NULL),
|
||||
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_cnt_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_cnt, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_0_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_0, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_1_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_1, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_2_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_2, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_3_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_3, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_4_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_4, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_5_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_5, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_6_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_6, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_7_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_7, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_8_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_8, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_9_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_9, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_10_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_10, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_11_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_11, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_12_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_12, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(&infected_key_13_uuid.uuid, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_key_13, NULL, NULL),
|
||||
);
|
||||
}
|
@ -36,7 +36,6 @@ void main(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
init_contacts();
|
||||
err = init_io();
|
||||
if (err) {
|
||||
printk("Button init failed (err %d)\n", err);
|
||||
|
Loading…
Reference in New Issue
Block a user