Skip to content

Commit 1e982ee

Browse files
committed
Initial import
0 parents  commit 1e982ee

File tree

7 files changed

+370
-0
lines changed

7 files changed

+370
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
*.elf
3+
*.velf
4+
*.o
5+
*.a

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
DEBUGNET FOR VITA
2+
=================
3+
4+
===================
5+
What does this do?
6+
===================
7+
8+
debugnet is a psp2 small library to depure your homebrew code over udp. It is the same method that i use to depure PlayStation 3 code, so i can use the same host tools for PlayStation Vita and PlayStation 3 to do it.
9+
10+
==================
11+
How do I use it?
12+
==================
13+
14+
1) Compile and install library and include file
15+
16+
You need a psp2 toolchain installed in your environment and PSP2SDK must be defined
17+
18+
cd libdebugnet
19+
make
20+
make install
21+
22+
2) Compile sample
23+
24+
cd sample
25+
edit main.c and change your server ip and port to listen udp messages from PlayStation Vita
26+
make
27+
28+
29+
3) Open a terminal and execute (change port if you don't use 18194). It can be in osx, linux or if you have socat like tool on windows
30+
31+
32+
socat udp-recv:18194 stdout
33+
34+
35+
4) Execute sample with rejuvenate
36+
37+
You will see in socat terminal window output from your PlayStation Vita:
38+
39+
debugnet initialized
40+
Copyright (C) 2010,2015 Antonio Jose Ramos Marquez aka bigboss @psxdev
41+
This Program is subject to the terms of the Mozilla Public
42+
License, v. 2.0. If a copy of the MPL was not distributed with this
43+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
44+
ready to have a lot of fun...
45+
[DEBUG]: Test debug level 1
46+
[ERROR]: Test error level 1
47+
[INFO]: Test info level 1
48+
49+
5) ready to have a lot of fun :P
50+
51+
===========================
52+
Credits
53+
===========================
54+
55+
Special thanks goes to:
56+
57+
- yifanlu to open the doors with rejuvenete. We need PlayStation VitaTV suppport and other cool things so i wait you come back.
58+
- All people collaborating in #PSP2SDK: @17310, @xerpi(i stole you network initialization code :P from FTPVita), @frangar , @frtomtomdu80, @hykemthedemon , @SMOKE587, @Josh_Axey ...
59+
- All ps3dev and ps2dev old comrades
60+

libdebugnet/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
TARGET_LIB = libdebugnet.a
2+
OBJS = source/debugnet.o
3+
INCLUDES = include
4+
PREFIX = arm-none-eabi
5+
CC = $(PREFIX)-gcc
6+
AR = $(PREFIX)-ar
7+
CFLAGS = -O2 -Wall -specs=psp2.specs -I$(INCLUDES)
8+
ASFLAGS = $(CFLAGS)
9+
10+
all: $(TARGET_LIB)
11+
12+
13+
$(TARGET_LIB): $(OBJS)
14+
$(AR) -rc $@ $^
15+
16+
clean:
17+
@rm -rf $(TARGET_LIB) $(OBJS)
18+
19+
install: $(TARGET_LIB)
20+
@cp $(TARGET_LIB) $(PSP2SDK)/lib
21+
@cp include/debugnet.h $(PSP2SDK)/include
22+
@echo "Installed!"

libdebugnet/include/debugnet.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* debugnet library for PSP2
3+
* Copyright (C) 2010,2015 Antonio Jose Ramos Marquez (aka bigboss) @psxdev on twitter
4+
* Repository https://github.com/psxdev/debugnet
5+
*/
6+
#ifndef _DEBUGNET_H_
7+
#define _DEBUGNET_H_
8+
9+
#define NET_INIT_SIZE 1*1024*1024
10+
11+
#define NONE 0
12+
#define INFO 1
13+
#define ERROR 2
14+
#define DEBUG 3
15+
16+
17+
18+
int debugNetInit(char *serverIp, int port, int level);
19+
void debugNetFinish();
20+
void debugNetPrintf(int level, char* format, ...);
21+
void debugNetSetLogLevel(int level);
22+
23+
24+
25+
#endif

libdebugnet/source/debugnet.c

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/*
2+
* debugnet library for PSP2
3+
* Copyright (C) 2010,2015 Antonio Jose Ramos Marquez (aka bigboss) @psxdev on twitter
4+
* Repository https://github.com/psxdev/debugnet
5+
*/
6+
7+
#include <stdio.h>
8+
#include <stdarg.h>
9+
#include <stdlib.h>
10+
#include <string.h>
11+
#include <psp2/net/net.h>
12+
#include <psp2/net/netctl.h>
13+
#include <psp2/types.h>
14+
#include "debugnet.h"
15+
16+
17+
18+
19+
static int debugnet_initialized=0;
20+
int SocketFD = -1;
21+
static void *net_memory = NULL;
22+
static SceNetInAddr vita_addr;
23+
int sceClibVsnprintf(char *, SceSize, const char *, va_list);
24+
int logLevel=INFO;
25+
26+
/**
27+
* UDP printf for debugnet library
28+
*
29+
* @par Example:
30+
* @code
31+
* debugNetUDPPrintf("This is a test\n");
32+
* @endcode
33+
*/
34+
void debugNetUDPPrintf(const char* fmt, ...)
35+
{
36+
char buffer[0x800];
37+
va_list arg;
38+
va_start(arg, fmt);
39+
sceClibVsnprintf(buffer, sizeof(buffer), fmt, arg);
40+
va_end(arg);
41+
sceNetSend(SocketFD, buffer, strlen(buffer), 0);
42+
}
43+
/**
44+
* Log Level printf for debugnet library
45+
*
46+
* @par Example:
47+
* @code
48+
* debugNetPrintf(INFO,"This is a test\n");
49+
* @endcode
50+
*
51+
* @param level - NONE,INFO,ERROR or DEBUG
52+
*/
53+
void debugNetPrintf(int level, char* format, ...)
54+
{
55+
char msgbuf[0x800];
56+
va_list args;
57+
58+
if (level>logLevel)
59+
return;
60+
61+
va_start(args, format);
62+
63+
sceClibVsnprintf(msgbuf,2048, format, args);
64+
msgbuf[2047] = 0;
65+
va_end(args);
66+
switch(level)
67+
{
68+
case INFO:
69+
debugNetUDPPrintf("[INFO]: %s",msgbuf);
70+
break;
71+
case ERROR:
72+
debugNetUDPPrintf("[ERROR]: %s",msgbuf);
73+
break;
74+
case DEBUG:
75+
debugNetUDPPrintf("[DEBUG]: %s",msgbuf);
76+
break;
77+
case NONE:
78+
break;
79+
default:
80+
debugNetUDPPrintf("%s",msgbuf);
81+
82+
}
83+
}
84+
/**
85+
* Set log level for debugnet library
86+
*
87+
* @par Example:
88+
* @code
89+
* debugNetSetLogLevel(DEBUG);
90+
* @endcode
91+
* @param level - DEBUG,ERROR,INFO or NONE
92+
*/
93+
void debugNetSetLogLevel(int level)
94+
{
95+
logLevel=level;
96+
}
97+
/**
98+
* Init debugnet library
99+
*
100+
* @par Example:
101+
* @code
102+
* #define LOGLEVEL 3
103+
* int ret;
104+
* ret = debugNetInit("172.26.0.2", 18194, DEBUG);
105+
* @endcode
106+
*
107+
* @param serverIP - your pc/mac server ip
108+
* @param port - udp port server
109+
* @param level - DEBUG,ERROR,INFO or NONE
110+
*/
111+
int debugNetInit(char *serverIp, int port, int level)
112+
{
113+
int ret;
114+
SceNetInitParam initparam;
115+
SceNetCtlInfo info;
116+
struct SceNetSockaddrIn stSockAddr;
117+
debugNetSetLogLevel(level);
118+
if (debugnet_initialized) {
119+
return debugnet_initialized;
120+
}
121+
/*net initialazation code from xerpi at https://github.com/xerpi/FTPVita/blob/master/ftp.c*/
122+
/* Init Net */
123+
if (sceNetShowNetstat() == PSP2_NET_ERROR_ENOTINIT) {
124+
net_memory = malloc(NET_INIT_SIZE);
125+
126+
initparam.memory = net_memory;
127+
initparam.size = NET_INIT_SIZE;
128+
initparam.flags = 0;
129+
130+
ret = sceNetInit(&initparam);
131+
//printf("sceNetInit(): 0x%08X\n", ret);
132+
} else {
133+
//printf("Net is already initialized.\n");
134+
}
135+
136+
/* Init NetCtl */
137+
ret = sceNetCtlInit();
138+
//printf("sceNetCtlInit(): 0x%08X\n", ret);
139+
140+
141+
/* Get IP address */
142+
ret = sceNetCtlInetGetInfo(PSP2_NETCTL_INFO_GET_IP_ADDRESS, &info);
143+
//printf("sceNetCtlInetGetInfo(): 0x%08X\n", ret);
144+
145+
146+
/* Save the IP of PSVita to a global variable */
147+
sceNetInetPton(PSP2_NET_AF_INET, info.ip_address, &vita_addr);
148+
149+
/* Create datagram udp socket*/
150+
SocketFD = sceNetSocket("debugnet_socket",
151+
PSP2_NET_AF_INET , PSP2_NET_SOCK_DGRAM, PSP2_NET_IPPROTO_UDP);
152+
153+
memset(&stSockAddr, 0, sizeof stSockAddr);
154+
155+
/*Populate SceNetSockaddrIn structure values*/
156+
stSockAddr.sin_family = PSP2_NET_AF_INET;
157+
stSockAddr.sin_port = sceNetHtons(port);
158+
sceNetInetPton(PSP2_NET_AF_INET, serverIp, &stSockAddr.sin_addr);
159+
160+
/*Connect socket to server*/
161+
sceNetConnect(SocketFD, (struct SceNetSockaddr *)&stSockAddr, sizeof stSockAddr);
162+
163+
/*Show log on pc/mac side*/
164+
debugNetUDPPrintf("debugnet initialized\n");
165+
debugNetUDPPrintf("Copyright (C) 2010,2015 Antonio Jose Ramos Marquez aka bigboss @psxdev\n");
166+
debugNetUDPPrintf("This Program is subject to the terms of the Mozilla Public\n"
167+
"License, v. 2.0. If a copy of the MPL was not distributed with this\n"
168+
"file, You can obtain one at http://mozilla.org/MPL/2.0/.\n");
169+
debugNetUDPPrintf("ready to have a lot of fun...\n");
170+
171+
/*library debugnet initialized*/
172+
debugnet_initialized = 1;
173+
174+
return debugnet_initialized;
175+
}
176+
177+
/**
178+
* Finish debugnet library
179+
*
180+
* @par Example:
181+
* @code
182+
* debugNetFinish();
183+
* @endcode
184+
*/
185+
void debugNetFinish()
186+
{
187+
if (debugnet_initialized) {
188+
189+
sceNetCtlTerm();
190+
sceNetTerm();
191+
192+
if (net_memory) {
193+
free(net_memory);
194+
net_memory = NULL;
195+
}
196+
197+
debugnet_initialized = 0;
198+
}
199+
}

sample/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Copyright (c) 2015 Antonio Jose Ramos Marquez aka bigboss (@psxdev)
3+
#
4+
5+
6+
7+
8+
9+
TARGET := debugnetsample
10+
11+
OBJS= main.o
12+
13+
LIBS=-lSceNet_stub -lSceNetCtl_stub -ldebugnet
14+
15+
PREFIX = arm-none-eabi
16+
AS = $(PREFIX)-as
17+
CC = $(PREFIX)-gcc
18+
CXX = $(PREFIX)-g++
19+
READELF = $(PREFIX)-readelf
20+
OBJDUMP = $(PREFIX)-objdump
21+
CFLAGS = -O2 -Wall -specs=psp2.specs $(DEFINES) $(INCDIR) -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -ffunction-sections
22+
CXXFLAGS = $(CFLAGS) -fno-unwind-tables -fno-rtti -fno-exceptions -Wno-deprecated -Wno-comment -Wno-sequence-point
23+
ASFLAGS = $(CFLAGS) --gc-sections
24+
25+
all: $(TARGET).velf
26+
27+
$(TARGET).velf: $(TARGET).elf
28+
psp2-fixup -q -S $< $@
29+
30+
$(TARGET).elf: $(OBJS)
31+
$(CC) $^ -o $@ $(CFLAGS) $(LIBS)
32+
33+
clean:
34+
@rm -rf $(TARGET).elf $(TARGET).velf $(OBJS) $(DATA)/*.h
35+

sample/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* debugnet library sample for PSP2
3+
* Copyright (C) 2010,2015 Antonio Jose Ramos Marquez (aka bigboss) @psxdev on twitter
4+
* Repository https://github.com/psxdev/debugnet
5+
*/
6+
#include <psp2/moduleinfo.h>
7+
#include <debugnet.h>
8+
9+
10+
PSP2_MODULE_INFO(0, 0, "debugnetSample");
11+
12+
#define ip_server "172.26.1.15"
13+
#define port_server 18194
14+
int main()
15+
{
16+
int ret;
17+
ret=debugNetInit(ip_server,port_server,DEBUG);
18+
debugNetPrintf(DEBUG,"Test debug level %d\n",ret);
19+
debugNetPrintf(ERROR,"Test error level %d\n",ret);
20+
debugNetPrintf(INFO,"Test info level %d\n",ret);
21+
debugNetFinish();
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)