really still wip
This commit is contained in:
250
User/lib/adc/temperature.c
Normal file
250
User/lib/adc/temperature.c
Normal file
@@ -0,0 +1,250 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : temperature.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2023/11/17
|
||||
* Description : Temperature program body.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
*@Note
|
||||
*Internal temperature sensor routine:
|
||||
*Through the ADC channel 16, the output voltage value and temperature value of the internal
|
||||
*temperature sensor are collected.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
#include "lib/telemetry/telemetry.h"
|
||||
|
||||
/* Global Variable */
|
||||
s16 Calibrattion_Val = 0;
|
||||
|
||||
/*********************************************************************
|
||||
* @fn ADC_Function_Init
|
||||
*
|
||||
* @brief Initializes ADC collection.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void ADC_Function_Init(void)
|
||||
{
|
||||
ADC_InitTypeDef ADC_InitStructure={0};
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE );
|
||||
RCC_ADCCLKConfig(RCC_PCLK2_Div8);
|
||||
|
||||
ADC_DeInit(ADC1);
|
||||
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
||||
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
|
||||
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
|
||||
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
|
||||
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
||||
ADC_InitStructure.ADC_NbrOfChannel = 1;
|
||||
ADC_Init(ADC1, &ADC_InitStructure);
|
||||
|
||||
ADC_Cmd(ADC1, ENABLE);
|
||||
|
||||
ADC_BufferCmd(ADC1, DISABLE); //disable buffer
|
||||
ADC_ResetCalibration(ADC1);
|
||||
while(ADC_GetResetCalibrationStatus(ADC1));
|
||||
ADC_StartCalibration(ADC1);
|
||||
while(ADC_GetCalibrationStatus(ADC1));
|
||||
Calibrattion_Val = Get_CalibrationValue(ADC1);
|
||||
|
||||
ADC_BufferCmd(ADC1, ENABLE); //enable buffer
|
||||
|
||||
ADC_TempSensorVrefintCmd(ENABLE);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Get_ADC_Val
|
||||
*
|
||||
* @brief Returns ADCx conversion result data.
|
||||
*
|
||||
* @param ch - ADC channel.
|
||||
* ADC_Channel_0 - ADC Channel0 selected.
|
||||
* ADC_Channel_1 - ADC Channel1 selected.
|
||||
* ADC_Channel_2 - ADC Channel2 selected.
|
||||
* ADC_Channel_3 - ADC Channel3 selected.
|
||||
* ADC_Channel_4 - ADC Channel4 selected.
|
||||
* ADC_Channel_5 - ADC Channel5 selected.
|
||||
* ADC_Channel_6 - ADC Channel6 selected.
|
||||
* ADC_Channel_7 - ADC Channel7 selected.
|
||||
* ADC_Channel_8 - ADC Channel8 selected.
|
||||
* ADC_Channel_9 - ADC Channel9 selected.
|
||||
* ADC_Channel_10 - ADC Channel10 selected.
|
||||
* ADC_Channel_11 - ADC Channel11 selected.
|
||||
* ADC_Channel_12 - ADC Channel12 selected.
|
||||
* ADC_Channel_13 - ADC Channel13 selected.
|
||||
* ADC_Channel_14 - ADC Channel14 selected.
|
||||
* ADC_Channel_15 - ADC Channel15 selected.
|
||||
* ADC_Channel_16 - ADC Channel16 selected.
|
||||
* ADC_Channel_17 - ADC Channel17 selected.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
u16 Get_ADC_Val(u8 ch)
|
||||
{
|
||||
u16 val;
|
||||
|
||||
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_239Cycles5 );
|
||||
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
|
||||
|
||||
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));
|
||||
|
||||
val = ADC_GetConversionValue(ADC1);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Get_ADC_Average
|
||||
*
|
||||
* @brief Returns ADCx conversion result average data.
|
||||
*
|
||||
* @param ch - ADC channel.
|
||||
* ADC_Channel_0 - ADC Channel0 selected.
|
||||
* ADC_Channel_1 - ADC Channel1 selected.
|
||||
* ADC_Channel_2 - ADC Channel2 selected.
|
||||
* ADC_Channel_3 - ADC Channel3 selected.
|
||||
* ADC_Channel_4 - ADC Channel4 selected.
|
||||
* ADC_Channel_5 - ADC Channel5 selected.
|
||||
* ADC_Channel_6 - ADC Channel6 selected.
|
||||
* ADC_Channel_7 - ADC Channel7 selected.
|
||||
* ADC_Channel_8 - ADC Channel8 selected.
|
||||
* ADC_Channel_9 - ADC Channel9 selected.
|
||||
* ADC_Channel_10 - ADC Channel10 selected.
|
||||
* ADC_Channel_11 - ADC Channel11 selected.
|
||||
* ADC_Channel_12 - ADC Channel12 selected.
|
||||
* ADC_Channel_13 - ADC Channel13 selected.
|
||||
* ADC_Channel_14 - ADC Channel14 selected.
|
||||
* ADC_Channel_15 - ADC Channel15 selected.
|
||||
* ADC_Channel_16 - ADC Channel16 selected.
|
||||
* ADC_Channel_17 - ADC Channel17 selected.
|
||||
*
|
||||
* @return val - The Data conversion value.
|
||||
*/
|
||||
u16 Get_ADC_Average(u8 ch,u8 times)
|
||||
{
|
||||
u32 temp_val=0;
|
||||
u8 t;
|
||||
u16 val;
|
||||
|
||||
for(t=0;t<times;t++)
|
||||
{
|
||||
temp_val+=Get_ADC_Val(ch);
|
||||
Delay_Ms(5);
|
||||
}
|
||||
|
||||
val = temp_val/times;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Get_ConversionVal
|
||||
*
|
||||
* @brief Get Conversion Value.
|
||||
*
|
||||
* @param val - Sampling value
|
||||
*
|
||||
* @return val+Calibrattion_Val - Conversion Value.
|
||||
*/
|
||||
u16 Get_ConversionVal(s16 val)
|
||||
{
|
||||
if((val+Calibrattion_Val)<0|| val==0) return 0;
|
||||
if((Calibrattion_Val+val)>4095||val==4095) return 4095;
|
||||
return (val+Calibrattion_Val);
|
||||
}
|
||||
|
||||
s32 TempSensor_Volt_To_Temper_x10(s32 Value)
|
||||
{
|
||||
s32 Temper_x10;
|
||||
s32 Refer_Volt, Refer_Temper;
|
||||
s32 k = 43; // slope in mV/¡ãC
|
||||
|
||||
// Read factory calibration values
|
||||
Refer_Volt = (s32)((*(u32 *)0x1FFFF720) & 0x0000FFFF); // mV at reference temp
|
||||
Refer_Temper = (s32)(((*(u32 *)0x1FFFF720) >> 16) & 0x0000FFFF); // ¡ãC
|
||||
|
||||
// Compute temperature in decicelsius
|
||||
// Formula: T_x10 = Tref*10 - ((V - Vref)*100 + k/2) / k
|
||||
// Multiply (V - Vref) by 100 to get tenths of ¡ãC
|
||||
Temper_x10 = Refer_Temper * 10 - ((Value - Refer_Volt) * 100 + (k / 2)) / k;
|
||||
|
||||
return Temper_x10;
|
||||
}
|
||||
|
||||
|
||||
s32 getTemperature(void)
|
||||
{
|
||||
u16 ADC_val;
|
||||
s32 val_mv;
|
||||
|
||||
ADC_val = Get_ADC_Average( ADC_Channel_TempSensor, 10 );
|
||||
|
||||
ADC_val = Get_ConversionVal(ADC_val);
|
||||
|
||||
val_mv = (ADC_val*3300/4096);
|
||||
|
||||
return TempSensor_Volt_To_Temper(val_mv);
|
||||
}
|
||||
|
||||
s16 getDeciTemperature(void)
|
||||
{
|
||||
u16 ADC_val;
|
||||
s32 val_mv;
|
||||
|
||||
ADC_val = Get_ADC_Average( ADC_Channel_TempSensor, 10 );
|
||||
|
||||
ADC_val = Get_ConversionVal(ADC_val);
|
||||
|
||||
val_mv = (ADC_val*3300/4096);
|
||||
|
||||
s32 temp_x10 = TempSensor_Volt_To_Temper_x10(val_mv);
|
||||
|
||||
int16_t temp16 = (int16_t)temp_x10; // store in 2 bytes
|
||||
return temp16;
|
||||
}
|
||||
|
||||
s32 getVoltage(void)
|
||||
{
|
||||
u16 ADC_val;
|
||||
s32 val_mv;
|
||||
|
||||
ADC_val = Get_ADC_Average( ADC_Channel_0, 10 );
|
||||
|
||||
ADC_val = Get_ConversionVal(ADC_val);
|
||||
|
||||
|
||||
val_mv = (ADC_val*3300/4096);
|
||||
|
||||
return val_mv;
|
||||
}
|
||||
|
||||
// Helper: convert signed 24-bit int to 3 bytes (big-endian)
|
||||
void int24_to_bytes(int32_t value, uint8_t *bytes) {
|
||||
if (value < 0) value += 0x1000000; // 2's complement for 24-bit
|
||||
bytes[0] = (value >> 16) & 0xFF;
|
||||
bytes[1] = (value >> 8) & 0xFF;
|
||||
bytes[2] = value & 0xFF;
|
||||
}
|
||||
|
||||
// Encode GPS into CayenneLPP payload
|
||||
void encode_gps(uint8_t channel, float lat, float lon, float alt, uint8_t *payload) {
|
||||
payload[0] = channel;
|
||||
payload[1] = LPP_GPS; // GPS type
|
||||
|
||||
int32_t latInt = lat * 10000;
|
||||
int32_t lonInt = lon * 10000;
|
||||
int32_t altInt = alt * 100;
|
||||
|
||||
int24_to_bytes(latInt, &payload[2]);
|
||||
int24_to_bytes(lonInt, &payload[5]);
|
||||
int24_to_bytes(altInt, &payload[8]);
|
||||
}
|
||||
113
User/lib/adc/temperature.h
Normal file
113
User/lib/adc/temperature.h
Normal file
@@ -0,0 +1,113 @@
|
||||
#ifndef TEMPERATURE_HEADER
|
||||
#define TEMPERATURE_HEADER
|
||||
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : temperature.c
|
||||
* Author : WCH
|
||||
* Version : V1.0.0
|
||||
* Date : 2023/11/17
|
||||
* Description : Temperature program body.
|
||||
*********************************************************************************
|
||||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
||||
* Attention: This software (modified or not) and binary are used for
|
||||
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
*@Note
|
||||
*Internal temperature sensor routine:
|
||||
*Through the ADC channel 16, the output voltage value and temperature value of the internal
|
||||
*temperature sensor are collected.
|
||||
*
|
||||
*/
|
||||
|
||||
/* Global Variable */
|
||||
extern s16 Calibrattion_Val;
|
||||
|
||||
/*********************************************************************
|
||||
* @fn ADC_Function_Init
|
||||
*
|
||||
* @brief Initializes ADC collection.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void ADC_Function_Init(void);
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Get_ADC_Val
|
||||
*
|
||||
* @brief Returns ADCx conversion result data.
|
||||
*
|
||||
* @param ch - ADC channel.
|
||||
* ADC_Channel_0 - ADC Channel0 selected.
|
||||
* ADC_Channel_1 - ADC Channel1 selected.
|
||||
* ADC_Channel_2 - ADC Channel2 selected.
|
||||
* ADC_Channel_3 - ADC Channel3 selected.
|
||||
* ADC_Channel_4 - ADC Channel4 selected.
|
||||
* ADC_Channel_5 - ADC Channel5 selected.
|
||||
* ADC_Channel_6 - ADC Channel6 selected.
|
||||
* ADC_Channel_7 - ADC Channel7 selected.
|
||||
* ADC_Channel_8 - ADC Channel8 selected.
|
||||
* ADC_Channel_9 - ADC Channel9 selected.
|
||||
* ADC_Channel_10 - ADC Channel10 selected.
|
||||
* ADC_Channel_11 - ADC Channel11 selected.
|
||||
* ADC_Channel_12 - ADC Channel12 selected.
|
||||
* ADC_Channel_13 - ADC Channel13 selected.
|
||||
* ADC_Channel_14 - ADC Channel14 selected.
|
||||
* ADC_Channel_15 - ADC Channel15 selected.
|
||||
* ADC_Channel_16 - ADC Channel16 selected.
|
||||
* ADC_Channel_17 - ADC Channel17 selected.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
u16 Get_ADC_Val(u8 ch);
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Get_ADC_Average
|
||||
*
|
||||
* @brief Returns ADCx conversion result average data.
|
||||
*
|
||||
* @param ch - ADC channel.
|
||||
* ADC_Channel_0 - ADC Channel0 selected.
|
||||
* ADC_Channel_1 - ADC Channel1 selected.
|
||||
* ADC_Channel_2 - ADC Channel2 selected.
|
||||
* ADC_Channel_3 - ADC Channel3 selected.
|
||||
* ADC_Channel_4 - ADC Channel4 selected.
|
||||
* ADC_Channel_5 - ADC Channel5 selected.
|
||||
* ADC_Channel_6 - ADC Channel6 selected.
|
||||
* ADC_Channel_7 - ADC Channel7 selected.
|
||||
* ADC_Channel_8 - ADC Channel8 selected.
|
||||
* ADC_Channel_9 - ADC Channel9 selected.
|
||||
* ADC_Channel_10 - ADC Channel10 selected.
|
||||
* ADC_Channel_11 - ADC Channel11 selected.
|
||||
* ADC_Channel_12 - ADC Channel12 selected.
|
||||
* ADC_Channel_13 - ADC Channel13 selected.
|
||||
* ADC_Channel_14 - ADC Channel14 selected.
|
||||
* ADC_Channel_15 - ADC Channel15 selected.
|
||||
* ADC_Channel_16 - ADC Channel16 selected.
|
||||
* ADC_Channel_17 - ADC Channel17 selected.
|
||||
*
|
||||
* @return val - The Data conversion value.
|
||||
*/
|
||||
u16 Get_ADC_Average(u8 ch,u8 times);
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Get_ConversionVal
|
||||
*
|
||||
* @brief Get Conversion Value.
|
||||
*
|
||||
* @param val - Sampling value
|
||||
*
|
||||
* @return val+Calibrattion_Val - Conversion Value.
|
||||
*/
|
||||
u16 Get_ConversionVal(s16 val);
|
||||
|
||||
s32 getTemperature(void);
|
||||
|
||||
s16 getDeciTemperature(void);
|
||||
|
||||
s32 getVoltage(void);
|
||||
|
||||
void encode_gps(uint8_t channel, float lat, float lon, float alt, uint8_t *payload);
|
||||
|
||||
#endif
|
||||
@@ -9,32 +9,23 @@
|
||||
#define AESKeyCount 8
|
||||
#define CONTACT_COUNT 100
|
||||
|
||||
typedef struct {
|
||||
char name[32];
|
||||
unsigned char pubKey[32];
|
||||
unsigned char secret[32];
|
||||
|
||||
int32_t gps_latitude;
|
||||
int32_t gps_longitude;
|
||||
|
||||
Path path;
|
||||
|
||||
uint8_t flags;
|
||||
uint8_t type;
|
||||
|
||||
uint8_t authenticated;
|
||||
|
||||
uint32_t last_seen_rt; //remote timestamp
|
||||
uint32_t last_seen_lt; //local timestamp
|
||||
|
||||
uint32_t sync_timestamp;
|
||||
} NodeEntry;
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic; // e.g. 0xDEADBEEF
|
||||
uint8_t privkey[32]; // Ed25519 private
|
||||
uint8_t pubkey[32]; // Ed25519 public
|
||||
uint8_t nodeType;
|
||||
int32_t latitude;
|
||||
int32_t longitude;
|
||||
int32_t altitude;
|
||||
|
||||
int8_t txPowerInDbm;
|
||||
uint32_t frequencyInHz;
|
||||
uint8_t spreadingFactor;
|
||||
uint8_t bandwidth;
|
||||
uint8_t codingRate;
|
||||
uint16_t preambleLength;
|
||||
float tcxoVoltage;
|
||||
|
||||
uint8_t aesKeys[AESKeyCount][17];
|
||||
uint8_t password[16];
|
||||
char nodeName[32];
|
||||
|
||||
@@ -4,34 +4,21 @@
|
||||
// Nightcracker's Ed25519 - https://github.com/orlp/ed25519
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(ED25519_BUILD_DLL)
|
||||
#define ED25519_DECLSPEC __declspec(dllexport)
|
||||
#elif defined(ED25519_DLL)
|
||||
#define ED25519_DECLSPEC __declspec(dllimport)
|
||||
#else
|
||||
#define ED25519_DECLSPEC
|
||||
#endif
|
||||
#else
|
||||
#define ED25519_DECLSPEC
|
||||
#endif
|
||||
|
||||
#include "meshcore/packetstructs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef ED25519_NO_SEED
|
||||
int ED25519_DECLSPEC ed25519_create_seed(unsigned char *seed);
|
||||
#endif
|
||||
|
||||
void ED25519_DECLSPEC ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed);
|
||||
void ED25519_DECLSPEC ed25519_derive_pub(unsigned char *public_key, const unsigned char *private_key);
|
||||
void ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key);
|
||||
int ED25519_DECLSPEC ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key);
|
||||
void ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar);
|
||||
void ED25519_DECLSPEC ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key);
|
||||
void ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed);
|
||||
void ed25519_derive_pub(unsigned char *public_key, const unsigned char *private_key);
|
||||
void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key);
|
||||
void ed25519_sign_ad(FrameStruct *frame);
|
||||
int ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key);
|
||||
int ed25519_verify_ad(const FrameStruct *frame);
|
||||
void ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar);
|
||||
void ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#include "ed_25519.h"
|
||||
|
||||
#ifndef ED25519_NO_SEED
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
int ed25519_create_seed(unsigned char *seed) {
|
||||
#ifdef _WIN32
|
||||
HCRYPTPROV prov;
|
||||
|
||||
if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!CryptGenRandom(prov, 32, seed)) {
|
||||
CryptReleaseContext(prov, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
CryptReleaseContext(prov, 0);
|
||||
#else
|
||||
FILE *f = fopen("/dev/urandom", "rb");
|
||||
|
||||
if (f == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
fread(seed, 1, 32, f);
|
||||
fclose(f);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "ed_25519.h"
|
||||
#include "lib/config.h"
|
||||
#include "sha512.h"
|
||||
#include "ge.h"
|
||||
#include "sc.h"
|
||||
@@ -29,3 +30,35 @@ void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t
|
||||
sc_reduce(hram);
|
||||
sc_muladd(signature + 32, hram, private_key, r);
|
||||
}
|
||||
|
||||
void ed25519_sign_ad(FrameStruct *frame) {
|
||||
sha512_context hash;
|
||||
unsigned char hram[64];
|
||||
unsigned char r[64];
|
||||
ge_p3 R;
|
||||
|
||||
unsigned char *signature = &(frame->payload[36]);
|
||||
|
||||
|
||||
sha512_init(&hash);
|
||||
sha512_update(&hash, persistent.privkey + 32, 32);
|
||||
sha512_update(&hash, frame->payload, 32);
|
||||
sha512_update(&hash, frame->payload, 36); // pubkey and timestamp combined (32 bytes pubkey, 4 bytes timestamp)
|
||||
sha512_update(&hash, &(frame->payload[100]), frame->payloadLen - 100);
|
||||
sha512_final(&hash, r);
|
||||
|
||||
sc_reduce(r);
|
||||
ge_scalarmult_base(&R, r);
|
||||
ge_p3_tobytes(signature, &R);
|
||||
|
||||
sha512_init(&hash);
|
||||
sha512_update(&hash, signature, 32);
|
||||
sha512_update(&hash, frame->payload, 32);
|
||||
sha512_update(&hash, frame->payload, 36); // pubkey and timestamp combined (32 bytes pubkey, 4 bytes timestamp)
|
||||
sha512_update(&hash, &(frame->payload[100]), frame->payloadLen - 100);
|
||||
sha512_final(&hash, hram);
|
||||
|
||||
sc_reduce(hram);
|
||||
sc_muladd(signature + 32, hram, persistent.privkey, r);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,3 +75,38 @@ int ed25519_verify(const unsigned char *signature, const unsigned char *message,
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int ed25519_verify_ad(const FrameStruct *frame) {
|
||||
unsigned char h[64];
|
||||
unsigned char checker[32];
|
||||
sha512_context hash;
|
||||
ge_p3 A;
|
||||
ge_p2 R;
|
||||
const unsigned char *signature = &(frame->payload[36]);
|
||||
|
||||
if (signature[63] & 224) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ge_frombytes_negate_vartime(&A, frame->payload) != 0) { //pubkey is at start
|
||||
return 0;
|
||||
}
|
||||
|
||||
sha512_init(&hash);
|
||||
sha512_update(&hash, signature, 32);
|
||||
sha512_update(&hash, frame->payload, 32);
|
||||
sha512_update(&hash, frame->payload, 36); // pubkey and timestamp combined (32 bytes pubkey, 4 bytes timestamp)
|
||||
sha512_update(&hash, &(frame->payload[100]), frame->payloadLen - 100);
|
||||
sha512_final(&hash, h);
|
||||
|
||||
sc_reduce(h);
|
||||
ge_double_scalarmult_vartime(&R, h, &A, signature + 32);
|
||||
ge_tobytes(checker, &R);
|
||||
|
||||
if (!consttime_equal(checker, signature)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
0
User/lib/telemetry/telemetry.c
Normal file
0
User/lib/telemetry/telemetry.c
Normal file
93
User/lib/telemetry/telemetry.h
Normal file
93
User/lib/telemetry/telemetry.h
Normal file
@@ -0,0 +1,93 @@
|
||||
#ifndef TELEMETRY_HEADER
|
||||
#define TELEMETRY_HEADER
|
||||
|
||||
#define TELEM_CHANNEL_SELF 1 // LPP data channel for 'self' device
|
||||
|
||||
#define LPP_DIGITAL_INPUT 0 // 1 byte
|
||||
#define LPP_DIGITAL_OUTPUT 1 // 1 byte
|
||||
#define LPP_ANALOG_INPUT 2 // 2 bytes, 0.01 signed
|
||||
#define LPP_ANALOG_OUTPUT 3 // 2 bytes, 0.01 signed
|
||||
#define LPP_GENERIC_SENSOR 100 // 4 bytes, unsigned
|
||||
#define LPP_LUMINOSITY 101 // 2 bytes, 1 lux unsigned
|
||||
#define LPP_PRESENCE 102 // 1 byte, bool
|
||||
#define LPP_TEMPERATURE 103 // 2 bytes, 0.1¡ãC signed
|
||||
#define LPP_RELATIVE_HUMIDITY 104 // 1 byte, 0.5% unsigned
|
||||
#define LPP_ACCELEROMETER 113 // 2 bytes per axis, 0.001G
|
||||
#define LPP_BAROMETRIC_PRESSURE 115 // 2 bytes 0.1hPa unsigned
|
||||
#define LPP_VOLTAGE 116 // 2 bytes 0.01V unsigned
|
||||
#define LPP_CURRENT 117 // 2 bytes 0.001A unsigned
|
||||
#define LPP_FREQUENCY 118 // 4 bytes 1Hz unsigned
|
||||
#define LPP_PERCENTAGE 120 // 1 byte 1-100% unsigned
|
||||
#define LPP_ALTITUDE 121 // 2 byte 1m signed
|
||||
#define LPP_CONCENTRATION 125 // 2 bytes, 1 ppm unsigned
|
||||
#define LPP_POWER 128 // 2 byte, 1W, unsigned
|
||||
#define LPP_DISTANCE 130 // 4 byte, 0.001m, unsigned
|
||||
#define LPP_ENERGY 131 // 4 byte, 0.001kWh, unsigned
|
||||
#define LPP_DIRECTION 132 // 2 bytes, 1deg, unsigned
|
||||
#define LPP_UNIXTIME 133 // 4 bytes, unsigned
|
||||
#define LPP_GYROMETER 134 // 2 bytes per axis, 0.01 ¡ã/s
|
||||
#define LPP_COLOUR 135 // 1 byte per RGB Color
|
||||
#define LPP_GPS 136 // 3 byte lon/lat 0.0001 ¡ã, 3 bytes alt 0.01 meter
|
||||
#define LPP_SWITCH 142 // 1 byte, 0/1
|
||||
#define LPP_POLYLINE 240 // 1 byte size, 1 byte delta factor, 3 byte lon/lat 0.0001¡ã * factor, n (size-8) bytes deltas
|
||||
|
||||
// Only Data Size
|
||||
#define LPP_DIGITAL_INPUT_SIZE 1
|
||||
#define LPP_DIGITAL_OUTPUT_SIZE 1
|
||||
#define LPP_ANALOG_INPUT_SIZE 2
|
||||
#define LPP_ANALOG_OUTPUT_SIZE 2
|
||||
#define LPP_GENERIC_SENSOR_SIZE 4
|
||||
#define LPP_LUMINOSITY_SIZE 2
|
||||
#define LPP_PRESENCE_SIZE 1
|
||||
#define LPP_TEMPERATURE_SIZE 2
|
||||
#define LPP_RELATIVE_HUMIDITY_SIZE 1
|
||||
#define LPP_ACCELEROMETER_SIZE 6
|
||||
#define LPP_BAROMETRIC_PRESSURE_SIZE 2
|
||||
#define LPP_VOLTAGE_SIZE 2
|
||||
#define LPP_CURRENT_SIZE 2
|
||||
#define LPP_FREQUENCY_SIZE 4
|
||||
#define LPP_PERCENTAGE_SIZE 1
|
||||
#define LPP_ALTITUDE_SIZE 2
|
||||
#define LPP_POWER_SIZE 2
|
||||
#define LPP_DISTANCE_SIZE 4
|
||||
#define LPP_ENERGY_SIZE 4
|
||||
#define LPP_DIRECTION_SIZE 2
|
||||
#define LPP_UNIXTIME_SIZE 4
|
||||
#define LPP_GYROMETER_SIZE 6
|
||||
#define LPP_GPS_SIZE 9
|
||||
#define LPP_SWITCH_SIZE 1
|
||||
#define LPP_CONCENTRATION_SIZE 2
|
||||
#define LPP_COLOUR_SIZE 3
|
||||
#define LPP_MIN_POLYLINE_SIZE 8
|
||||
|
||||
|
||||
// Multipliers
|
||||
#define LPP_DIGITAL_INPUT_MULT 1
|
||||
#define LPP_DIGITAL_OUTPUT_MULT 1
|
||||
#define LPP_ANALOG_INPUT_MULT 100
|
||||
#define LPP_ANALOG_OUTPUT_MULT 100
|
||||
#define LPP_GENERIC_SENSOR_MULT 1
|
||||
#define LPP_LUMINOSITY_MULT 1
|
||||
#define LPP_PRESENCE_MULT 1
|
||||
#define LPP_TEMPERATURE_MULT 10
|
||||
#define LPP_RELATIVE_HUMIDITY_MULT 2
|
||||
#define LPP_ACCELEROMETER_MULT 1000
|
||||
#define LPP_BAROMETRIC_PRESSURE_MULT 10
|
||||
#define LPP_VOLTAGE_MULT 100
|
||||
#define LPP_CURRENT_MULT 1000
|
||||
#define LPP_FREQUENCY_MULT 1
|
||||
#define LPP_PERCENTAGE_MULT 1
|
||||
#define LPP_ALTITUDE_MULT 1
|
||||
#define LPP_POWER_MULT 1
|
||||
#define LPP_DISTANCE_MULT 1000
|
||||
#define LPP_ENERGY_MULT 1000
|
||||
#define LPP_DIRECTION_MULT 1
|
||||
#define LPP_UNIXTIME_MULT 1
|
||||
#define LPP_GYROMETER_MULT 100
|
||||
#define LPP_GPS_LAT_LON_MULT 10000
|
||||
#define LPP_GPS_ALT_MULT 100
|
||||
#define LPP_SWITCH_MULT 1
|
||||
#define LPP_CONCENTRATION_MULT 1
|
||||
#define LPP_COLOUR_MULT 1
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user