1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-12-27 06:15:19 +00:00
sys-con/SwitchUSB/source/libnxFix.cpp
2019-10-31 21:00:42 +03:00

51 lines
1009 B
C++

#include "libnxFix.h"
#include <cstring>
#include <stdio.h>
#include "malloc.h"
static Result _usbHsCmdNoIO(Service *s, u64 cmd_id)
{
IpcCommand c;
ipcInitialize(&c);
struct Packet
{
u64 magic;
u64 cmd_id;
} * raw;
raw = static_cast<Packet *>(serviceIpcPrepareHeader(s, &c, sizeof(*raw)));
raw->magic = SFCI_MAGIC;
raw->cmd_id = cmd_id;
Result rc = serviceIpcDispatch(s);
if (R_SUCCEEDED(rc))
{
IpcParsedCommand r;
struct Reponse
{
u64 magic;
u64 result;
} * resp;
serviceIpcParse(s, &r, sizeof(*resp));
resp = static_cast<Reponse *>(r.Raw);
rc = resp->result;
}
return rc;
}
void usbHsEpCloseFixed(UsbHsClientEpSession *s)
{
if (!serviceIsActive(&s->s))
return;
_usbHsCmdNoIO(&s->s, hosversionAtLeast(2, 0, 0) ? 1 : 3); //Close
serviceClose(&s->s);
eventClose(&s->eventXfer);
memset(s, 0, sizeof(UsbHsClientEpSession));
}