stub out secure as its own feature
This commit is contained in:
		
							parent
							
								
									2c068d08dd
								
							
						
					
					
						commit
						89fab427c4
					
				
					 14 changed files with 204 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -16,6 +16,7 @@
 | 
			
		|||
 | 
			
		||||
#include <quantum.h>
 | 
			
		||||
#include <xap.h>
 | 
			
		||||
#include "secure.h"
 | 
			
		||||
 | 
			
		||||
#include "info_json_gz.h"
 | 
			
		||||
bool get_info_json_chunk(uint16_t offset, uint8_t *data, uint8_t data_len) {
 | 
			
		||||
| 
						 | 
				
			
			@ -27,8 +28,6 @@ bool get_info_json_chunk(uint16_t offset, uint8_t *data, uint8_t data_len) {
 | 
			
		|||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t secure_status = 2;
 | 
			
		||||
 | 
			
		||||
#define QSTR2(z) #z
 | 
			
		||||
#define QSTR(z) QSTR2(z)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -86,11 +85,18 @@ void xap_execute_route(xap_token_t token, const xap_route_t *routes, size_t max_
 | 
			
		|||
        xap_route_t route;
 | 
			
		||||
        memcpy_P(&route, &routes[id], sizeof(xap_route_t));
 | 
			
		||||
 | 
			
		||||
        if (route.flags.is_secure && secure_status != 2) {
 | 
			
		||||
        if (route.flags.is_secure && secure_get_status() != SECURE_UNLOCKED) {
 | 
			
		||||
            xap_respond_failure(token, XAP_RESPONSE_FLAG_SECURE_FAILURE);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // TODO: All other subsystems are disabled during unlock.
 | 
			
		||||
        //       how to flag status route as still allowed?
 | 
			
		||||
        // if (!route.flags.is_secure && secure_get_status() == SECURE_PENDING) {
 | 
			
		||||
        //     xap_respond_failure(token, XAP_RESPONSE_FLAG_UNLOCK_IN_PROGRESS);
 | 
			
		||||
        //     return;
 | 
			
		||||
        // }
 | 
			
		||||
 | 
			
		||||
        switch (route.flags.type) {
 | 
			
		||||
            case XAP_ROUTE:
 | 
			
		||||
                if (route.child_routes != NULL && route.child_routes_len > 0 && data_len > 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -134,3 +140,13 @@ void xap_execute_route(xap_token_t token, const xap_route_t *routes, size_t max_
 | 
			
		|||
void xap_receive(xap_token_t token, const uint8_t *data, size_t length) {
 | 
			
		||||
    xap_execute_route(token, xap_route_table, sizeof(xap_route_table) / sizeof(xap_route_t), data, length);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void xap_event_task(void) {
 | 
			
		||||
    static secure_status_t last_status = -1;
 | 
			
		||||
 | 
			
		||||
    secure_status_t status = secure_get_status();
 | 
			
		||||
    if (last_status != status) {
 | 
			
		||||
        last_status = status;
 | 
			
		||||
        xap_broadcast_secure_status(status);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,3 +36,5 @@ bool xap_respond_data_P(xap_token_t token, const void *data, size_t length);
 | 
			
		|||
 | 
			
		||||
void xap_send(xap_token_t token, xap_response_flags_t response_flags, const void *data, size_t length);
 | 
			
		||||
void xap_broadcast(uint8_t type, const void *data, size_t length);
 | 
			
		||||
 | 
			
		||||
void xap_event_task(void);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,6 +16,7 @@
 | 
			
		|||
 | 
			
		||||
#include <quantum.h>
 | 
			
		||||
#include <xap.h>
 | 
			
		||||
#include "secure.h"
 | 
			
		||||
 | 
			
		||||
void xap_respond_success(xap_token_t token) {
 | 
			
		||||
    xap_send(token, XAP_RESPONSE_FLAG_SUCCESS, NULL, 0);
 | 
			
		||||
| 
						 | 
				
			
			@ -59,6 +60,21 @@ bool xap_respond_get_info_json_chunk(xap_token_t token, const void *data, size_t
 | 
			
		|||
    return xap_respond_data(token, &ret, sizeof(ret));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool xap_respond_secure_status(xap_token_t token, const void *data, size_t length) {
 | 
			
		||||
    uint8_t ret = secure_get_status();
 | 
			
		||||
    return xap_respond_data(token, &ret, sizeof(ret));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool xap_respond_secure_unlock(xap_token_t token, const void *data, size_t length) {
 | 
			
		||||
    secure_request_unlock();
 | 
			
		||||
    return xap_respond_data(token, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool xap_respond_secure_lock(xap_token_t token, const void *data, size_t length) {
 | 
			
		||||
    secure_lock();
 | 
			
		||||
    return xap_respond_data(token, NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO: how to set this if "custom" is just an empty stub
 | 
			
		||||
#ifndef BOOTLOADER_JUMP_SUPPORTED
 | 
			
		||||
#    define BOOTLOADER_JUMP_SUPPORTED
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue