summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/ac/ac.cpp
blob: aa270a2c3b4c16c318bc3e8f963d42197b5c3c3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright 2016 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <array>

#include "common/logging/log.h"
#include "core/hle/kernel/event.h"
#include "core/hle/service/ac/ac.h"
#include "core/hle/service/ac/ac_i.h"
#include "core/hle/service/ac/ac_u.h"

namespace Service {
namespace AC {

struct ACConfig {
    std::array<u8, 0x200> data;
};

static ACConfig default_config{};

static bool ac_connected = false;

static Kernel::SharedPtr<Kernel::Event> close_event;
static Kernel::SharedPtr<Kernel::Event> connect_event;
static Kernel::SharedPtr<Kernel::Event> disconnect_event;

void CreateDefaultConfig(Interface* self) {
    u32* cmd_buff = Kernel::GetCommandBuffer();

    u32 ac_config_addr = cmd_buff[65];

    ASSERT_MSG(cmd_buff[64] == (sizeof(ACConfig) << 14 | 2),
               "Output buffer size not equal ACConfig size");

    Memory::WriteBlock(ac_config_addr, &default_config, sizeof(ACConfig));
    cmd_buff[1] = RESULT_SUCCESS.raw; // No error

    LOG_WARNING(Service_AC, "(STUBBED) called");
}

void ConnectAsync(Interface* self) {
    u32* cmd_buff = Kernel::GetCommandBuffer();

    connect_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]);
    if (connect_event) {
        connect_event->name = "AC:connect_event";
        connect_event->Signal();
        ac_connected = true;
    }
    cmd_buff[1] = RESULT_SUCCESS.raw; // No error

    LOG_WARNING(Service_AC, "(STUBBED) called");
}

void GetConnectResult(Interface* self) {
    u32* cmd_buff = Kernel::GetCommandBuffer();

    cmd_buff[1] = RESULT_SUCCESS.raw; // No error

    LOG_WARNING(Service_AC, "(STUBBED) called");
}

void CloseAsync(Interface* self) {
    u32* cmd_buff = Kernel::GetCommandBuffer();

    if (ac_connected && disconnect_event) {
        disconnect_event->Signal();
    }

    close_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]);
    if (close_event) {
        close_event->name = "AC:close_event";
        close_event->Signal();
    }

    ac_connected = false;

    cmd_buff[1] = RESULT_SUCCESS.raw; // No error
    LOG_WARNING(Service_AC, "(STUBBED) called");
}

void GetCloseResult(Interface* self) {
    u32* cmd_buff = Kernel::GetCommandBuffer();

    cmd_buff[1] = RESULT_SUCCESS.raw; // No error

    LOG_WARNING(Service_AC, "(STUBBED) called");
}

void GetWifiStatus(Interface* self) {
    u32* cmd_buff = Kernel::GetCommandBuffer();

    // TODO(purpasmart96): This function is only a stub,
    // it returns a valid result without implementing full functionality.

    cmd_buff[1] = RESULT_SUCCESS.raw; // No error
    cmd_buff[2] = 0;                  // Connection type set to none

    LOG_WARNING(Service_AC, "(STUBBED) called");
}

void GetInfraPriority(Interface* self) {
    u32* cmd_buff = Kernel::GetCommandBuffer();

    cmd_buff[1] = RESULT_SUCCESS.raw; // No error
    cmd_buff[2] = 0;                  // Infra Priority, default 0

    LOG_WARNING(Service_AC, "(STUBBED) called");
}

void SetRequestEulaVersion(Interface* self) {
    u32* cmd_buff = Kernel::GetCommandBuffer();

    u32 major = cmd_buff[1] & 0xFF;
    u32 minor = cmd_buff[2] & 0xFF;

    ASSERT_MSG(cmd_buff[3] == (sizeof(ACConfig) << 14 | 2),
               "Input buffer size not equal ACConfig size");
    ASSERT_MSG(cmd_buff[64] == (sizeof(ACConfig) << 14 | 2),
               "Output buffer size not equal ACConfig size");

    cmd_buff[1] = RESULT_SUCCESS.raw; // No error
    cmd_buff[2] = 0;                  // Infra Priority

    LOG_WARNING(Service_AC, "(STUBBED) called, major=%u, minor=%u", major, minor);
}

void RegisterDisconnectEvent(Interface* self) {
    u32* cmd_buff = Kernel::GetCommandBuffer();

    disconnect_event = Kernel::g_handle_table.Get<Kernel::Event>(cmd_buff[4]);
    if (disconnect_event) {
        disconnect_event->name = "AC:disconnect_event";
    }
    cmd_buff[1] = RESULT_SUCCESS.raw; // No error

    LOG_WARNING(Service_AC, "(STUBBED) called");
}

void IsConnected(Interface* self) {
    u32* cmd_buff = Kernel::GetCommandBuffer();

    cmd_buff[1] = RESULT_SUCCESS.raw; // No error
    cmd_buff[2] = ac_connected;

    LOG_WARNING(Service_AC, "(STUBBED) called");
}

void SetClientVersion(Interface* self) {
    u32* cmd_buff = Kernel::GetCommandBuffer();

    const u32 version = cmd_buff[1];
    self->SetVersion(version);

    LOG_WARNING(Service_AC, "(STUBBED) called, version: 0x%08X", version);

    cmd_buff[1] = RESULT_SUCCESS.raw; // No error
}

void Init() {
    AddService(new AC_I);
    AddService(new AC_U);

    ac_connected = false;

    close_event = nullptr;
    connect_event = nullptr;
    disconnect_event = nullptr;
}

void Shutdown() {
    ac_connected = false;

    close_event = nullptr;
    connect_event = nullptr;
    disconnect_event = nullptr;
}

} // namespace AC
} // namespace Service