1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-12-01 19:51:32 +02:00
antorcha/fw/reset.c

52 lines
1.2 KiB
C
Raw Normal View History

/*
* fw/reset.c - Reset protocol
*
* Written 2012 by Werner Almesberger
* Copyright 2012 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "proto.h"
#include "dispatch.h"
#include "secret.h"
/*
* For now, we use the unlock secret for reset as well. The reasoning is as
* follows:
*
* - both secrets are transmitted in the clear and can therefore only be
* used in a trusted environment,
* - both secrets are used mainly during development and not needed for regular
* operation,
* - RESET is normally followed immediately by FIRMWARE, so a listener could
* intercept the secret(s) either way.
*/
static bool reset_first(uint8_t limit, const uint8_t *payload)
{
if (memcmp_P(payload, maint_secret, PAYLOAD))
return 0;
WDTCSR = 1 << WDE;
return 1;
}
struct handler reset_handler = {
.type = RESET,
.first = reset_first,
};