/** * Copyright (c) 2026 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #pragma once #include "dusk.h" #include "network/networkhttprequest.h" #include "thread/thread.h" #include #define NETWORK_HTTP_PENDING_MAX 4 #define NETWORK_HTTP_URL_MAX 512 #define NETWORK_HTTP_BODY_MAX 2048 #define NETWORK_HTTP_RESPONSE_MAX 16384 #define NETWORK_HTTP_HEADER_MAX 8 #define NETWORK_HTTP_HEADER_KEY_MAX 64 #define NETWORK_HTTP_HEADER_VAL_MAX 256 #define NETWORK_ERROR_MESSAGE_MAX 256 #define NETWORK_PSP_AGENT "DuskEngine/1.0" #define NETWORK_PSP_HTTP_HEAP_SIZE 0x25800 typedef enum { NETWORK_PSP_STATE_DISCONNECTED, /* Init done, no connection requested yet */ NETWORK_PSP_STATE_DIALOG, /* WiFi netconf dialog is active */ NETWORK_PSP_STATE_CONNECTED, /* AP connected, HTTP ready */ NETWORK_PSP_STATE_FAILED, /* Connection attempt failed or cancelled */ } networkpspstate_t; typedef struct { bool_t used; volatile bool_t resultReady; bool_t isError; char_t url[NETWORK_HTTP_URL_MAX]; networkhttprequestmethod_t method; char_t body[NETWORK_HTTP_BODY_MAX]; bool_t hasBody; char_t headerKeys[NETWORK_HTTP_HEADER_MAX][NETWORK_HTTP_HEADER_KEY_MAX]; char_t headerVals[NETWORK_HTTP_HEADER_MAX][NETWORK_HTTP_HEADER_VAL_MAX]; uint32_t headerCount; networkhttpcallback_t callback; networkhttperrorcallback_t errorCallback; void *user; uint16_t status; char_t responseBody[NETWORK_HTTP_RESPONSE_MAX]; char_t errorMessage[NETWORK_ERROR_MESSAGE_MAX]; thread_t thread; } networkhttppendingitem_t; typedef struct { networkpspstate_t state; pspUtilityNetconfData dialogData; struct pspUtilityNetconfAdhoc dialogAdhoc; void (*onConnected)(void *user); void (*onFailed)(errorret_t error, void *user); void *connectionUser; networkhttppendingitem_t requests[NETWORK_HTTP_PENDING_MAX]; threadmutex_t resultsMutex; } networkpsp_t; errorret_t networkPspInit(); errorret_t networkPspUpdate(); errorret_t networkPspDispose(); bool_t networkPspIsConnected(); void networkPspRequestConnection( void (*onConnected)(void *user), void (*onFailed)(errorret_t error, void *user), void *user ); void networkPspHTTPRequest( const char_t *url, const networkhttprequestmethod_t method, const char_t *bodyOrNull, const networkhttpheader_t *headers, const uint32_t headerCount, void *user, networkhttpcallback_t callback, networkhttperrorcallback_t errorCallback );