summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-03-01 17:28:07 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-03-01 17:28:07 -0400
commit0d82cc507e0c49e2871f18a7f574b3071b51f4a1 (patch)
tree3ceb935b7387767da7324febc707165eb354d6b5
parent926f5f5ec7992651d2e0602f4fdb77f8be8a5ae5 (diff)
TTcpSocket: Match `open()`
I might do `test_connection()` next, if not, `TProtocol` will be next.
-rw-r--r--context.h54
-rw-r--r--src/pso/TTcpSocket.cpp114
2 files changed, 167 insertions, 1 deletions
diff --git a/context.h b/context.h
index d83ee43..2a3e8dc 100644
--- a/context.h
+++ b/context.h
@@ -484,8 +484,26 @@ u32 render_shadow_flags;
u32 old_render_shadow_flags;
u32 some_id_805c6f74;
-// THeap.cpp
+// TTcpSocket.cpp
// func defs.
+extern void func_80019aa0();
+extern void controller_stuff();
+extern char func_801a5d1c();
+extern void render_tick();
+extern void func_803d96a4();
+extern short tcp_abort(short nh);
+extern short tcp_bind(short nh, struct at_ip_addr *addr, u16 port);
+extern short tcp_connect(short nh, struct at_ip_addr *addr, u16 port, struct at_ip_option *option);
+extern short tcp_create();
+extern short tcp_delete(short nh);
+extern short tcp_get_opt(short nh, short type, u32 *opt);
+extern short tcp_send(short nh, void (*notify)(short size, short sock_fd), char bufnum, struct send_buffs *sb);
+extern short tcp_stat(short nh, short *stat, short *backlog, u32 *sendwin, u32 *recvwin);
+extern short tcp_receive(short nh, void (*notify)(short size, short sock_fd), short len, u8 *buf);
+extern int get_link_status();
+extern char *get_sock_status_name(short code);
+
+// THeap.cpp
extern void heap_xfree(void *ptr);
extern void *heap_xmalloc(size_t size);
@@ -519,6 +537,40 @@ struct packet_header {
void bswap();
} __packed__;
+// TTcpSocket.cpp, but they're really from AVE-TCP
+struct at_ip4_opt {
+ u8 ttl;
+ u8 svctype;
+ u8 df_flag;
+};
+
+struct at_ip6_opt {
+ u8 traffic_class;
+ u32 flow_label;
+ u8 hop_limit;
+};
+
+struct at_ip_option {
+ u32 type;
+ union {
+ struct at_ip6_opt ip6;
+ struct at_ip4_opt ip4;
+ } ip46;
+};
+
+struct at_ip_addr {
+ u32 type;
+ union {
+ u8 ip6[16];
+ u32 ip4;
+ } ip46;
+};
+
+struct send_buffs {
+ short len;
+ u8 *buff;
+};
+
// pso/TSocket.h
// Union defs.
union ipv4_addr {
diff --git a/src/pso/TTcpSocket.cpp b/src/pso/TTcpSocket.cpp
index 0317f37..e319b0e 100644
--- a/src/pso/TTcpSocket.cpp
+++ b/src/pso/TTcpSocket.cpp
@@ -3,6 +3,7 @@
#include <string.h>
#include "pso/macros.h"
#include "pso/TArray.h"
+#include "pso/TMainTask.h"
#include "pso/TObject.h"
#include "pso/TSocket.h"
#include "pso/TTcpSocket.h"
@@ -10,13 +11,50 @@
OBJECT_NAME(TTcpSocket);
TTcpSocket *tcp_socket_table[16] = {nullptr};
+struct at_ip4_opt {
+ u8 ttl;
+ u8 svctype;
+ u8 df_flag;
+};
+
+struct at_ip6_opt {
+ u8 traffic_class;
+ u32 flow_label;
+ u8 hop_limit;
+};
+
+struct at_ip_option {
+ u32 type;
+ union {
+ struct at_ip6_opt ip6;
+ struct at_ip4_opt ip4;
+ } ip46;
+};
+
+struct at_ip_addr {
+ u32 type;
+ union {
+ u8 ip6[16];
+ u32 ip4;
+ } ip46;
+};
+
struct send_buffs {
short len;
u8 *buff;
};
+void func_80019aa0();
+void controller_stuff();
+char func_801a5d1c();
+void render_tick();
+void func_803d96a4();
short tcp_abort(short nh);
+short tcp_bind(short nh, struct at_ip_addr *addr, u16 port);
+short tcp_connect(short nh, struct at_ip_addr *addr, u16 port, struct at_ip_option *option);
+short tcp_create();
short tcp_delete(short nh);
+short tcp_get_opt(short nh, short type, u32 *opt);
short tcp_send(short nh, void (*notify)(short size, short sock_fd), char bufnum, struct send_buffs *sb);
short tcp_stat(short nh, short *stat, short *backlog, u32 *sendwin, u32 *recvwin);
short tcp_receive(short nh, void (*notify)(short size, short sock_fd), short len, u8 *buf);
@@ -169,11 +207,87 @@ short TTcpSocket::close() {
}
short TTcpSocket::open() {
+ set_sock_fd(-1);
+ m_is_encrypted = 0;
+ set_size(0);
+ set_buffer_offset(0);
+ set_buffer_cleared(true);
+ set_unused(0);
+ set_sock_fd(tcp_create());
+
+ if (sock_fd() < 0) {
+ log(get_sock_status_name(sock_fd()));
+ return -1;
+ } else {
+ struct at_ip_option connect_option;
+ struct at_ip_addr connect_addr;
+ struct at_ip_addr bind_addr;
+
+ u32 opt = 1;
+
+ tcp_get_opt(sock_fd(), 0x2001, &opt);
+
+ bind_addr.type = 4;
+ bind_addr.ip46.ip4 = 0;
+ tcp_bind(sock_fd(), &bind_addr, src_port());
+
+ connect_addr.type = 4;
+ connect_addr.ip46.ip4 = dst_addr().addr;
+
+ connect_option.type = 4;
+ connect_option.ip46.ip4.ttl = 120;
+ connect_option.ip46.ip4.svctype = 0;
+ connect_option.ip46.ip4.df_flag = 0;
+
+ if (tcp_connect(sock_fd(), &connect_addr, dst_port(), &connect_option)) {
+ log(get_sock_status_name(sock_fd()));
+ return -1;
+ } else {
+ for (;;) {
+ func_803d96a4();
+ controller_stuff();
+ if (short status = stat()) {
+ log(get_sock_status_name(status));
+ return -2;
+ } else if (stat_val() < 0) {
+ return -2;
+ } else {
+ some_stub();
+ if (stat_val() < 4) {
+ if (!get_link_status()) {
+ return -3;
+ } else if (func_801a5d1c()) {
+ return -2;
+ } else {
+ main_task.some_empty_func();
+ main_task.run_tl_camera_tasks();
+ main_task.render();
+ main_task.render_screen_overlay();
+ func_80019aa0();
+ render_tick();
+ }
+ } else {
+ tcp_socket_table[sock_fd()] = this;
+ return sock_fd();
+ }
+ }
+ }
+ }
+ }
}
+void func_80019aa0() {}
+void controller_stuff() {}
+char func_801a5d1c() {}
+void render_tick() {}
+void func_803d96a4() {}
short tcp_abort(short nh) {}
+short tcp_bind(short nh, struct at_ip_addr *addr, u16 port) {}
+short tcp_connect(short nh, struct at_ip_addr *addr, u16 port, struct at_ip_option *option) {}
+short tcp_create() {}
short tcp_delete(short nh) {}
+short tcp_get_opt(short nh, short type, u32 *opt) {}
short tcp_send(short nh, void (*notify)(short size, short sock_fd), char bufnum, struct send_buffs *sb) {}
short tcp_stat(short nh, short *stat, short *backlog, u32 *sendwin, u32 *recvwin) {}
short tcp_receive(short nh, void (*notify)(short size, short sock_fd), short len, u8 *buf) {}