-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f9f0eb
commit 40778a7
Showing
7 changed files
with
203 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set(COMPONENT_ADD_INCLUDEDIRS ".") | ||
set(COMPONENT_SRCS "./elaphureLink_protocol.c") | ||
|
||
register_component() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "components/elaphureLink/elaphureLink_protocol.h" | ||
|
||
|
||
#include "lwip/err.h" | ||
#include "lwip/sockets.h" | ||
#include "lwip/sys.h" | ||
#include <lwip/netdb.h> | ||
|
||
extern int kSock; | ||
extern int usbip_network_send(int s, const void *dataptr, size_t size, int flags); | ||
|
||
extern void malloc_dap_ringbuf(); | ||
extern void free_dap_ringbuf(); | ||
|
||
extern uint32_t DAP_ExecuteCommand(const uint8_t *request, uint8_t *response); | ||
|
||
uint8_t* el_process_buffer = NULL; | ||
|
||
void el_process_buffer_malloc() { | ||
if (el_process_buffer != NULL) | ||
return; | ||
|
||
free_dap_ringbuf(); | ||
|
||
el_process_buffer = malloc(1500); | ||
} | ||
|
||
|
||
void el_process_buffer_free() { | ||
if (el_process_buffer != NULL) { | ||
free(el_process_buffer); | ||
el_process_buffer = NULL; | ||
} | ||
} | ||
|
||
|
||
int el_handshake_process(int fd, void *buffer, size_t len) { | ||
if (len != sizeof(el_request_handshake)) { | ||
return -1; | ||
} | ||
|
||
el_request_handshake* 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; | ||
} | ||
|
||
el_response_handshake res; | ||
res.el_link_identifier = htonl(EL_LINK_IDENTIFIER); | ||
res.command = htonl(EL_COMMAND_HANDSHAKE); | ||
res.el_dap_version = htonl(EL_DAP_VERSION); | ||
|
||
usbip_network_send(fd, &res, sizeof(el_response_handshake), 0); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
void el_dap_data_process(void* buffer, size_t len) { | ||
int res = DAP_ExecuteCommand(buffer, (uint8_t *)el_process_buffer); | ||
res &= 0xFFFF; | ||
|
||
usbip_network_send(kSock, el_process_buffer, res, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#ifndef __ELAPHURELINK_PROTOCOL_H__ | ||
#define __ELAPHURELINK_PROTOCOL_H__ | ||
|
||
#include <stdint.h> | ||
#include <stddef.h> | ||
|
||
#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 | ||
} __attribute__((packed)) el_request_handshake; | ||
|
||
|
||
typedef struct | ||
{ | ||
uint32_t el_link_identifier; | ||
uint32_t command; | ||
uint32_t el_dap_version | ||
} __attribute__((packed)) el_response_handshake; | ||
|
||
|
||
/** | ||
* @brief elahpureLink Proxy handshake phase process | ||
* | ||
* @param fd socket fd | ||
* @param buffer packet buffer | ||
* @param len packet length | ||
* @return 0 on Success, other on failed. | ||
*/ | ||
int el_handshake_process(int fd, void* buffer, size_t len); | ||
|
||
|
||
/** | ||
* @brief Process dap data and send to socket | ||
* | ||
* @param buffer dap data buffer | ||
* @param len dap data length | ||
*/ | ||
void el_dap_data_process(void* buffer, size_t len); | ||
|
||
|
||
void el_process_buffer_malloc(); | ||
void el_process_buffer_free(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters