### Connect to Proxy and Set Disconnect Callback Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md This example demonstrates how to initialize the proxy, start it with a specific address, and set a callback function to be executed upon disconnection. It includes error handling for proxy initialization and startup. The program then waits indefinitely for the proxy thread to exit. ```c #include #include void on_proxy_disconnect_callback(const char* msg) { printf("proxy exit. Reason: %s\n", msg); exit(0); } int start_proxy(char* proxy_address) { int ret; ret = el_proxy_init(); if (ret != 0) { printf("Could not start proxy. Exit.\n"); return ret; // failed } ret = el_proxy_start_with_address(proxy_address); if (ret != 0) { return ret; // failed } el_proxy_set_on_disconnect_callback(on_proxy_disconnect_callback); return 0; } int main() { int ret; ret = start_proxy("dap.local"); if (ret = 0) { exit(1); // failed } Sleep(INFINITE); // wait proxy thread to exit. return 0; } ``` -------------------------------- ### Start Proxy with Address Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Starts the Proxy service using the provided network address. Returns 0 on success and a non-zero value on failure. ```c int el_proxy_start_with_address(char *address); ``` -------------------------------- ### el_proxy_start_with_address Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Starts the Proxy with the specified network address. ```APIDOC ## el_proxy_start_with_address ### Description Start the Proxy with the specified address. ### Function Signature ```c int el_proxy_start_with_address(char *address); ``` ### Parameters #### Path Parameters - **address** (char *) - Required - The network address to start the proxy with. ### Return Value Returns 0 on success, a non-zero value on failure. ``` -------------------------------- ### elaphureLink TCP Server and CMSIS-DAP Example Source: https://github.com/windowsair/elaphurelink/blob/master/docs/server_providers_document.md This C code implements a basic elaphureLink service provider using a TCP server. It handles the handshake process and processes DAP commands. Ensure the product name of your DAP device contains 'CMSIS-DAP' and reserve a buffer larger than 1400 bytes. ```c #define BUF_SIZE 1500 uint8_t el_process_buffer[BUF_SIZE]; #define EL_LINK_IDENTIFIER 0x8a656c70 #define EL_DAP_VERSION 0x00000001 #define EL_COMMAND_HANDSHAKE 0x00000000 typedef struct { uint32_t el_link_identifier; uint32_t command; uint32_t el_proxy_version } el_request_handshake_t; typedef struct { uint32_t el_link_identifier; uint32_t command; uint32_t el_dap_version } el_response_handshake_t; int elaphureLink_handshake(int fd, void *buffer, size_t len) { // verify if (len != sizeof(el_request_handshake)) { return -1; } el_request_handshake_t* req = (el_request_handshake*)buffer; if (ntohl(req->el_link_identifier) != EL_LINK_IDENTIFIER) { return -1; } if (ntohl(req->command) != EL_COMMAND_HANDSHAKE) { return -1; } // send response el_response_handshake_t res; res.el_link_identifier = htonl(EL_LINK_IDENTIFIER); res.command = htonl(EL_COMMAND_HANDSHAKE); res.el_dap_version = htonl(EL_DAP_VERSION); send(fd, &res, sizeof(el_response_handshake_t), 0); return 0; } void elaphureLink_process(int fd, void *buffer, size_t len) { int length = DAP_ExecuteCommand(buffer, (uint8_t *)el_process_buffer); length &= 0xFFFF; // get response length send(fd, el_process_buffer, length, 0); } void tcp_server() { uint8_t buf[BUF_SIZE]; int socketfd; size_t length; int status = 0; do_bind(&socketfd); do_accept(&socketfd); for (;;) { length = recv(socketfd, buf, BUF_SIZE, 0); if (length <= 0) { break; } switch (status) { case 0: if (elaphureLink_handshake(socketfd, buf, length) != 0) { break; } status = 1; break; case 1: elaphureLink_process(socketfd, buf, length); } } close(socketfd); } ``` -------------------------------- ### Initialize Proxy Resources Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Call this function at the beginning to initialize proxy resources. Returns 0 on success, and a non-zero value on failure. ```c int el_proxy_init(); ``` -------------------------------- ### el_proxy_init Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Initializes proxy resources. This function must be called before any other elaphureLinkProxy functions. ```APIDOC ## el_proxy_init ### Description Initialize proxy resources, must call it at the beginning. ### Function Signature ```c int el_proxy_init(); ``` ### Return Value Returns 0 on success, a non-zero value on failure. ``` -------------------------------- ### Flash Program Sequence Diagram Source: https://github.com/windowsair/elaphurelink/blob/master/docs/vendor_command.md Illustrates the firmware download process using elaphureLink vendor commands. All operations occur within the elaphureLink vendor scope. ```mermaid sequenceDiagram participant Host as Host participant Target as Target Host->>Target: Enter vendor scope (0x2) Target-->>Host: Acknowledge Host->>Target: Load FlashOS algorithm (0x4) Target-->>Host: Acknowledge loop Erase sector Host->>Target: Erase sector (0x6) Target-->>Host: Acknowledge end loop Program Page Host->>Target: Program page (0x7) Target-->>Host: Acknowledge end Host->>Target: Exit vendor scope (0x3) Target-->>Host: Acknowledge ``` -------------------------------- ### el_proxy_set_on_connect_callback Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Sets a callback function to be executed when the Proxy connection is successfully established. ```APIDOC ## el_proxy_set_on_connect_callback ### Description Set the callback function to be used when the Proxy connection is successfully established. ### Function Signature ```c void el_proxy_set_on_connect_callback(onSocketConnectCallbackType callback); ``` ### Parameters #### Request Body - **callback** (onSocketConnectCallbackType) - Required - The callback function to be registered for connection establishment events. ``` -------------------------------- ### Prism.js GitHub Theme Styles Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_protocol.html CSS styles for the Prism.js syntax highlighter, mimicking the GitHub theme. Applied to code blocks and inline code elements. ```css code[class*="language-"], pre[class*="language-"] { color: #333; background: none; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; text-align: left; white-space: pre; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.4; -moz-tab-size: 8; -o-tab-size: 8; tab-size: 8; -webkit-hyphens: none; -moz-hyphens: none; -ms-hyphens: none; hyphens: none; } /* Code blocks */ pre[class*="language-"] { padding: .8em; overflow: auto; /* border: 1px solid #ddd; */ border-radius: 3px; /* background: #fff; */ background: #f5f5f5; } /* Inline code */ :not(pre) > code[class*="language-"] { padding: .1em; border-radius: .3em; white-space: normal; background: #f5f5f5; } .token.comment, .token.blockquote { color: #969896; } .token.cdata { color: #183691; } .token.doctype, .token.punctuation, .token.variable, .token.macro.property { color: #333; } .token.operator, .token.important, .token.keyword, .token.rule, .token.builtin { color: #a71d5d; } .token.string, .token.url, .token.regex, .token.attr-value { color: #183691; } .token.property, .token.number, .token.boolean, .token.entity, .token.atrule, .token.constant, .token.symbol, .token.command, .token.code { color: #0086b3; } .token.tag, .token.selector, .token.prolog { color: #63a35c; } .token.function, .token.namespace, .token.pseudo-element, .token.class, .token.class-name, .token.pseudo-class, .token.id, .token.url-reference .token.variable, .token.attr-name { color: #795da3; } .token.entity { cursor: help; } .token.title, .token.title .token.punctuation { font-weight: bold; color: #1d3e81; } .token.list { color: #ed6a43; } .token.inserted { background-color: #eaffea; color: #55a532; } .token.deleted { background-color: #ffecec; color: #bd2c00; } .token.bold { font-weight: bold; } .token.italic { font-style: italic; } /* JSON */ .language-json .token.property { color: #183691; } /* CSS */ code.language-css, .language-css .token.function { color: #0086b3; } /* YAML */ .language-yaml .token.atrule { color: #63a35c; } code.language-yaml { color: #183691; } /* Ruby */ .language-ruby .token.function { color: #333; } /* Markdown */ .language-markdown .token.url { color: #795da3; } /* Makefile */ .language-makefile .token.symbol { color: #795da3; } .language-makefile .token.variable { color: #183691; } .language-makefile .token.builtin { color: #0086b3; } /* Bash */ .language-bash .token.keyword { color: #0086b3; } /* highlight */ pre[data-line] { position: relative; padding: 1em 0 1em 3em; } pre[data-line] .line-highlight-wrapper { position: absolute; top: 0; left: 0; background-color: transparent; display: block; width: 100%; } pre[data-line] .line-highlight { position: absolute; left: 0; right: 0; padding: inherit 0; margin-top: 1em; background: hsla(24, 20%, 50%, .08); background: linear-gradient(to right, hsla(24, 20%, 50%, .1) 70%, hsla(24, 20%, 50%, 0)); pointer-events: none; line-height: inherit; white-space: pre; } pre[data-line] .line-highlight:before, pre[data-line] .line-highlight[data-end]:after { content: attr(data-start); position: absolute; top: .4em; left: .6em; min-width: 1em; padding: 0 .5em; background-color: hsla(24, 20%, 50%, .4); color: hsl(24, 20%, 95%); font: bold 65%/1.5 sans-serif; text-align: center; vertical-align: .3em; border-radius: 999px; text-shadow: none; box-shadow: 0 1px white; } pre[data-line] .line-highlight[data-end]:after { content: attr(data-end); top: auto; bottom: .4em; } ``` -------------------------------- ### BSD 2-Clause License Source: https://github.com/windowsair/elaphurelink/blob/master/License.md This is the standard BSD 2-Clause License text. It outlines the conditions for redistribution and use of the software, disclaiming warranties and limiting liability. ```plaintext Copyright (c) 2022, windowsair All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ``` -------------------------------- ### CMSIS-DAP Command Transfer Flow Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_protocol.md Illustrates the request-response flow for CMSIS-DAP commands between the elaphureLink proxy (client) and the DAP host (server). ```text elaphureLink Proxy DAP host "client" "server" (imports DAP device) (exports DAP device) | | | REQ_CMSIS_DAP_COMMAND | | ----------------------------------------------> | | | | RES_CMSIS_DAP_COMMAND | | <---------------------------------------------- | | . | | . | | . | | REQ_CMSIS_DAP_COMMAND | | ----------------------------------------------> | | | | RES_CMSIS_DAP_COMMAND | | <---------------------------------------------- | | | ``` -------------------------------- ### Capability Command Source: https://github.com/windowsair/elaphurelink/blob/master/docs/vendor_command.md The capability command is used to query the feature support status of elaphureLink vendor commands. It should be checked before requesting other commands. ```APIDOC ## Capability Command **Command Type** : `0x0` **Response Status** : - **%x0** denotes command successfully completed. - All other values are reserved for future use and MAY be considered as execution failure. ### Request Payload | Syntax | No. of bits | Mnemonic | | :---------------------------- | ----------- | -------- | | capability_request_payload() { | | | |  **capability_request_type_byte** | **8** | **bslbf** | | } | | | **capability_request_type_byte** ​ Indicates the type of request. `0x0` is for the capabilities of all commands. ### Response Payload | Syntax | No. of bits | Mnemonic | | :----------------------------- | ----------- | -------- | | capability_response_payload() { | | | |  **capability_response_type_byte** | **8** | **bslbf** | |  if (capability_response_type_byte == 0x0) { | | | |   **command_type_0x0_present** | **1** | **bslbf** | |   **command_type_0x1_present** | **1** | **bslbf** | |   **command_type_0x2_present** | **1** | **bslbf** | |   **command_type_0x3_present** | **1** | **bslbf** | |   **command_type_0x4_present** | **1** | **bslbf** | |   **command_type_0x5_present** | **1** | **bslbf** | |   **command_type_0x6_present** | **1** | **bslbf** | |   **command_type_0x7_present** | **1** | **bslbf** | |   **command_type_0x8_present** | **1** | **bslbf** | |   ... | | | |  } | | | | } | | | **command_type_0x_present** ​ The presence of each command is indicated by a bitmap. When a specific command type is present, the corresponding bit value is set to 1; otherwise, it is 0. ``` -------------------------------- ### Set Connection Success Callback Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Sets the callback function that will be invoked when the Proxy connection is successfully established. The callback receives a message string from the proxy. ```c void el_proxy_set_on_connect_callback(onSocketConnectCallbackType callback); ``` -------------------------------- ### elaphureLink Proxy Handshake Sequence Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_protocol.md Illustrates the handshake sequence between the elaphureLink proxy client and the DAP host server. This sequence establishes communication before data transfer. ```text elaphureLink Proxy DAP host "client" "server" (imports DAP device) (exports DAP device) | | | REQ_HANDSHAKE | | ----------------------------------------------> | | | | RES_HANDSHAKE | | <---------------------------------------------- | | | ``` -------------------------------- ### ElaphureLink Command Types Source: https://github.com/windowsair/elaphurelink/blob/master/docs/vendor_command.md Lists the defined command types for elaphureLink vendor commands. Command type 0x0 is required, while others are optional. ```markdown | Command Name | | ------------ | | el_capability | 0x0 | | el_native_command_passthrough | 0x1 | | el_vendor_scope_enter | 0x2 | | el_vendor_scope_exit | 0x3 | | el_flashos_load_algorithm | 0x4 | | el_flashos_execute_function | 0x5 | | el_flashos_erase_sector | 0x6 | | el_flashos_program_page | 0x7 | ``` -------------------------------- ### Callback Type for Connection Success Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Defines the type for a callback function that handles successful proxy connection events. It accepts a constant character pointer as a message. ```c typedef void (*onSocketConnectCallbackType)(const char* msg); ``` -------------------------------- ### Set Disconnection Callback Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Sets the callback function to be executed when the Proxy connection is disconnected. The callback receives a message string detailing the reason for disconnection. ```c void el_proxy_set_on_disconnect_callback(onSocketDisconnectCallbackType callback); ``` -------------------------------- ### Capability Response Payload Source: https://github.com/windowsair/elaphurelink/blob/master/docs/vendor_command.md Defines the syntax for a capability response payload. It includes a bitmap indicating the presence of different command types. ```markdown | Syntax | | :----------------------------- | | capability_response_payload() { | |  **capability_response_type_byte** | **8** | **bslbf** | |  if (capability_response_type_byte == 0x0) { | |   **command_type_0x0_present** | **1** | **bslbf** | |   **command_type_0x1_present** | **1** | **bslbf** | |   **command_type_0x2_present** | **1** | **bslbf** | |   **command_type_0x3_present** | **1** | **bslbf** | |   **command_type_0x4_present** | **1** | **bslbf** | |   **command_type_0x5_present** | **1** | **bslbf** | |   **command_type_0x6_present** | **1** | **bslbf** | |   **command_type_0x7_present** | **1** | **bslbf** | |   **command_type_0x8_present** | **1** | **bslbf** | |   ... | | | |  } | | | | } | | | ``` -------------------------------- ### Capability Request Payload Source: https://github.com/windowsair/elaphurelink/blob/master/docs/vendor_command.md Defines the syntax for a capability request payload. The capability_request_type_byte should be set to 0x0 to query all command capabilities. ```markdown | Syntax | | :---------------------------- | | capability_request_payload() { | |  **capability_request_type_byte** | **8** | **bslbf** | | } | ``` -------------------------------- ### el_proxy_set_on_disconnect_callback Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Sets a callback function to be executed when the Proxy connection is disconnected. ```APIDOC ## el_proxy_set_on_disconnect_callback ### Description Set the callback function to be used when the Proxy connection is disconnected. ### Function Signature ```c void el_proxy_set_on_disconnect_callback(onSocketDisconnectCallbackType callback); ``` ### Parameters #### Request Body - **callback** (onSocketDisconnectCallbackType) - Required - The callback function to be registered for disconnection events. ``` -------------------------------- ### ElaphureLink Vendor Command Response Packet Format Source: https://github.com/windowsair/elaphurelink/blob/master/docs/vendor_command.md Defines the structure of a response packet for elaphureLink vendor commands. This format includes fields for prefix, status, payload length, and payload data. ```text 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+----------------+------------------------------+ | Prefix | Status | Payload length | | (8) | (8) | (16) | | | | | +---------------+----------------+------------------------------+ | Payload Data | +---------------------------------------------------------------+ : Payload Data continued ... : +---------------------------------------------------------------+ | Payload Data continued ... | +---------------------------------------------------------------+ ``` -------------------------------- ### HTML Body Styles Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_protocol.html Default styling for HTML body elements, including typography, links, and basic layout. Ensures consistent presentation across different browsers. ```css html body { font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif; font-size: 16px; line-height: 1.6; color: #333; background-color: #fff; overflow: initial; box-sizing: border-box; word-wrap: break-word; } html body > :first-child { margin-top: 0; } html body h1, html body h2, html body h3, html body h4, html body h5, html body h6 { line-height: 1.2; margin-top: 1em; margin-bottom: 16px; color: #000; } html body h1 { font-size: 2.25em; font-weight: 300; padding-bottom: .3em; } html body h2 { font-size: 1.75em; font-weight: 400; padding-bottom: .3em; } html body h3 { font-size: 1.5em; font-weight: 500; } html body h4 { font-size: 1.25em; font-weight: 600; } html body h5 { font-size: 1.1em; font-weight: 600; } html body h6 { font-size: 1em; font-weight: 600; } html body h1, html body h2, html body h3, html body h4, html body h5 { font-weight: 600; } html body h5 { font-size: 1em; } html body h6 { color: #5c5c5c; } html body strong { color: #000; } html body del { color: #5c5c5c; } html body a:not([href]) { color: inherit; text-decoration: none; } html body a { color: #08c; text-decoration: none; } html body a:hover { color: #00a3f5; text-decoration: none; } html body img { max-width: 100%; } html body > p { margin-top: 0; margin-bottom: 16px; word-wrap: break-word; } html body > ul, html body > ol { margin-bottom: 16px; } html body ul, html body ol { padding-left: 2em; } html body ul.no-list, html body ol.no-list { padding: 0; list-style-type: none; } html body ul ul, html body ul ol ``` -------------------------------- ### ElaphureLink Vendor Command Request Packet Format Source: https://github.com/windowsair/elaphurelink/blob/master/docs/vendor_command.md Defines the structure of a request packet for elaphureLink vendor commands. This format includes fields for prefix, command type, extended command type, payload length, and payload data. ```text 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+----------------+------------------------------+ | Prefix | Command Type | Extended Command Type | | (8) | (8) | (16) | | | | (if command type > 127) | | | | | +---------------+----------------+------------------------------+ | Payload Length | Payload Data | | (16) | | | | | +--------------------------------+------------------------------+ : Payload Data continued ... : +---------------------------------------------------------------+ | Payload Data continued ... | +---------------------------------------------------------------+ ``` -------------------------------- ### Callback Type for Disconnection Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Defines the type for a callback function that handles proxy disconnection events. It accepts a constant character pointer as a message. ```c typedef void (*onSocketDisconnectCallbackType)(const char* msg); ``` -------------------------------- ### onSocketConnectCallbackType Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Defines the type for callback functions that handle successful proxy connection establishments. ```APIDOC ## onSocketConnectCallbackType ### Description Defines the type for callback functions that handle successful proxy connection establishments. ### Type Definition ```c typedef void (*onSocketConnectCallbackType)(const char* msg); ``` ### Parameters #### Request Body - **msg** (const char*) - A string message provided by the proxy to the callback function about the reason for the establishment. ``` -------------------------------- ### onSocketDisconnectCallbackType Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Defines the type for callback functions that handle proxy connection disconnections. ```APIDOC ## onSocketDisconnectCallbackType ### Description Defines the type for callback functions that handle proxy connection disconnections. ### Type Definition ```c typedef void (*onSocketDisconnectCallbackType)(const char* msg); ``` ### Parameters #### Request Body - **msg** (const char*) - A string message provided by the proxy to the callback function about the reason for the disconnection. ``` -------------------------------- ### el_proxy_stop Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Forces the Proxy to stop its operation. This function can be called at any time. ```APIDOC ## el_proxy_stop ### Description Force the Proxy to stop. This function can be used at any time. ### Function Signature ```c void el_proxy_stop(); ``` ``` -------------------------------- ### Stop Proxy Source: https://github.com/windowsair/elaphurelink/blob/master/docs/proxy_api.md Forces the Proxy service to stop. This function can be called at any time. ```c void el_proxy_stop(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.