12#include "irx_imports.h"
22#include <sys/statvfs.h>
27typedef intptr_t siptr;
31typedef uintptr_t uiptr;
32#define iomanX_rename(old, new) rename(old, new)
33#define iomanX_sync(...) 0
39 unsigned char ctime[8];
40 unsigned char atime[8];
41 unsigned char mtime[8];
43 unsigned int private_0;
44 unsigned int private_1;
45 unsigned int private_2;
46 unsigned int private_3;
47 unsigned int private_4;
48 unsigned int private_5;
61IRX_ID(
"NET_configuration", 2, 30);
83static void do_init_xor_magic(
const char *in_id_buf);
84static int magic_shift_write_netcnf_2(
int inshft,
int buflen);
85static int magic_shift_read_netcnf_2(
int inshft,
int buflen);
86static int magic_shift_write_netcnf_1(
int inshft,
int buflen);
87static int magic_shift_read_netcnf_1(
int inshft,
int buflen);
88static int do_check_capacity_inner(
const char *fpath);
89static int do_get_count_list_inner(
const char *fname,
int type,
sceNetCnfList_t *p);
90static int do_load_entry_inner(
const char *fname,
int type,
const char *usr_name,
sceNetCnfEnv_t *e);
91static int do_add_entry_inner(
96 const char *icon_value,
97 const char *iconsys_value,
98 int no_check_capacity);
99static int do_edit_entry_inner(
102 const char *usr_name,
103 const char *new_usr_name,
105 const char *icon_value,
106 const char *iconsys_value,
107 int no_check_capacity);
108static int do_delete_entry_inner(
111 const char *usr_name,
112 const char *icon_value,
113 const char *iconsys_value,
114 int no_check_capacity);
115static int do_set_latest_entry_inner(
const char *fname,
int type,
const char *usr_name);
116static int do_delete_all_inner(
const char *dev);
117static int do_check_special_provider_inner(
const char *fname,
int type,
const char *usr_name,
sceNetCnfEnv_t *e);
118static char *do_alloc_mem_inner(
sceNetCnfEnv_t *e,
unsigned int size,
int align);
124static void do_address_to_string_inner(
char *dst,
unsigned int srcint);
125static int do_name_2_address_inner(
unsigned int *dst,
const char *buf);
126static int do_conv_a2s_inner(
char *sp_,
char *dp_,
int len);
127static int do_conv_s2a_inner(
char *sp_,
char *dp_,
int len);
128static int do_read_check_netcnf(
const char *netcnf_path,
int type,
int no_check_magic,
int no_decode);
129static int do_check_provider_inner(
const sceNetCnfEnv_t *e,
int type);
130static const char *do_handle_netcnf_dirname(
const char *fpath,
const char *entry_buffer,
char *netcnf_file_path);
131static int do_open_netcnf(
const char *netcnf_path,
int file_flags,
int file_mode);
132static int do_readfile_netcnf(
int fd,
void *ptr,
int size);
133static int do_write_netcnf_no_encode(
int fd,
void *ptr,
int size);
134static int do_dopen_wrap(
const char *fn);
136static int do_remove_wrap(
const char *fn);
137static void do_close_netcnf(
int fd);
138static void do_dclose_wrap(
int fd);
139static int do_filesize_netcnf(
int fd);
140static void do_getstat_wrap(
const char *fn,
iox_stat_t *stx);
141static void do_chstat_mode_copyprotect_wrap(
const char *fn);
144static int do_init_heap(
void);
146static void *do_alloc_heapmem(
int nbytes);
147static void do_free_heapmem(
void *ptr);
149static void do_delete_heap(
void);
156static int g_no_check_capacity;
158static int g_no_check_provider;
160static u32 g_id_result;
162static char *g_count_list_heapptr;
164static char *g_load_entry_heapptr;
166static char *g_add_entry_heapptr;
168static char *g_edit_entry_heapptr;
170static char *g_delete_entry_heapptr;
172static char *g_set_latest_entry_heapptr;
174static char *g_check_special_provider_heapptr;
176 {112, 12,
"chat_additional"},
177 {52, 16,
"redial_count"},
178 {52, 20,
"redial_interval"},
179 {112, 24,
"outside_number"},
180 {112, 28,
"outside_delay"},
181 {68, 32,
"dialing_type"},
187 {112, 12,
"location"},
189 {112, 20,
"dhcp_host_name"},
190 {98, 24,
"dhcp_host_name_null_terminated"},
191 {98, 25,
"dhcp_release_on_stop"},
192 {112, 28,
"address"},
193 {112, 32,
"netmask"},
194 {112, 36,
"chat_additional"},
195 {52, 40,
"redial_count"},
196 {52, 44,
"redial_interval"},
197 {112, 48,
"outside_number"},
198 {112, 52,
"outside_delay"},
199 {98, 96,
"answer_mode"},
200 {52, 100,
"answer_timeout"},
201 {68, 104,
"dialing_type"},
202 {112, 108,
"chat_login"},
203 {112, 112,
"auth_name"},
204 {112, 116,
"auth_key"},
205 {112, 120,
"peer_name"},
206 {112, 124,
"peer_key"},
207 {52, 128,
"lcp_timeout"},
208 {52, 132,
"ipcp_timeout"},
209 {52, 136,
"idle_timeout"},
210 {52, 140,
"connect_timeout"},
211 {98, 144,
"want.mru_nego"},
212 {98, 145,
"want.accm_nego"},
213 {98, 146,
"want.magic_nego"},
214 {98, 147,
"want.prc_nego"},
215 {98, 148,
"want.acc_nego"},
216 {98, 149,
"want.address_nego"},
217 {98, 150,
"want.vjcomp_nego"},
218 {98, 151,
"want.dns1_nego"},
219 {98, 152,
"want.dns2_nego"},
220 {77, 160,
"want.mru"},
221 {67, 164,
"want.accm"},
222 {65, 168,
"want.auth"},
223 {112, 172,
"want.ip_address"},
224 {112, 176,
"want.ip_mask"},
225 {112, 180,
"want.dns1"},
226 {112, 184,
"want.dns2"},
227 {98, 220,
"allow.mru_nego"},
228 {98, 221,
"allow.accm_nego"},
229 {98, 222,
"allow.magic_nego"},
230 {98, 223,
"allow.prc_nego"},
231 {98, 224,
"allow.acc_nego"},
232 {98, 225,
"allow.address_nego"},
233 {98, 226,
"allow.vjcomp_nego"},
234 {98, 227,
"allow.dns1_nego"},
235 {98, 228,
"allow.dns2_nego"},
236 {77, 236,
"allow.mru"},
237 {67, 240,
"allow.accm"},
238 {65, 244,
"allow.auth"},
239 {112, 248,
"allow.ip_address"},
240 {112, 252,
"allow.ip_mask"},
241 {112, 256,
"allow.dns1"},
242 {112, 260,
"allow.dns2"},
243 {76, 296,
"log_flags"},
244 {99, 300,
"force_chap_type"},
245 {98, 301,
"omit_empty_frame"},
246 {80, 332,
"phy_config"},
248 {98, 303,
"pppoe_host_uniq_auto"},
249 {112, 308,
"pppoe_service_name"},
250 {112, 312,
"pppoe_ac_name"},
252 {49, 324,
"auth_timeout"},
253 {49, 321,
"lcp_max_terminate"},
254 {49, 323,
"ipcp_max_terminate"},
255 {49, 320,
"lcp_max_configure"},
256 {49, 322,
"ipcp_max_configure"},
257 {49, 325,
"auth_max_failure"},
260 {112, 12,
"chat_init"}, {112, 16,
"chat_dial"}, {112, 20,
"chat_answer"}, {112, 24,
"redial_string"}, {0, 0, NULL}};
261static int g_callbacks_set;
264static void *g_netcnf_heap;
267static char g_icon_value[0x100];
268static char g_iconsys_value[0x100];
269static char g_id_xorbuf[24];
270static char g_id_buffer[8];
271static char g_ifc_buffer[0x3e8];
272static char g_arg_fname[0x400];
273static char g_entry_buffer[0x400];
274static char g_netcnf_file_path[0x100];
275static char g_dir_name[0x100];
276static char g_combination_buf1[0x100];
277static char g_combination_buf2[0x100];
278static char *g_read_check_netcnf_heapptr;
281static int g_open_callback_handle_count;
283static int get_check_provider_eq_zero(
void)
285 return !g_no_check_provider;
289static void do_print_usage(
void)
291 printf(
"Usage: netcnf [<option>] icon=<icon-path> iconsys=<iconsys-path>\n");
292 printf(
" <option>:\n");
293 printf(
" -no_check_capacity do not check capacity\n");
294 printf(
" -no_check_provider do not check special provider\n");
297static int do_module_load(
int ac,
char *av[],
void *startaddr,
ModuleInfo_t *mi)
308 return MODULE_NO_RESIDENT_END;
311 semaparam.attr = SA_THPRI;
312 semaparam.initial = 1;
314 semaparam.option = 0;
315 semid = CreateSema(&semaparam);
319 printf(
"netcnf: CreateSema (%d)\n", semid);
320 return MODULE_NO_RESIDENT_END;
323 g_iconsys_value[0] = 0;
324 for ( i = 1; i < ac; i += 1 )
326 if ( !strncmp(
"icon=", av[i], 5) )
328 strcpy(g_icon_value, av[i] + 5);
330 else if ( !strncmp(
"iconsys=", av[i], 8) )
332 strcpy(g_iconsys_value, av[i] + 8);
334 else if ( !strcmp(
"-no_check_capacity", av[i]) )
336 g_no_check_capacity = 1;
338 else if ( !strcmp(
"-no_check_provider", av[i]) )
340 g_no_check_provider = 1;
348 if ( !g_icon_value[0] || !g_iconsys_value[0] )
356 heap_inited = do_init_heap();
357 if ( heap_inited < 0 )
359 printf(
"netcnf: init_heap(%d)\n", heap_inited);
365 regres = RegisterLibraryEntries(&_exp_netcnf);
369 return MODULE_REMOVABLE_END;
371 if ( mi && ((mi->
newflags & 2) != 0) )
373 return MODULE_RESIDENT_END;
376 printf(
"netcnf: RegisterLibraryEntries(%d)\n", regres);
385 return MODULE_NO_RESIDENT_END;
388static int do_module_unload(
void)
394 relres = ReleaseLibraryEntries(&_exp_netcnf);
397 printf(
"netcnf: ReleaseLibraryEntries (%d)\n", relres);
402 relres = DeleteSema(g_semid);
405 printf(
"netcnf: DeleteSema (%d)\n", relres);
415 return MODULE_NO_RESIDENT_END;
419 RegisterLibraryEntries(&_exp_netcnf);
421 return MODULE_REMOVABLE_END;
424int _start(
int ac,
char *av[],
void *startaddr,
ModuleInfo_t *mi)
426 return (ac >= 0) ? do_module_load(ac, av, startaddr, mi) : do_module_unload();
430int sceNetCnfGetCount(
const char *fname,
int type)
437 retres = do_get_count_list_inner(fname, type, 0);
451 retres = do_get_count_list_inner(fname, type, p);
458int sceNetCnfLoadEntry(
const char *fname,
int type,
const char *usr_name,
sceNetCnfEnv_t *e)
465 retres = do_load_entry_inner(fname, type, usr_name, e);
472int sceNetCnfAddEntry(
const char *fname,
int type,
const char *usr_name,
sceNetCnfEnv_t *e)
479 retres = do_add_entry_inner(fname, type, usr_name, e, g_icon_value, g_iconsys_value, g_no_check_capacity);
486int sceNetCnfEditEntry(
const char *fname,
int type,
const char *usr_name,
const char *new_usr_name,
sceNetCnfEnv_t *e)
494 do_edit_entry_inner(fname, type, usr_name, new_usr_name, e, g_icon_value, g_iconsys_value, g_no_check_capacity);
501int sceNetCnfDeleteEntry(
const char *fname,
int type,
const char *usr_name)
508 retres = do_delete_entry_inner(fname, type, usr_name, g_icon_value, g_iconsys_value, g_no_check_capacity);
515int sceNetCnfSetLatestEntry(
const char *fname,
int type,
const char *usr_name)
522 retres = do_set_latest_entry_inner(fname, type, usr_name);
531 return do_alloc_mem_inner(e, (
unsigned int)size, align);
539 do_init_ifc_inner(ifc);
546 return do_load_conf_inner(e);
551 return do_load_dial_inner(e, pair);
556 return do_merge_conf_inner(e);
561 unsigned int paddr_tmp;
564 if ( buf && !do_name_2_address_inner(&paddr_tmp, buf) )
569 memcpy(paddr->data, &paddr_tmp,
sizeof(paddr_tmp));
577 unsigned int srcintx;
579 if ( paddr->reserved )
583 memcpy(&srcintx, paddr->data,
sizeof(srcintx));
584 do_address_to_string_inner(buf_tmp, srcintx);
585 buflen = (u32)strlen(buf_tmp) + 1;
586 if ( (
unsigned int)len < buflen )
590 memcpy(buf, buf_tmp, buflen);
594int sceNetCnfDeleteAll(
const char *dev)
601 retres = do_delete_all_inner(dev);
608int sceNetCnfCheckCapacity(
const char *fname)
615 retres = do_check_capacity_inner(fname);
622int sceNetCnfConvA2S(
char *sp_,
char *dp_,
int len)
626 retres = do_conv_a2s_inner(sp_, dp_, len);
631 if ( len < (
int)(strlen(sp_) + 1) )
639int sceNetCnfConvS2A(
char *sp_,
char *dp_,
int len)
643 retres = do_conv_s2a_inner(sp_, dp_, len);
648 if ( len < (
int)(strlen(sp_) + 1) )
656int sceNetCnfCheckSpecialProvider(
const char *fname,
int type,
const char *usr_name,
sceNetCnfEnv_t *e)
663 retres = do_check_special_provider_inner(fname, type, usr_name, e);
675 do_set_callback_inner(pcallback);
681static int do_read_ilink_id(
void)
686 for ( i = 0; i < 20; i += 1 )
689 if (
sceCdRI((u8 *)g_id_buffer, &g_id_result) == 1 )
698 memset(&g_id_buffer, 0,
sizeof(g_id_buffer));
704static int do_read_netcnf_decode(
const char *netcnf_path,
char **netcnf_heap_ptr)
714 *netcnf_heap_ptr = 0;
715 result = do_read_ilink_id();
719 do_init_xor_magic(g_id_buffer);
720 fd = do_open_netcnf(netcnf_path, 1, 0);
723 return (fd == -
EIO) ? -18 : -3;
725 netcnf_size = do_filesize_netcnf(fd);
726 if ( netcnf_size < 0 )
731 heapmem = (
char *)do_alloc_heapmem(netcnf_size + 1);
732 *netcnf_heap_ptr = heapmem;
740 for ( i = 0; i < netcnf_size; i += 2 )
742 readres = do_readfile_netcnf(fd, &heapmem[i], 2);
745 *((u16 *)&heapmem[i]) ^= 0xFFFF;
746 *((u16 *)&heapmem[i]) = (u16)magic_shift_read_netcnf_1(*((u16 *)&heapmem[i]), (u8)g_id_xorbuf[xorind1 + 2]);
748 xorind1 = (xorind1 !=
sizeof(g_id_xorbuf)) ? xorind1 : 0;
752 if ( (netcnf_size & 1) != 0 )
754 readres = do_readfile_netcnf(fd, &heapmem[netcnf_size - 1], 1);
757 heapmem[netcnf_size - 1] ^= 0xFF;
758 heapmem[netcnf_size - 1] =
759 (char)magic_shift_read_netcnf_2(heapmem[netcnf_size - 1], (u8)g_id_xorbuf[xorind1 + 2]);
764 heapmem[netcnf_size] = 0;
769 do_free_heapmem(heapmem);
770 *netcnf_heap_ptr = 0;
772 return (readres != -
EIO) ? -4 : -18;
775static int do_write_netcnf_encode(
const char *netcnf_path,
void *buf,
int netcnf_len)
787 result = do_read_ilink_id();
791 do_init_xor_magic(g_id_buffer);
792 fd = do_open_netcnf(netcnf_path, 1538, 511);
796 return (fd == -
EIO) ? -18 : -3;
798 netcnf_len_1 = netcnf_len;
802 while ( writeres >= 0 )
804 while ( netcnf_len_1 >= 2 )
806 bufflipx1 = (u16)magic_shift_write_netcnf_1(*buf_1, (u8)g_id_xorbuf[xorind1 + 2]);
808 xorind1 = (xorind1 !=
sizeof(g_id_xorbuf)) ? xorind1 : 0;
810 writeres = do_write_netcnf_no_encode(fd, &bufflipx1,
sizeof(bufflipx1));
817 if ( writeres >= 0 && !netcnf_len_1 )
824 bufflipx2 = (char)magic_shift_write_netcnf_2(*(u8 *)buf_1, (u8)g_id_xorbuf[xorind1 + 2]);
826 xorind1 = (xorind1 !=
sizeof(g_id_xorbuf)) ? xorind1 : 0;
828 writeres = do_write_netcnf_no_encode(fd, &bufflipx2,
sizeof(bufflipx2));
834 return (writeres != -
EIO) ? -5 : -18;
837static int do_read_netcnf_no_decode(
const char *netcnf_path,
char **netcnf_heap_ptr)
843 *netcnf_heap_ptr = 0;
844 fd = do_open_netcnf(netcnf_path, 1, 0);
847 return (fd != -
EIO) ? -3 : -18;
849 netcnf_size = do_filesize_netcnf(fd);
850 if ( netcnf_size < 0 )
855 netcnf_data = (
char *)do_alloc_heapmem(netcnf_size + 1);
856 *netcnf_heap_ptr = netcnf_data;
862 netcnf_size = do_readfile_netcnf(fd, netcnf_data, netcnf_size);
863 if ( netcnf_size < 0 )
865 do_free_heapmem(*netcnf_heap_ptr);
866 *netcnf_heap_ptr = 0;
868 return (netcnf_size != -
EIO) ? -4 : -18;
870 netcnf_data[netcnf_size] = 0;
875static void do_init_xor_magic(
const char *in_id_buf)
879 for ( i = 0; (i + 1) < 8; i += 1 )
881 g_id_xorbuf[(i * 3) + 2] = ((u8)in_id_buf[i] >> 5) + 1;
882 g_id_xorbuf[(i * 3) + 3] = (((u8)in_id_buf[i] >> 2) & 7) + 1;
883 g_id_xorbuf[(i * 3) + 4] = (in_id_buf[i] & 3) + 1;
887static int magic_shift_write_netcnf_2(
int inshft,
int buflen)
889 for ( ; buflen; buflen -= 1 )
890 inshft = ((u8)inshft >> 7) | (inshft << 1);
894static int magic_shift_read_netcnf_2(
int inshft,
int buflen)
896 for ( ; buflen; buflen -= 1 )
897 inshft = ((u8)inshft >> 1) | (inshft << 7);
901static int magic_shift_write_netcnf_1(
int inshft,
int buflen)
903 for ( ; buflen; buflen -= 1 )
904 inshft = ((u16)inshft >> 15) | (inshft << 1);
908static int magic_shift_read_netcnf_1(
int inshft,
int buflen)
910 for ( ; buflen; buflen -= 1 )
911 inshft = ((u16)inshft >> 1) | (inshft << 15);
915static void do_safe_strcpy(
char *dst,
size_t maxlen,
const char *src,
int linenum)
917 if ( strlen(src) >= maxlen )
919 printf(
"[netcnf] strcpy failed(%d)\n", linenum);
925static void do_safe_strcat(
char *dst,
size_t maxlen,
const char *src,
int linenum)
927 if ( strlen(dst) + strlen(src) >= maxlen )
929 printf(
"[netcnf] strcat failed(%d)\n", linenum);
935static void do_safe_make_pathname(
char *dst,
size_t maxlen,
const char *srcdir,
const char *srcbase)
937 if ( strlen(srcdir) + strlen(srcbase) + 1 >= maxlen )
939 printf(
"[netcnf] make_pathname failed\n");
944 strcat(dst, srcbase);
947static void do_safe_make_name(
char *dst,
size_t maxlen,
const char *src1,
const char *src2)
949 if ( strlen(src1) + strlen(src2) >= maxlen )
951 printf(
"[netcnf] make_name failed\n");
958static int do_check_capacity_inner2(
const char *fpath,
int minsize)
964 for ( i = 0; i < 5; i += 1 )
966 devname[i] = fpath[i];
967 if ( fpath[i] ==
':' )
971 zonefree = iomanX_devctl(devname, 0x5002, 0, 0, 0, 0) * ((int)iomanX_devctl(devname, 0x5001, 0, 0, 0, 0) / 1024);
976 statvfs(devname, &st);
977 zonefree = (int)(u32)(st.f_bfree * st.f_frsize);
980 return (zonefree < minsize) ? -16 : 0;
986static int do_check_capacity_inner(
const char *fpath)
990 if ( !strncmp(fpath,
"mc", 2) )
992 else if ( !strncmp(fpath,
"pfs", 3) )
996 return do_check_capacity_inner2(fpath, minsize);
999static int do_handle_combination_path(
int type,
const char *fpath,
char *dst,
size_t maxlen,
const char *usr_name)
1008 do_safe_strcpy(dst, maxlen, usr_name, 139);
1011 for ( i = dst; !isdigit(*i); i += 1 )
1013 for ( j = 0; j < 4 && isdigit(i[j]); j += 1 )
1020 devnr = (int)strtol(devnum, 0, 10);
1022 !strncmp(fpath,
"mc", 2) ? ((
unsigned int)(devnr - 1) >= 6) :
1023 (!strncmp(fpath,
"pfs", 3) ? (
unsigned int)(devnr - 1) >= 0xA :
1024 (
unsigned int)(devnr - 1) >=
sizeof(g_ifc_buffer)) )
1026 do_safe_make_name(dst, maxlen,
"Combination", devnum);
1030static int do_copy_netcnf_path(
const char *netcnf_path_1,
const char *netcnf_path_2)
1037 fd2 = do_open_netcnf(netcnf_path_2, 1538, 511);
1040 fd1 = do_open_netcnf(netcnf_path_1, 1, 0);
1043 do_close_netcnf(fd2);
1050 readres = do_readfile_netcnf(fd1, tmpbuf,
sizeof(tmpbuf));
1053 writeres = do_write_netcnf_no_encode(fd2, tmpbuf, readres);
1054 if ( readres != writeres )
1056 do_close_netcnf(fd2);
1057 do_close_netcnf(fd1);
1061 do_close_netcnf(fd2);
1062 do_close_netcnf(fd1);
1063 return (readres < 0) ? -4 : 0;
1066static char *do_write_memcard_pathcopy(
char *dst,
size_t maxlen,
const char *src)
1068 char *dst_end_slash;
1070 do_safe_strcpy(dst, maxlen, src, 218);
1071 for ( dst_end_slash = &dst[strlen(dst)]; *dst_end_slash !=
'/'; dst_end_slash -= 1 )
1073 for ( ; *dst_end_slash ==
'/'; dst_end_slash -= 1 )
1075 if ( *dst_end_slash ==
':' )
1077 dst_end_slash[1] = 0;
1081static int do_write_memcard_files(
const char *fpath,
const char *icon_value,
const char *iconsys_value)
1084 char cur_basepath[256];
1085 char cur_combpath[256];
1087 if ( !do_write_memcard_pathcopy(cur_basepath,
sizeof(cur_basepath), fpath) )
1089 do_safe_make_pathname(cur_combpath,
sizeof(cur_combpath), cur_basepath,
"SYS_NET.ICO");
1090 result = do_copy_netcnf_path(icon_value, cur_combpath);
1093 do_safe_make_pathname(cur_combpath,
sizeof(cur_combpath), cur_basepath,
"icon.sys");
1094 result = do_copy_netcnf_path(iconsys_value, cur_combpath);
1100static int do_handle_fname(
char *fpath,
size_t maxlen,
const char *fname)
1103 const char *pathname;
1106 do_safe_strcpy(fpath, maxlen, fname, 266);
1107 index_res = index(fpath,
':');
1110 if ( !strncmp(fpath,
"mc", 2) )
1113 pathname =
"/BWNETCNF/BWNETCNF";
1116 else if ( !strncmp(fpath,
"pfs", 3) )
1119 pathname =
"/etc/network/net.db";
1124 do_safe_strcat(fpath, maxlen, pathname, maxbuf);
1128static const char *do_get_str_line(
const char *buf)
1130 for ( ; *buf && *buf !=
'\n'; buf += 1 )
1132 return &buf[*buf ==
'\n'];
1135static int do_split_str_comma_index(
char *dst,
const char *src,
int commaind)
1139 for ( i = 0; i < commaind; i += 1 )
1141 for ( ; *src && *src !=
'\n' && *src !=
','; src += 1 )
1147 for ( ; *src && *src !=
',' && *src !=
'\n' && *src !=
'\r'; src += 1 )
1157do_remove_old_config(
const char *fpath,
const char *netcnf_heap_buf,
const char *icon_value,
const char *iconsys_value)
1162 const char *curheapbuf1;
1163 char cur_basepath[256];
1164 char cur_combpath[256];
1171 if ( !do_write_memcard_pathcopy(cur_basepath,
sizeof(cur_basepath), fpath) )
1173 dfd = do_dopen_wrap(cur_basepath);
1177 return (dfd == -
EIO) ? -18 : 0;
1183 fileop_res = do_dread_wrap(dfd, &statname);
1185 if ( fileop_res <= 0 )
1188 if ( strlen(statname.name) == 10 )
1190 if ( !strncmp(&statname.name[6],
".cnf", 4) || !strncmp(&statname.name[6],
".dat", 4) )
1192 for ( curheapbuf1 = netcnf_heap_buf; curheapbuf1 && *curheapbuf1; curheapbuf1 = do_get_str_line(curheapbuf1) )
1194 do_split_str_comma_index(cur_combpath, curheapbuf1, 2);
1195 if ( !strcmp(statname.name, cur_combpath) )
1197 do_safe_make_pathname(cur_combpath,
sizeof(cur_combpath), cur_basepath, statname.name);
1204 else if ( !strncmp(fpath,
"mc", 2) )
1206 if ( !strcmp(statname.name,
"SYS_NET.ICO") )
1208 do_safe_make_pathname(cur_combpath,
sizeof(cur_combpath), cur_basepath, statname.name);
1209 do_getstat_wrap(cur_combpath, &statsize);
1210 if ( statsize.size != 0x8398 )
1219 else if ( !strcmp(statname.name,
"icon.sys") )
1221 do_safe_make_pathname(cur_combpath,
sizeof(cur_combpath), cur_basepath, statname.name);
1222 do_getstat_wrap(cur_combpath, &statsize);
1223 if ( statsize.size != 0x3C4 )
1232 else if ( strcmp(statname.name,
"BWNETCNF") )
1234 do_safe_make_pathname(cur_combpath,
sizeof(cur_combpath), cur_basepath, statname.name);
1238 else if ( !strncmp(fpath,
"pfs", 3) && strcmp(statname.name,
"net.db") )
1240 do_safe_make_pathname(cur_combpath,
sizeof(cur_combpath), cur_basepath, statname.name);
1245 fileop_res = do_remove_wrap(cur_combpath);
1246 if ( fileop_res == -
EIO )
1250 if ( fileop_res == -
EIO )
1252 do_dclose_wrap(dfd);
1255 do_dclose_wrap(dfd);
1256 if ( !strncmp(fpath,
"mc", 2) )
1258 if ( sysneticoflag || iconsysflag )
1259 fileop_res = do_write_memcard_files(fpath, icon_value, iconsys_value);
1260 do_chstat_mode_copyprotect_wrap(cur_basepath);
1265static int do_type_check(
int type,
const char *buf)
1267 return (do_split_str_comma_index(g_arg_fname, buf, 0)) ? -1 : (strtol(g_arg_fname, 0, 10) == type);
1270static int do_read_current_netcnf_nodecode(
const char *fpath,
char **netcnf_heap_ptr)
1276 retres = do_read_netcnf_no_decode(fpath, netcnf_heap_ptr);
1277 return (retres < 0) ? ((retres != -3) ? retres : 0) : retres;
1280static int do_write_noencode_netcnf_atomic(
const char *fpath,
void *ptr,
int size)
1284 char fpath_comb[256];
1288 do_safe_make_name(fpath_comb,
sizeof(fpath_comb), fpath,
".tmp");
1289 fd = do_open_netcnf(fpath_comb, 1538, 511);
1292 return (fd == -
EIO) ? -18 : -3;
1294 writeres = do_write_netcnf_no_encode(fd, ptr, size);
1295 do_close_netcnf(fd);
1297 return (size != writeres) ? ((writeres != -
EIO) ? -5 : -18) : ((iomanX_rename(fpath_comb, fpath) == -
EIO) ? -18 : 0);
1300static int do_remove_netcnf_dirname(
const char *dirpath,
const char *entry_buffer)
1302 const char *p_dirname;
1305 p_dirname = do_handle_netcnf_dirname(dirpath, entry_buffer, g_netcnf_file_path);
1308 remove_res_1 = do_remove_wrap(p_dirname);
1309 return (remove_res_1 < 0) ? ((remove_res_1 == -
EIO) ? -18 : -7) : 0;
1312static int do_get_count_list_inner(
const char *fname,
int type,
sceNetCnfList_t *p)
1315 const char *curheapbuf1;
1318 result = do_handle_fname(g_dir_name,
sizeof(g_dir_name), fname);
1321 result = do_read_current_netcnf_nodecode(g_dir_name, &g_count_list_heapptr);
1325 for ( curheapbuf1 = g_count_list_heapptr; *curheapbuf1; curheapbuf1 = do_get_str_line(curheapbuf1) )
1327 if ( do_type_check(type, curheapbuf1) <= 0 )
1333 if ( do_split_str_comma_index(g_arg_fname, curheapbuf1, 1) )
1335 p->stat = (int)strtol(g_arg_fname, 0, 10);
1337 do_split_str_comma_index(p->sys_name, curheapbuf1, 2) || do_split_str_comma_index(p->usr_name, curheapbuf1, 3) )
1341 do_free_heapmem(g_count_list_heapptr);
1345static int do_load_entry_inner(
const char *fname,
int type,
const char *usr_name,
sceNetCnfEnv_t *e)
1348 const char *curheapbuf1;
1350 result = do_handle_fname(g_dir_name,
sizeof(g_dir_name), fname);
1353 result = do_handle_combination_path(type, g_dir_name, g_combination_buf1,
sizeof(g_combination_buf1), usr_name);
1356 result = do_read_current_netcnf_nodecode(g_dir_name, &g_load_entry_heapptr);
1358 return !result ? -8 : result;
1359 for ( curheapbuf1 = g_load_entry_heapptr; *curheapbuf1; curheapbuf1 = do_get_str_line(curheapbuf1) )
1362 do_type_check(type, curheapbuf1) >= 0 && !do_split_str_comma_index(g_arg_fname, curheapbuf1, 3)
1363 && !strcmp(g_arg_fname, g_combination_buf1) && !do_split_str_comma_index(g_arg_fname, curheapbuf1, 2) )
1365 do_free_heapmem(g_load_entry_heapptr);
1366 e->dir_name = g_dir_name;
1367 e->arg_fname = g_arg_fname;
1368 e->req = type ? 2 : 1;
1369 return do_load_conf_inner(e);
1372 do_free_heapmem(g_load_entry_heapptr);
1376static void do_extra_ifc_handling(
const char *arg_fname)
1379 const char *curptr1;
1380 unsigned int curbufsz1;
1381 unsigned int curindx;
1383 if ( !arg_fname || !*arg_fname )
1385 for ( i = &arg_fname[strlen(arg_fname) - 1]; i >= arg_fname && *i !=
'.'; i -= 1 )
1388 if ( curptr1 < arg_fname || *i !=
'.' || !isdigit(*curptr1) )
1392 for ( ; curptr1 >= arg_fname && isdigit(*curptr1); curptr1 -= 1 )
1394 curbufsz1 += curindx * (u8)(*curptr1 -
'0');
1397 if ( curbufsz1 <
sizeof(g_ifc_buffer) )
1398 g_ifc_buffer[curbufsz1] = 1;
1401static void do_extra_pair_handling(
char *fpath,
int type,
const char *src,
const sceNetCnfEnv_t *e)
1407 if ( do_split_str_comma_index(g_arg_fname, src, 2) )
1413 heapmem->mem_ptr = &heapmem[1];
1414 heapmem->mem_base = &heapmem[1];
1415 heapmem->dir_name = fpath;
1416 heapmem->arg_fname = g_arg_fname;
1417 heapmem->mem_last = ((
char *)&heapmem[1]) + 4096;
1418 heapmem->f_no_check_magic = e->f_no_check_magic;
1419 heapmem->f_no_decode = e->f_no_decode;
1420 heapmem->f_verbose = e->f_verbose;
1421 conf_inner = do_load_conf_inner(heapmem);
1422 if ( (!conf_inner || conf_inner == -21) && heapmem->root )
1424 for ( i = heapmem->root->pair_head; i; i = i->forw )
1429 do_extra_ifc_handling((
char *)i->attach_ifc);
1432 do_extra_ifc_handling((
char *)i->attach_dev);
1439 do_free_heapmem(heapmem);
1442static int do_add_entry_inner(
1445 const char *usr_name,
1447 const char *icon_value,
1448 const char *iconsys_value,
1449 int no_check_capacity)
1453 const char *curentry1;
1455 const char *curentry2;
1458 char atomicrenamepath[256];
1464 if ( get_check_provider_eq_zero() )
1466 result = do_check_provider_inner(e, type);
1470 result = do_handle_fname(g_dir_name,
sizeof(g_dir_name), fname);
1473 if ( !no_check_capacity )
1475 result = do_check_capacity_inner(g_dir_name);
1479 atomicrenamepath[0] = 0;
1480 result = do_handle_combination_path(type, g_dir_name, g_combination_buf1,
sizeof(g_combination_buf1), usr_name);
1483 retres1 = do_read_current_netcnf_nodecode(g_dir_name, &g_add_entry_heapptr);
1486 retres2 = do_remove_old_config(g_dir_name, g_add_entry_heapptr, icon_value, iconsys_value);
1491 memset(g_ifc_buffer, 0,
sizeof(g_ifc_buffer));
1494 if ( !strncmp(g_dir_name,
"mc", 2) )
1497 for ( curentry1 = g_add_entry_heapptr; *curentry1; curentry1 = do_get_str_line(curentry1) )
1499 if ( do_type_check(type, curentry1) == 1 )
1519 else if ( !strncmp(g_dir_name,
"pfs", 3) )
1522 for ( curentry2 = g_add_entry_heapptr; *curentry2; curentry2 = do_get_str_line(curentry2) )
1524 if ( do_type_check(type, curentry2) == 1 )
1546 for ( k = g_add_entry_heapptr; *k; k = do_get_str_line(k) )
1548 if ( (
unsigned int)(type - 1) < 2 && do_type_check(0, k) > 0 )
1549 do_extra_pair_handling(g_dir_name, type, k, e);
1551 do_type_check(type, k) > 0 && !do_split_str_comma_index(g_arg_fname, k, 1)
1552 && strtol(g_arg_fname, 0, 10) == 1 && !do_split_str_comma_index(g_arg_fname, k, 2) )
1554 do_extra_ifc_handling(g_arg_fname);
1555 if ( !do_split_str_comma_index(g_arg_fname, k, 3) && !strcmp(g_combination_buf1, g_arg_fname) )
1557 do_free_heapmem(g_add_entry_heapptr);
1568 const char *fileext;
1570 do_safe_strcpy(g_arg_fname,
sizeof(g_arg_fname), g_dir_name, 740);
1571 for ( endbuf = &g_arg_fname[strlen(g_arg_fname) - 1];
1572 endbuf >= g_arg_fname && *endbuf !=
':' && *endbuf !=
'/' && *endbuf !=
'\\';
1575 if ( endbuf >= g_arg_fname && *endbuf !=
':' && *endbuf !=
'/' && *endbuf !=
'\\' )
1583 fileext = (type && !e->f_no_decode) ?
".dat" :
".cnf";
1584 for ( i = 0; i < (int)(
sizeof(g_ifc_buffer)); i += 1 )
1586 if ( !g_ifc_buffer[i] )
1592 sprintf(g_netcnf_file_path,
"%.245sifc%03d%s", g_arg_fname, i, fileext);
1596 sprintf(g_netcnf_file_path,
"%.245sdev%03d%s", g_arg_fname, i, fileext);
1600 sprintf(g_netcnf_file_path,
"%.245snet%03d%s", g_arg_fname, i, fileext);
1603 do_free_heapmem(g_add_entry_heapptr);
1606 fd = do_open_netcnf(g_netcnf_file_path, 1, 0);
1613 do_close_netcnf(fd);
1617 if ( i < (
int)(
sizeof(g_ifc_buffer)) )
1620 char *cur_entry_buffer;
1622 cur_entry_buffer = g_entry_buffer;
1623 for ( dirname_buf1 = g_dir_name; *dirname_buf1; dirname_buf1 += 1 )
1625 if ( (*dirname_buf1 ==
'/' || *dirname_buf1 ==
'\\') && dirname_buf1[1] )
1627 *cur_entry_buffer = 0;
1628 retres2 = mkdir(g_entry_buffer, 511);
1629 if ( !retres2 && !strncmp(g_dir_name,
"mc", 2) )
1631 do_chstat_mode_copyprotect_wrap(g_entry_buffer);
1632 retres2 = do_write_memcard_files(g_dir_name, icon_value, iconsys_value);
1636 if ( retres2 == -5 )
1640 *cur_entry_buffer = *dirname_buf1;
1641 cur_entry_buffer += 1;
1643 if ( *dirname_buf1 )
1645 e->dir_name = g_dir_name;
1646 e->arg_fname = &g_netcnf_file_path[strlen(g_arg_fname)];
1647 e->req = type ? 2 : 1;
1649 if ( !do_export_netcnf(e) )
1651 do_safe_make_name(atomicrenamepath,
sizeof(atomicrenamepath), g_dir_name,
".tmp");
1652 fd = do_open_netcnf(atomicrenamepath, 1538, 511);
1655 retres2 = (fd == -
EIO) ? -18 : -3;
1663 g_entry_buffer,
"%d,%d,%s,%s\n", type, 1, &g_netcnf_file_path[strlen(g_arg_fname)], g_combination_buf1);
1664 writeres = do_write_netcnf_no_encode(fd, g_entry_buffer, strlenx);
1666 if ( strlenx != writeres )
1668 retres2 = (writeres == -
EIO) ? -18 : -5;
1672 writeres = do_write_netcnf_no_encode(fd, g_add_entry_heapptr, retres1);
1673 if ( retres1 != writeres )
1675 retres2 = (writeres == -
EIO) ? -18 : -5;
1683 do_free_heapmem(g_add_entry_heapptr);
1685 do_close_netcnf(fd);
1687 return (atomicrenamepath[0] && iomanX_rename(atomicrenamepath, g_dir_name) == -
EIO) ?
1689 ((strncmp(g_dir_name,
"pfs", 3) || iomanX_sync(g_dir_name, 0) != -
EIO) ? retres2 : -18);
1692static int do_handle_set_usrname(
const char *fpath,
int type,
const char *usrname_buf2,
const char *usrname_bufnew)
1703 if ( !usrname_buf2 )
1705 result = do_handle_combination_path(type, g_dir_name, g_combination_buf1,
sizeof(g_combination_buf1), usrname_bufnew);
1708 retres1 = do_read_current_netcnf_nodecode(fpath, &ptr);
1710 return (!retres1) ? -3 : retres1;
1711 heapmem = (
char *)do_alloc_heapmem((
int)((
unsigned int)retres1 + strlen(usrname_bufnew) + 1));
1714 do_free_heapmem(ptr);
1718 heapmem_1 = heapmem;
1721 if ( do_type_check(type, ptr_1) > 0 && !do_split_str_comma_index(g_arg_fname, ptr_1, 3) )
1723 if ( !strcmp(g_arg_fname, usrname_buf2) )
1725 if ( !do_split_str_comma_index(g_arg_fname, ptr_1, 2) )
1727 heapmem_1 += sprintf(heapmem_1,
"%d,%d,%s,%s\n", type, 1, g_arg_fname, g_combination_buf1);
1728 ptr_1 = do_get_str_line(ptr_1);
1732 else if ( !strcmp(g_arg_fname, g_combination_buf1) )
1734 do_free_heapmem(ptr);
1735 do_free_heapmem(heapmem);
1739 for ( ; *ptr_1 && *ptr_1 !=
'\n'; ptr_1 += 1 )
1741 *heapmem_1 = *ptr_1;
1744 if ( *ptr_1 ==
'\n' )
1746 *heapmem_1 = *ptr_1;
1751 do_free_heapmem(ptr);
1752 writeres1 = do_write_noencode_netcnf_atomic(fpath, heapmem, (
int)(heapmem_1 - heapmem));
1753 do_free_heapmem(heapmem);
1757static int do_edit_entry_inner(
1760 const char *usr_name,
1761 const char *new_usr_name,
1763 const char *icon_value,
1764 const char *iconsys_value,
1765 int no_check_capacity)
1769 const char *curentry1;
1770 char curentrybuf1[256];
1771 char curfilepath1[256];
1773 if ( get_check_provider_eq_zero() )
1775 result = do_check_provider_inner(e, type);
1779 result = do_handle_fname(g_dir_name,
sizeof(g_dir_name), fname);
1782 if ( !no_check_capacity )
1784 result = do_check_capacity_inner(g_dir_name);
1788 result = do_handle_combination_path(type, g_dir_name, g_combination_buf2,
sizeof(g_combination_buf2), usr_name);
1791 result = do_read_current_netcnf_nodecode(g_dir_name, &g_edit_entry_heapptr);
1794 return !result ? -3 : result;
1796 rmoldcfgres = do_remove_old_config(g_dir_name, g_edit_entry_heapptr, icon_value, iconsys_value);
1797 if ( rmoldcfgres >= 0 )
1802 for ( curentry1 = g_edit_entry_heapptr; *curentry1; curentry1 = do_get_str_line(curentry1) )
1805 do_type_check(type, curentry1) > 0 && !do_split_str_comma_index(g_arg_fname, curentry1, 3)
1806 && !strcmp(g_arg_fname, g_combination_buf2) && !do_split_str_comma_index(curentrybuf1, curentry1, 2) )
1818 if ( !get_check_provider_eq_zero() )
1824 rmoldcfgres = !do_handle_netcnf_dirname(g_dir_name, curentrybuf1, curfilepath1) ?
1826 do_read_check_netcnf(curfilepath1, type, e->f_no_check_magic, e->f_no_decode);
1829 if ( flg || rmoldcfgres >= 0 )
1831 do_safe_make_name(curfilepath1,
sizeof(curfilepath1), curentrybuf1,
".tmp");
1832 e->dir_name = g_dir_name;
1834 e->arg_fname = curfilepath1;
1835 e->req = type ? 2 : 1;
1836 if ( do_export_netcnf(e) )
1842 char *curfilepath1end;
1844 do_safe_strcpy(curfilepath1,
sizeof(curfilepath1), g_dir_name, 1010);
1845 for ( curfilepath1end = &curfilepath1[strlen(curfilepath1)]; curfilepath1end != curfilepath1;
1846 curfilepath1end -= 1 )
1848 if ( *curfilepath1end ==
'/' || *curfilepath1end ==
'\\' )
1850 curfilepath1end[1] = 0;
1854 do_safe_strcat(curfilepath1,
sizeof(curfilepath1), curentrybuf1, 1017);
1855 do_safe_strcpy(curentrybuf1,
sizeof(curentrybuf1), curfilepath1, 1018);
1856 do_safe_strcat(curfilepath1,
sizeof(curfilepath1),
".tmp", 1019);
1857 if ( iomanX_rename(curfilepath1, curentrybuf1) == -
EIO )
1862 do_free_heapmem(g_edit_entry_heapptr);
1863 if ( rmoldcfgres >= 0 )
1865 do_set_latest_entry_inner(g_dir_name, type, g_combination_buf2);
1867 rmoldcfgres = do_handle_set_usrname(g_dir_name, type, g_combination_buf2, new_usr_name);
1869 return (!strncmp(g_dir_name,
"pfs", 3) && iomanX_sync(g_dir_name, 0) == -
EIO) ? -18 : rmoldcfgres;
1872static int do_delete_entry_inner(
1875 const char *usr_name,
1876 const char *icon_value,
1877 const char *iconsys_value,
1878 int no_check_capacity)
1883 const char *curentry1;
1886 g_delete_entry_heapptr = 0;
1887 result = do_handle_fname(g_dir_name,
sizeof(g_dir_name), fname);
1892 if ( !no_check_capacity )
1894 result = do_check_capacity_inner(g_dir_name);
1898 result = do_handle_combination_path(type, g_dir_name, g_combination_buf1,
sizeof(g_combination_buf1), usr_name);
1901 result = do_read_current_netcnf_nodecode(g_dir_name, &g_delete_entry_heapptr);
1903 return !result ? -3 : result;
1904 heapmem = (
char *)do_alloc_heapmem(result);
1907 do_free_heapmem(g_delete_entry_heapptr);
1910 result = do_remove_old_config(g_dir_name, g_delete_entry_heapptr, icon_value, iconsys_value);
1915 curentry1 = g_delete_entry_heapptr;
1916 heapmem_1 = heapmem;
1917 while ( *curentry1 )
1920 do_type_check(type, curentry1) <= 0 || do_split_str_comma_index(g_arg_fname, curentry1, 3)
1921 || strcmp(g_arg_fname, g_combination_buf1) )
1923 for ( ; *curentry1 && *curentry1 !=
'\n'; curentry1 += 1 )
1925 *heapmem_1 = *curentry1;
1928 if ( *curentry1 ==
'\n' )
1930 *heapmem_1 = *curentry1;
1937 if ( !do_split_str_comma_index(g_entry_buffer, curentry1, 2) )
1939 curentry1 = do_get_str_line(curentry1);
1942 result = do_write_noencode_netcnf_atomic(g_dir_name, heapmem, (
int)(heapmem_1 - heapmem));
1943 if ( result >= 0 && has_comma )
1944 result = do_remove_netcnf_dirname(g_dir_name, g_entry_buffer);
1946 do_free_heapmem(g_delete_entry_heapptr);
1947 do_free_heapmem(heapmem);
1948 return (!strncmp(g_dir_name,
"pfs", 3) && iomanX_sync(g_dir_name, 0) == -
EIO) ? -18 : result;
1951static int do_set_latest_entry_inner(
const char *fname,
int type,
const char *usr_name)
1962 result = do_handle_fname(g_dir_name,
sizeof(g_dir_name), fname);
1967 result = do_handle_combination_path(type, g_dir_name, g_combination_buf1,
sizeof(g_combination_buf1), usr_name);
1973 g_set_latest_entry_heapptr = 0;
1974 result = do_read_current_netcnf_nodecode(g_dir_name, &g_set_latest_entry_heapptr);
1978 return !result ? -3 : result;
1981 heapmem1 = (
char *)do_alloc_heapmem(readsz);
1982 heapmem1_1 = heapmem1;
1987 heapmem2 = (
char *)do_alloc_heapmem(readsz);
1988 heapmem2_1 = heapmem2;
1991 curentry1 = g_set_latest_entry_heapptr;
1993 while ( *curentry1 )
1996 do_type_check(type, curentry1) > 0 && !do_split_str_comma_index(g_arg_fname, curentry1, 3)
1997 && !strcmp(g_arg_fname, g_combination_buf1) )
1999 for ( ; *curentry1 && *curentry1 !=
'\n'; curentry1 += 1 )
2001 *heapmem1_1 = *curentry1;
2004 if ( *curentry1 ==
'\n' )
2006 *heapmem1_1 = *curentry1;
2011 if ( heapmem2 < heapmem2_1 )
2016 for ( ; *curentry1 && *curentry1 !=
'\n'; curentry1 += 1 )
2018 *heapmem2_1 = *curentry1;
2021 if ( *curentry1 ==
'\n' )
2023 *heapmem2_1 = *curentry1;
2031 memcpy(heapmem1_1, heapmem2, (u32)(heapmem2_1 - heapmem2));
2033 do_write_noencode_netcnf_atomic(g_dir_name, heapmem1, (
int)(heapmem1_1 - heapmem1 + heapmem2_1 - heapmem2));
2037 do_free_heapmem(g_set_latest_entry_heapptr);
2038 do_free_heapmem(heapmem1);
2039 do_free_heapmem(heapmem2);
2040 return (!strncmp(g_dir_name,
"pfs", 3) && iomanX_sync(g_dir_name, 0) == -
EIO) ? -18 : result;
2043static int do_delete_all_inner(
const char *dev)
2049 if ( !strncmp(dev,
"mc", 2) )
2053 for ( i = 0; dev[i] !=
':'; i += 1 )
2055 g_netcnf_file_path[i] = dev[i];
2057 g_netcnf_file_path[i] = dev[i];
2058 g_netcnf_file_path[i + 1] = 0;
2059 do_safe_strcat(g_netcnf_file_path,
sizeof(g_netcnf_file_path),
"/BWNETCNF", 1199);
2060 dfd1 = do_dopen_wrap(g_netcnf_file_path);
2066 dread_res = do_dread_wrap(dfd1, &statname);
2068 if ( dread_res <= 0 )
2070 if ( strcmp(statname.name,
".") && strcmp(statname.name,
"..") )
2072 do_safe_make_pathname(g_dir_name,
sizeof(g_dir_name), g_netcnf_file_path, statname.name);
2073 if ( do_remove_wrap(g_dir_name) < 0 )
2075 do_dclose_wrap(dfd1);
2080 do_dclose_wrap(dfd1);
2081 return (rmdir(g_netcnf_file_path) < 0) ? -7 : 0;
2083 else if ( !strncmp(dev,
"pfs", 3) )
2089 for ( i = 0; dev[i] !=
':'; i += 1 )
2091 g_netcnf_file_path[i] = dev[i];
2093 g_netcnf_file_path[i] = dev[i];
2094 g_netcnf_file_path[i + 1] = 0;
2095 do_safe_strcat(g_netcnf_file_path,
sizeof(g_netcnf_file_path),
"/etc/network", 1229);
2096 dfd2 = do_dopen_wrap(g_netcnf_file_path);
2100 return (dfd2 == -
EIO) ? -18 : 0;
2104 dread_res = do_dread_wrap(dfd2, &statname);
2106 if ( dread_res <= 0 )
2108 if ( strcmp(statname.name,
".") && strcmp(statname.name,
"..") )
2110 do_safe_make_pathname(g_dir_name,
sizeof(g_dir_name), g_netcnf_file_path, statname.name);
2111 remove_res2 = do_remove_wrap(g_dir_name);
2112 if ( remove_res2 < 0 )
2114 do_dclose_wrap(dfd2);
2115 return (remove_res2 == -
EIO) ? -18 : -7;
2119 if ( dread_res == -
EIO )
2121 do_dclose_wrap(dfd2);
2124 do_dclose_wrap(dfd2);
2125 rmdir_res1 = rmdir(g_netcnf_file_path);
2126 return (rmdir_res1 >= 0) ? ((iomanX_sync(g_netcnf_file_path, 0) != -
EIO) ? 0 : -18) :
2127 ((rmdir_res1 == -
EIO) ? -18 : -7);
2132static int do_check_special_provider_inner(
const char *fname,
int type,
const char *usr_name,
sceNetCnfEnv_t *e)
2135 const char *curentry1;
2139 result = do_handle_fname(g_dir_name,
sizeof(g_dir_name), fname);
2142 result = do_handle_combination_path(type, g_dir_name, g_combination_buf2,
sizeof(g_combination_buf2), usr_name);
2145 result = do_read_current_netcnf_nodecode(g_dir_name, &g_check_special_provider_heapptr);
2148 return !result ? -3 : result;
2151 for ( curentry1 = g_check_special_provider_heapptr; *curentry1; curentry1 = do_get_str_line(curentry1) )
2154 do_type_check(type, curentry1) > 0 && !do_split_str_comma_index(g_arg_fname, curentry1, 3)
2155 && !strcmp(g_arg_fname, g_combination_buf2) && !do_split_str_comma_index((
char *)e->lbuf, curentry1, 2) )
2160 retres = curentcount ? ((do_handle_netcnf_dirname(g_dir_name, (
const char *)e->lbuf, (
char *)e->dbuf)) ?
2161 do_read_check_netcnf((
const char *)e->dbuf, type, e->f_no_check_magic, e->f_no_decode) :
2164 do_free_heapmem(g_check_special_provider_heapptr);
2168static char *do_alloc_mem_inner(
sceNetCnfEnv_t *e,
unsigned int size,
int align)
2173 mem_ptr = e->mem_ptr;
2179 retptrbegin = (
char *)(((uiptr)mem_ptr + (1 << align) - 1) & (uiptr) ~((1 << align) - 1));
2180 if ( &retptrbegin[size] >= (
char *)e->mem_last )
2185 e->mem_ptr = &retptrbegin[size];
2186 memset(retptrbegin, 0, size);
2190static const char *do_netcnf_parse_string(
sceNetCnfEnv_t *e,
const char *e_arg)
2193 const char *argbegin;
2199 if ( *e_arg !=
'"' )
2202 for ( argbegin = e_arg + 1; *argbegin && *argbegin !=
'"' && (
char *)(dbuf + 1) < (
char *)&(e->dbuf[1023]); )
2206 argchr_1 = *argbegin;
2208 if ( argchr_1 ==
'\\' )
2216 if ( (
unsigned int)(((u8)*argbegin) -
'0') >= 8 )
2218 if ( ((u8)*argbegin) ==
'x' || ((u8)*argbegin) ==
'X' )
2222 if ( !isxdigit(*argbegin) )
2227 for ( i = 0; i < 2 && isxdigit(*argbegin); i += 1 )
2229 hexnum = 16 * argchr_1;
2232 + (isdigit(*argbegin) ? (((u8)*argbegin) -
'0') : ((!islower(*argbegin)) ? ((u8)*argbegin) -
'7' : ((u8)*argbegin) -
'W')));
2238 argchr_1 = *argbegin;
2270 for ( i = 0; i < 3 && (((u8)*argbegin) - (
unsigned int)
'0' < 8); i += 1 )
2272 argchr_1 = 8 * argchr_1 + *argbegin -
'0';
2277 else if ( (
unsigned int)(argchr_1 - 129) < 0x1F || (
unsigned int)(argchr_1 - 224) < 0x1D )
2279 if ( (u8)(((u8)*argbegin) - 64) < 0xBDu && ((u8)*argbegin) != 127 )
2281 *dbuf = (u8)argchr_1;
2283 argchr_1 = *argbegin;
2287 *dbuf = (u8)argchr_1;
2292 if ( ((u8)*argbegin) !=
'"' )
2296 else if ( argbegin[1] )
2303 printf(
"netcnf: \"%s\" line %d: ", e->fname, e->lno);
2307 printf(
"invalid escape (%s)", e_arg);
2310 printf(
"missing hexa-decimal(%s)", e_arg);
2313 printf(
"invalid quote (%s)", e_arg);
2316 printf(
"invalid extra chars (%s)", e_arg);
2326 return (
const char *)e->dbuf;
2329static char *do_alloc_mem_for_write(
sceNetCnfEnv_t *e,
const char *str)
2333 strptr = do_alloc_mem_inner(e, (
unsigned int)strlen(str) + 1, 0);
2336 strcpy(strptr, str);
2344 strptr = do_netcnf_parse_string(e, e_arg);
2345 return strptr ? do_alloc_mem_for_write(e, strptr) : 0;
2348static int do_parse_number(
sceNetCnfEnv_t *e,
const char *e_arg,
unsigned int *n_result)
2350 const char *e_arg_1;
2351 unsigned int curbasex;
2352 unsigned int curnum;
2356 if ( *e_arg ==
'0' && e_arg[1] )
2358 e_arg_1 = e_arg + 1;
2360 if ( e_arg[1] ==
'x' )
2362 e_arg_1 = e_arg + 2;
2373 e_arg_1_num = (((u8)*e_arg_1)) -
'0';
2374 if ( ((u8)*e_arg_1) - (
unsigned int)
'0' >= 0xA )
2376 e_arg_1_num = (((u8)*e_arg_1)) -
'W';
2377 if ( ((u8)*e_arg_1) - (
unsigned int)
'a' >= 6 )
2380 if ( e_arg_1_num >= curbasex )
2383 curnum = curnum * curbasex + e_arg_1_num;
2391 printf(
"netcnf: \"%s\" line %d: ", e->fname, e->lno);
2392 printf(
"invalid digit (%s)", e_arg);
2402 errret = sceNetCnfName2Address(paddr, buf);
2405 printf(
"netcnf: \"%s\" line %d: ", e->fname, e->lno);
2406 printf(
"sceNetCnfName2Address(%s) -> %d\n", buf, errret);
2414static int do_parse_phone_argument(
sceNetCnfEnv_t *e,
int opt_argc,
const char **opt_argv,
unsigned int *p_result)
2417 unsigned int bitflags1;
2418 unsigned int numval;
2421 for ( i = 0; i < opt_argc; i += 1 )
2423 if ( !strcmp(
"phase", opt_argv[i]) )
2427 else if ( !strcmp(
"cp", opt_argv[i]) )
2431 else if ( !strcmp(
"auth", opt_argv[i]) )
2435 else if ( !strcmp(
"chat", opt_argv[i]) )
2439 else if ( !strcmp(
"private", opt_argv[i]) )
2443 else if ( !strcmp(
"dll", opt_argv[i]) )
2447 else if ( !strcmp(
"dump", opt_argv[i]) )
2451 else if ( !strcmp(
"timer", opt_argv[i]) )
2453 bitflags1 |= 0x10000;
2455 else if ( !strcmp(
"event", opt_argv[i]) )
2457 bitflags1 |= 0x20000;
2459 else if ( do_parse_number(e, opt_argv[i], &numval) )
2462 *p_result = bitflags1;
2466static int do_check_interface_keyword(
2467 sceNetCnfEnv_t *e,
const char *display_name_arg,
const char *attach_ifc_arg,
const char *attach_dev_arg)
2475 cnfpair1->display_name = (u8 *)do_check_e_arg(e, display_name_arg);
2476 if ( !cnfpair1->display_name )
2478 cnfpair1->attach_ifc = (u8 *)do_check_e_arg(e, attach_ifc_arg);
2479 if ( !cnfpair1->attach_ifc )
2481 if ( attach_dev_arg && *attach_dev_arg )
2483 cnfpair1->attach_dev = (u8 *)do_check_e_arg(e, attach_dev_arg);
2484 if ( !cnfpair1->attach_dev )
2487 pair_tail = e->root->pair_tail;
2488 cnfpair1->back = pair_tail;
2491 pair_tail->forw = cnfpair1;
2493 e->root->pair_tail = cnfpair1;
2505 if ( !strcmp(
"add", opt_argv[1]) )
2507 else if ( !strcmp(
"del", opt_argv[1]) )
2512 if ( !nameservermem_1 )
2514 nameservermem_1->cmd.code = addordel;
2515 if ( do_netcnfname2address_wrap(e, opt_argv[2], &nameservermem_1->address) )
2517 nameservermem_1->cmd.back = ifc->cmd_tail;
2518 if ( ifc->cmd_tail )
2519 ifc->cmd_tail->forw = &nameservermem_1->cmd;
2521 ifc->cmd_head = &nameservermem_1->cmd;
2522 nameservermem_1->cmd.forw = 0;
2523 ifc->cmd_tail = &nameservermem_1->cmd;
2535 if ( !strcmp(
"add", opt_argv[1]) )
2537 else if ( !strcmp(
"del", opt_argv[1]) )
2541 route_mem_1 = (
route_t *)do_alloc_mem_inner(e,
sizeof(
route_t), 2);
2545 route_mem_1->cmd.code = addordel;
2546 if ( !strcmp(
"-net", opt_argv[i]) )
2549 route_mem_1->re.flags &= ~2;
2551 else if ( !strcmp(
"-host", opt_argv[i]) )
2554 route_mem_1->re.flags |= 2;
2556 if ( i >= opt_argc )
2558 if ( do_netcnfname2address_wrap(e, 0, &route_mem_1->re.dstaddr) )
2560 if ( do_netcnfname2address_wrap(e, 0, &route_mem_1->re.gateway) )
2562 if ( do_netcnfname2address_wrap(e, 0, &route_mem_1->re.genmask) )
2564 if ( (strcmp(
"default", opt_argv[i])
2565 && do_netcnfname2address_wrap(e, (
const char *)opt_argv[i], &route_mem_1->re.dstaddr)) )
2568 for ( ; i < opt_argc; i += 2 )
2570 if ( !strcmp(
"gw", opt_argv[i]) )
2572 if ( do_netcnfname2address_wrap(e, opt_argv[i + 1], &route_mem_1->re.gateway) )
2574 route_mem_1->re.flags |= 4;
2576 else if ( !strcmp(
"netmask", opt_argv[i]) )
2578 if ( do_netcnfname2address_wrap(e, opt_argv[i + 1], &route_mem_1->re.genmask) )
2582 route_mem_1->cmd.back = ifc->cmd_tail;
2583 if ( ifc->cmd_tail )
2584 ifc->cmd_tail->forw = &route_mem_1->cmd;
2586 ifc->cmd_head = &route_mem_1->cmd;
2587 route_mem_1->cmd.forw = 0;
2588 ifc->cmd_tail = &route_mem_1->cmd;
2596 for ( curentry1 = g_options_attach_cnf; curentry1->m_key; curentry1 += 1 )
2598 switch ( curentry1->m_type )
2603 *((
char *)ifc + curentry1->m_offset) = 0xFF;
2610 *(u32 *)((
char *)ifc + curentry1->m_offset) = 0xFFFFFFFF;
2626 for ( i = 0; i < e->ac; i += 1 )
2628 lenx1 += 3 + strlen(e->av[i]);
2633 cpydst_1 = listtmp + 1;
2634 for ( i = 0; i < e->ac; i += 1 )
2638 cpysz = (
unsigned int)strlen(e->av[i]);
2639 memcpy(cpydst_1, e->av[i], cpysz);
2640 ((
char *)cpydst_1)[cpysz] = 32 * (i < e->ac - 1);
2643 listtmp->back = unknown_list->tail;
2644 if ( unknown_list->tail )
2645 unknown_list->tail->forw = listtmp;
2647 unknown_list->head = listtmp;
2649 unknown_list->tail = listtmp;
2653static int do_check_other_keywords(
2657 unsigned int numval;
2659 wasprefixed = (e->av[0][0] ==
'-') ? 1 : 0;
2660 if ( e->av[0][wasprefixed] )
2662 for ( ; options->m_key && strcmp(&(e->av[0])[wasprefixed], options->m_key); options += 1 )
2664 if ( !options->m_key )
2665 return do_check_args(e, unknown_list);
2666 switch ( options->m_type )
2670 if ( !wasprefixed && (e->ac < 2 || do_parse_number(e, e->av[1], &numval)) )
2672 *((u8 *)cnfdata + options->m_offset) = (u8)numval;
2675 numval = 0xFFFFFFFF;
2676 if ( !wasprefixed && (e->ac < 2 || do_parse_number(e, e->av[1], &numval)) )
2678 *(u32 *)((
char *)cnfdata + options->m_offset) = numval;
2685 if ( !strcmp(
"any", (
const char *)e->av[1]) )
2689 else if ( !strcmp(
"pap", (
const char *)e->av[1]) )
2693 else if ( !strcmp(
"chap", (
const char *)e->av[1]) )
2697 else if ( !strcmp(
"pap/chap", (
const char *)e->av[1]) )
2701 else if ( !strcmp(
"chap/pap", (
const char *)e->av[1]) )
2705 else if ( do_parse_number(e, e->av[1], &numval) )
2709 *((u8 *)cnfdata + options->m_offset) = (u8)numval;
2711 if ( !strcmp(
"want.auth", (
const char *)e->av[0]) )
2712 *((u8 *)cnfdata + 171) = !wasprefixed;
2714 *((u8 *)cnfdata + 247) = !wasprefixed;
2719 if ( e->ac < 2 || do_parse_number(e, e->av[1], &numval) )
2721 *(u32 *)((
char *)cnfdata + options->m_offset) = numval;
2723 if ( !strcmp(
"want.accm", (
const char *)e->av[0]) )
2724 *((u8 *)cnfdata + 170) = !wasprefixed;
2726 *((u8 *)cnfdata + 246) = !wasprefixed;
2729 numval = 0xFFFFFFFF;
2734 if ( !strcmp(
"tone", (
const char *)e->av[1]) )
2738 else if ( !strcmp(
"pulse", (
const char *)e->av[1]) )
2742 else if ( !strcmp(
"any", (
const char *)e->av[1]) )
2746 else if ( do_parse_number(e, e->av[1], &numval) )
2751 *(u32 *)((
char *)cnfdata + options->m_offset) = numval;
2754 numval = 0xFFFFFFFF;
2755 if ( !wasprefixed && do_parse_phone_argument(e, e->ac - 1, (
const char **)&e->av[1], &numval) )
2757 *(u32 *)((
char *)cnfdata + options->m_offset) = numval;
2762 if ( e->ac < 2 || do_parse_number(e, e->av[1], &numval) )
2764 *(u16 *)((
char *)cnfdata + options->m_offset) = (u16)numval;
2766 if ( !strcmp(
"want.mru", (
const char *)e->av[0]) )
2767 *((u8 *)cnfdata + 169) = !wasprefixed;
2769 *((u8 *)cnfdata + 245) = !wasprefixed;
2772 numval = 0xFFFFFFFF;
2777 if ( !strcmp(
"auto", (
const char *)e->av[1]) )
2781 else if ( !strcmp(
"10", (
const char *)e->av[1]) )
2785 else if ( !strcmp(
"10_fd", (
const char *)e->av[1]) )
2789 else if ( !strcmp(
"10_fd_pause", (
const char *)e->av[1]) )
2793 else if ( !strcmp(
"tx", (
const char *)e->av[1]) )
2797 else if ( !strcmp(
"tx_fd", (
const char *)e->av[1]) )
2801 else if ( !strcmp(
"tx_fd_pause", (
const char *)e->av[1]) )
2805 else if ( do_parse_number(e, e->av[1], &numval) )
2810 *(u32 *)((
char *)cnfdata + options->m_offset) = numval;
2813 numval = 0xFFFFFFFF;
2818 if ( !strcmp(
"any", (
const char *)e->av[1]) )
2822 if ( !strcmp(
"eth", (
const char *)e->av[1]) )
2826 else if ( !strcmp(
"ppp", (
const char *)e->av[1]) )
2830 else if ( !strcmp(
"nic", (
const char *)e->av[1]) )
2834 else if ( do_parse_number(e, e->av[1], &numval) )
2839 *(u32 *)((
char *)cnfdata + options->m_offset) = numval;
2842 numval = !wasprefixed;
2843 *((u8 *)cnfdata + options->m_offset) = (u8)numval;
2851 if ( !strcmp(
"no", (
const char *)e->av[1]) )
2855 else if ( !strcmp(
"md5", (
const char *)e->av[1]) )
2859 else if ( !strcmp(
"ms", (
const char *)e->av[1]) )
2863 else if ( !strcmp(
"ms-v1", (
const char *)e->av[1]) )
2867 else if ( !strcmp(
"ms-v2", (
const char *)e->av[1]) )
2871 else if ( do_parse_number(e, e->av[1], &numval) )
2876 *((u8 *)cnfdata + options->m_offset) = (u8)numval;
2885 *(
char **)((
char *)cnfdata + options->m_offset) = do_check_e_arg(e, e->av[1]);
2886 return (!*(
char **)((
char *)cnfdata + options->m_offset)) ? -1 : 0;
2888 *(u32 *)((
char *)cnfdata + options->m_offset) = 0;
2891 return printf(
"netcnf: internal load err (%d, type=%c)\n", 606, options->m_type);
2894 printf(
"netcnf: \"%s\" line %d: ", e->fname, e->lno);
2895 printf(
"ac=%d", e->ac);
2906 wasprefixed = (e->av[0][0] ==
'-') ? 1 : 0;
2907 if ( strcmp(
"interface", &(e->av[0])[wasprefixed]) )
2909 if ( strcmp(
"zero_prefix", &(e->av[0])[wasprefixed]) )
2910 return do_check_other_keywords(e, g_options_net_cnf, e->root, &e->root->unknown_list);
2911 printf(
"netcnf: \"%s\" line %d: ", e->fname, e->lno);
2912 printf(
"obsoleted keyword (%s)", &(e->av[0])[wasprefixed]);
2921 printf(
"netcnf: \"%s\" line %d: ", e->fname, e->lno);
2922 printf(
"ac=%d", e->ac);
2927 return !do_check_interface_keyword(e, e->av[1], e->av[2], (e->ac >= 4) ? e->av[3] : 0) ? 0 : -1;
2930static int do_handle_attach_cnf(
sceNetCnfEnv_t *e,
void *userdata)
2936 wasprefixed = (e->av[0][0] ==
'-') ? 1 : 0;
2937 if ( !strncmp(
"phone_number", &(e->av[0])[wasprefixed], 12) )
2942 if ( e->av[0][wasprefixed + 12] )
2944 if ( !isdigit(e->av[0][wasprefixed + 12]) || e->av[0][wasprefixed + 13] )
2946 keyasnum = e->av[0][wasprefixed + 12] - 48;
2950 ifc->phone_numbers[keyasnum] = 0;
2955 ifc->phone_numbers[keyasnum] = (u8 *)do_check_e_arg(e, e->av[1]);
2956 return (ifc->phone_numbers[keyasnum]) ? 0 : -1;
2959 else if ( !strcmp(
"nameserver", &(e->av[0])[wasprefixed]) )
2962 return do_check_nameserver(e, ifc, e->ac, &e->av[0]);
2964 else if ( !strcmp(
"route", &(e->av[0])[wasprefixed]) )
2967 return do_check_route(e, ifc, e->ac, &e->av[0]);
2969 else if ( !strcmp(
"zero_prefix", &(e->av[0])[wasprefixed]) || !strcmp(
"dial_cnf", &(e->av[0])[wasprefixed]) )
2971 printf(
"netcnf: \"%s\" line %d: ", e->fname, e->lno);
2972 printf(
"obsoleted keyword (%s)", &(e->av[0])[wasprefixed]);
2978 return do_check_other_keywords(e, g_options_attach_cnf, ifc, &ifc->unknown_list);
2989 wasprefixed = (e->av[0][0] ==
'-') ? 1 : 0;
2990 if ( strcmp(
"dialing_type_string", &(e->av[0])[wasprefixed]) )
2991 return do_check_other_keywords(e, g_options_dial_cnf, dial, &dial->unknown_list);
2992 if ( wasprefixed || e->ac < 2 )
2994 dial->tone_dial = (u8 *)do_check_e_arg(e, e->av[1]);
2995 if ( !dial->tone_dial )
2999 dial->pulse_dial = (u8 *)do_check_e_arg(e, e->av[2]);
3000 if ( !dial->pulse_dial )
3004 dial->any_dial = (u8 *)do_check_e_arg(e, e->av[3]);
3005 return dial->any_dial ? 0 : -1;
3014 for ( i = lbuf; e->lbuf < i && i[-1] < 0x21u; i -= 1 )
3017 for ( j = (
char *)e->lbuf; *j && isspace(*j); j += 1 )
3020 while ( *j && e->ac <
'\n' && (u8)*j !=
'#' )
3042 condtmp1 = (*j ==
'"') ? (condtmp1 ? 0 : 1) : (condtmp1 ? 1 : 0);
3045 if ( !condtmp1 && (*j ==
'#' || isspace(*j)) )
3061 for ( ; *j && isspace(*j); j += 1 )
3066 return (e->ac <= 0) ? 0 : readcb(e, userdata);
3069static int do_read_netcnf(
sceNetCnfEnv_t *e,
const char *netcnf_path,
char **netcnf_heap_ptr,
int is_attach_cnf)
3073 result = (!is_attach_cnf || e->f_no_decode) ? do_read_netcnf_no_decode(netcnf_path, netcnf_heap_ptr) :
3074 do_read_netcnf_decode(netcnf_path, netcnf_heap_ptr);
3080static const char *do_handle_netcnf_prerw(
sceNetCnfEnv_t *e,
const char *entry_buffer)
3084 result = do_handle_netcnf_dirname(e->dir_name, entry_buffer, (
char *)e->lbuf);
3085 return (result == (
const char *)e->lbuf) ? do_alloc_mem_for_write(e, result) : result;
3088static int do_netcnf_read_related(
3092 const char *fullpath;
3100 printf(
"netcnf: dir=%s path=%s\n", e->dir_name ? e->dir_name :
"NULL", path ? path :
"NULL");
3101 fullpath = do_handle_netcnf_prerw(e, path);
3106 printf(
"netcnf: reading \"%s\" as ", fullpath);
3107 if ( (
char *)readcb == (
char *)do_handle_net_cnf )
3111 else if ( (
char *)readcb == (
char *)do_handle_attach_cnf )
3113 printf(
"ATTACH_CNF");
3115 else if ( (
char *)readcb == (
char *)do_handle_dial_cnf )
3125 e->fname = fullpath;
3126 read_res1 = do_read_netcnf(e, fullpath, &ptr, readcb == do_handle_attach_cnf);
3127 if ( read_res1 < 0 )
3129 printf(
"netcnf: can't load %s (%d)\n", e->fname, read_res1);
3133 if ( !e->f_no_check_magic && (read_res1 < 36 || strncmp(ptr,
"# <Sony Computer Entertainment Inc.>", 36)) )
3135 printf(
"netcnf: decoding error (magic=\"");
3136 for ( i = 0; i < read_res1 && i < 36; i += 1 )
3138 printf(
"%c", ((u8)ptr[i] - (
unsigned int)
' ' <
'_') ? ((u8)ptr[i]) :
'?');
3141 do_free_heapmem(ptr);
3145 for ( i = 0; i < read_res1; i += 1 )
3147 if ( ptr[i] ==
'\n' )
3150 if ( e->lbuf < lbuf && lbuf[-1] ==
'\\' )
3156 cur_linelen += do_check_line_buffer(e, lbuf, readcb, userdata);
3162 if ( lbuf < &e->lbuf[1023] && ptr[i] !=
'\r' )
3169 if ( e->lbuf < lbuf )
3170 cur_linelen += do_check_line_buffer(e, lbuf, readcb, userdata);
3171 do_free_heapmem(ptr);
3180 e->root->version = 3;
3181 e->root->redial_count = -1;
3182 e->root->redial_interval = -1;
3183 e->root->dialing_type = -1;
3184 return do_netcnf_read_related(e, e->arg_fname, do_handle_net_cnf, 0);
3192 do_init_ifc_inner(e->ifc);
3193 return do_netcnf_read_related(e, e->arg_fname, do_handle_attach_cnf, e->ifc);
3207 for ( i = 0; g_options_attach_cnf[i].m_key; i += 1 )
3209 switch ( g_options_attach_cnf[i].m_type )
3214 typadd1 = *((u8 *)&ncis->type + g_options_attach_cnf[i].m_offset);
3215 if ( typadd1 != 0xFF )
3216 *((u8 *)&ncid->type + g_options_attach_cnf[i].m_offset) = typadd1;
3223 typadd1_1 = *(u32 *)((
char *)&ncis->type + g_options_attach_cnf[i].m_offset);
3224 if ( typadd1_1 != 0xFFFFFFFF )
3225 *(u32 *)((
char *)&ncid->type + g_options_attach_cnf[i].m_offset) = typadd1_1;
3228 if ( !strcmp(
"want.auth", g_options_attach_cnf[i].m_key) )
3230 if ( ncis->want.f_auth )
3232 ncid->want.f_auth = 1;
3233 ncid->want.auth = ncis->want.auth;
3236 else if ( ncis->allow.f_auth )
3238 ncid->allow.f_auth = 1;
3239 ncid->allow.auth = ncis->allow.auth;
3243 if ( !strcmp(
"want.accm", g_options_attach_cnf[i].m_key) )
3245 if ( ncis->want.f_accm )
3247 ncid->want.f_accm = 1;
3248 ncid->want.accm = ncis->want.accm;
3251 else if ( ncis->allow.f_accm )
3253 ncid->allow.f_accm = 1;
3254 ncid->allow.accm = ncis->allow.accm;
3258 if ( !strcmp(
"want.mru", g_options_attach_cnf[i].m_key) )
3260 if ( ncis->want.f_mru )
3262 ncid->want.f_mru = 1;
3263 ncid->want.mru = ncis->want.mru;
3266 else if ( ncis->allow.f_mru )
3268 ncid->allow.f_mru = 1;
3269 ncid->allow.mru = ncis->allow.mru;
3273 typadd1_3 = *(u32 *)((
char *)&ncis->type + g_options_attach_cnf[i].m_offset);
3275 *(u32 *)((
char *)&ncid->type + g_options_attach_cnf[i].m_offset) = typadd1_3;
3281 for ( i = 0; i < 10; i += 1 )
3283 if ( ncis->phone_numbers[i] )
3284 ncid->phone_numbers[i] = ncis->phone_numbers[i];
3296 for ( pair_head = e->root->pair_head; pair_head; pair_head = pair_head->forw )
3300 if ( !pair_head->ctl )
3303 if ( !pair_head->ctl )
3306 if ( !pair_head->ctl->dial )
3309 if ( !pair_head->ctl->dial )
3312 if ( !pair_head->ctl->ifc )
3315 if ( !pair_head->ctl->ifc )
3318 do_init_ifc_inner(pair_head->ctl->ifc);
3319 pair_head->ctl->ifc->chat_additional = e->root->chat_additional;
3320 pair_head->ctl->ifc->redial_count = e->root->redial_count;
3321 pair_head->ctl->ifc->redial_interval = e->root->redial_interval;
3322 pair_head->ctl->ifc->outside_number = e->root->outside_number;
3323 pair_head->ctl->ifc->outside_delay = e->root->outside_delay;
3324 pair_head->ctl->ifc->dialing_type = e->root->dialing_type;
3325 do_dialauth_related(pair_head->ctl->ifc, pair_head->ifc);
3326 type = pair_head->dev->type;
3327 pair_head->dev->type = -1;
3328 do_dialauth_related(pair_head->ctl->ifc, pair_head->dev);
3329 pair_head->dev->type = type;
3346 ifcres1_1 = do_netcnf_dial_related(e);
3351 pair_head = e->root->pair_head;
3354 if ( index(e->arg_fname,
':') )
3355 e->dir_name = e->arg_fname;
3356 for ( ; pair_head; pair_head = pair_head->forw )
3358 if ( pair_head->attach_ifc )
3360 e->arg_fname = (
char *)pair_head->attach_ifc;
3361 ifcres1_1 = do_netcnf_ifc_related(e);
3364 printf(
"netcnf: load_attach ifc(%d)\n", ifcres1_1);
3366 if ( (
unsigned int)(ifcres1_1 + 15) < 2 )
3375 pair_head->ifc = e->ifc;
3382 if ( pair_head->attach_dev )
3384 e->arg_fname = (
char *)pair_head->attach_dev;
3385 ifcres1_1 = do_netcnf_ifc_related(e);
3388 printf(
"netcnf: load_attach dev(%d)\n", ifcres1_1);
3390 if ( (
unsigned int)(ifcres1_1 + 15) < 2 )
3396 pair_head->dev = e->ifc;
3404 return (retres1 == -21) ? -21 : ifcres1_1;
3407 return do_netcnf_ifc_related(e);
3418 return pair->ctl->dial ? do_netcnf_read_related(e, e->arg_fname, do_handle_dial_cnf, pair->ctl->dial) : -2;
3421static int do_netcnf_vsprintf_buffer(
sceNetCnfEnv_t *e,
const char *fmt, va_list va)
3424 void *mem_ptr_rval_04;
3440 void *mem_ptr_rval_02;
3442 void *mem_ptr_rval_03;
3445 void *mem_ptr_rval_01;
3447 char strptr_curchr1;
3470 for ( ; isdigit(*fmt); fmt += 1 )
3472 strlened = 10 * strlened -
'0' + *fmt;
3481 mem_ptr_01 = (
char *)e->mem_ptr;
3482 mem_ptr_rval_04 = mem_ptr_01 + 1;
3483 if ( mem_ptr_01 >= (
char *)e->mem_last )
3485 *mem_ptr_01 = (char)va_arg(va,
int);
3486 e->mem_ptr = mem_ptr_rval_04;
3513 mem_ptr_03 = (
char *)e->mem_ptr;
3514 mem_ptr_rval_04 = mem_ptr_03 + 1;
3515 if ( mem_ptr_03 >= (
char *)e->mem_last )
3518 e->mem_ptr = mem_ptr_rval_04;
3522 if ( fmt_flag_str != -1 )
3524 strptr1 = va_arg(va,
char *);
3531 cur_va1 = va_arg(va,
int);
3532 strptr1 = __builtin_alloca(strpad1 + 1);
3533 strptr1[strpad1] = 0;
3536 if ( *fmt ==
'd' && cur_va1 < 0 )
3544 *strptr1 = ((*fmt ==
'X') ?
"0123456789ABCDEF" :
"0123456789abcdef")[cur_va1 % strpad1];
3552 strlencalc = strlenmax ? (strlened + 1) : strlened;
3553 strlencalc -= strlen(strptr1);
3554 if ( has_sero ==
'0' && strlenmax )
3556 mem_ptr_02 = (
char *)e->mem_ptr;
3557 if ( mem_ptr_02 >= (
char *)e->mem_last )
3560 e->mem_ptr = mem_ptr_02 + 1;
3562 if ( !has_negative )
3564 for ( ; strlencalc > 0; strlencalc -= 1 )
3566 mem_ptr_04 = (
char *)e->mem_ptr;
3567 if ( mem_ptr_04 >= (
char *)e->mem_last )
3569 *mem_ptr_04 = has_sero;
3570 e->mem_ptr = mem_ptr_04 + 1;
3573 if ( has_sero !=
'0' && strlenmax )
3575 mem_ptr_05 = (
char *)e->mem_ptr;
3576 if ( mem_ptr_05 >= (
char *)e->mem_last )
3579 e->mem_ptr = mem_ptr_05 + 1;
3581 if ( fmt_flag_str != 1 )
3583 for ( ; *strptr1; strptr1 += 1 )
3585 strptr_curchr1 = *strptr1;
3586 mem_ptr_06 = (
char *)e->mem_ptr;
3587 if ( mem_ptr_06 >= (
char *)e->mem_last )
3589 *mem_ptr_06 = strptr_curchr1;
3590 e->mem_ptr = mem_ptr_06 + 1;
3595 for ( i = strptr1; *i; i += 1 )
3598 (((u8)*i - 0x81 >= 0x1F) && ((u8)*i - 0xE0 >= 0x1D)) || ((u8)((
int)*i - 64) >= 0xBDu) || (u8)*i == 0x7F )
3600 if ( (u8)*i ==
'"' || (u8)*i ==
'\\' )
3602 mem_ptr_07 = (
char *)e->mem_ptr;
3603 if ( mem_ptr_07 >= (
char *)e->mem_last )
3606 e->mem_ptr = mem_ptr_07 + 1;
3607 mem_ptr_rval_03 = mem_ptr_07 + 2;
3608 if ( mem_ptr_07 + 1 >= (
char *)e->mem_last )
3612 else if ( (u8)*i -
' ' <
'_' )
3614 mem_ptr_08 = (
char *)e->mem_ptr;
3615 mem_ptr_rval_03 = mem_ptr_08 + 1;
3616 if ( mem_ptr_08 >= (
char *)e->mem_last )
3622 mem_ptr_09 = (
char *)e->mem_ptr;
3623 if ( mem_ptr_09 >= (
char *)e->mem_last )
3626 e->mem_ptr = mem_ptr_09 + 1;
3627 if ( mem_ptr_09 + 1 >= (
char *)e->mem_last )
3629 mem_ptr_09[1] =
'x';
3630 e->mem_ptr = mem_ptr_09 + 2;
3631 mem_ptr_rval_01 = mem_ptr_09 + 3;
3632 if ( mem_ptr_09 + 2 >= (
char *)e->mem_last )
3634 mem_ptr_09[2] = (
"0123456789abcdef")[(u8)*i >> 4];
3635 e->mem_ptr = mem_ptr_rval_01;
3636 mem_ptr_rval_03 = mem_ptr_09 + 4;
3637 if ( (
char *)mem_ptr_rval_01 >= (
char *)e->mem_last )
3639 mem_ptr_09[3] = (
"0123456789abcdef")[(u8)*i & 0xF];
3644 mem_ptr_0a = (
char *)e->mem_ptr;
3645 mem_ptr_rval_02 = mem_ptr_0a + 1;
3646 if ( mem_ptr_0a >= (
char *)e->mem_last )
3649 e->mem_ptr = mem_ptr_rval_02;
3652 if ( (
char *)mem_ptr_rval_02 >= (
char *)e->mem_last )
3654 mem_ptr_rval_03 = mem_ptr_0a + 2;
3655 mem_ptr_0a[1] = i_curchr2;
3657 e->mem_ptr = mem_ptr_rval_03;
3660 for ( ; has_negative && strlencalc > 0; strlencalc -= 1 )
3662 if ( (
char *)e->mem_ptr >= (
char *)e->mem_last )
3664 *((
char *)e->mem_ptr) =
' ';
3665 e->mem_ptr = ((
char *)e->mem_ptr) + 1;
3671 mem_ptr_03 = (
char *)e->mem_ptr;
3672 mem_ptr_rval_04 = mem_ptr_03 + 1;
3673 if ( mem_ptr_03 >= (
char *)e->mem_last )
3676 e->mem_ptr = mem_ptr_rval_04;
3683static int do_netcnf_sprintf_buffer(
sceNetCnfEnv_t *e,
const char *fmt, ...)
3689 retval = do_netcnf_vsprintf_buffer(e, fmt, va);
3697 unsigned int offsptr6;
3698 unsigned int offsptr4;
3701 for ( ; options->m_key; options += 1 )
3703 unsigned int offsptr3;
3709 lbuf = (
const char *)e->lbuf;
3710 switch ( options->m_type )
3713 if ( *((u8 *)cnfdata + options->m_offset) == 255 )
3718 result = do_netcnf_sprintf_buffer(e,
"%s %d\n", options->m_key, *((u8 *)cnfdata + options->m_offset));
3722 offsptr1 = (
char *)cnfdata + options->m_offset;
3723 if ( *(
int *)offsptr1 < 0 )
3728 result = do_netcnf_sprintf_buffer(e,
"%s %d\n", options->m_key, *(u32 *)offsptr1);
3732 if ( !strcmp(
"want.auth", options->m_key) ? !*((u8 *)cnfdata + 171) : !*((u8 *)cnfdata + 247) )
3737 offsptr3 = (u32)(s32) * ((
char *)cnfdata + options->m_offset);
3760 if ( !strcmp(
"want.accm", options->m_key) ? !*((u8 *)cnfdata + 170) : !*((u8 *)cnfdata + 246) )
3766 do_netcnf_sprintf_buffer(e,
"%s 0x%08x\n", options->m_key, *(u32 *)((
char *)cnfdata + options->m_offset));
3770 offsptr3 = *(u32 *)((
char *)cnfdata + options->m_offset);
3790 offsptr4 = *(u32 *)((
char *)cnfdata + options->m_offset);
3791 if ( offsptr4 == 0xFFFFFFFF )
3796 result = do_netcnf_sprintf_buffer(e,
"%s", options->m_key);
3799 for ( i = 0; i < 32; i += 1 )
3802 switch ( ((u32)1 << i) & offsptr4 )
3836 offsptr4 &= ~((u32)1 << i);
3837 result = do_netcnf_sprintf_buffer(e,
" %s", lbuf);
3844 result = do_netcnf_sprintf_buffer(e,
" 0x%x", offsptr4);
3848 result = do_netcnf_sprintf_buffer(e,
"\n");
3852 if ( !strcmp(
"want.mru", options->m_key) ? !*((u8 *)cnfdata + 169) : !*((u8 *)cnfdata + 245) )
3857 result = do_netcnf_sprintf_buffer(e,
"%s %d\n", options->m_key, *(u16 *)((
char *)cnfdata + options->m_offset));
3861 offsptr3 = *(u32 *)((
char *)cnfdata + options->m_offset);
3877 lbuf =
"10_fd_pause";
3886 lbuf =
"tx_fd_pause";
3893 offsptr3 = *(u32 *)((
char *)cnfdata + options->m_offset);
3916 if ( *((u8 *)cnfdata + options->m_offset) == 255 )
3921 result = do_netcnf_sprintf_buffer(e,
"%s%s\n", *((u8 *)cnfdata + options->m_offset) ?
"" :
"-", options->m_key);
3925 offsptr3 = (u32)(s32) * ((
char *)cnfdata + options->m_offset);
3948 offsptr6 = *(u32 *)((
char *)cnfdata + options->m_offset);
3954 result = do_netcnf_sprintf_buffer(e,
"%s \"%S\"\n", options->m_key, offsptr6);
3958 return printf(
"netcnf: internal save error (%d, type=%c)\n", 302, options->m_type);
3962 if ( (
const char *)e->lbuf == (
const char *)lbuf )
3964 sprintf((
char *)e->lbuf,
"0x%x", offsptr3);
3966 result = do_netcnf_sprintf_buffer(e,
"%s %s\n", options->m_key, lbuf);
3979 for ( cmd_head = ifc->cmd_head; cmd_head; cmd_head = cmd_head->forw )
3983 nameserverflag = -1;
3984 switch ( cmd_head->code )
3994 result = do_netcnf_sprintf_buffer(e,
"route add -%s", (((
route_t *)cmd_head)->re.flags & 2) ?
"host" :
"net");
3997 if ( sceNetCnfAddress2String((
char *)e->lbuf,
sizeof(e->lbuf), &((
route_t *)cmd_head)->re.dstaddr) )
3999 result = do_netcnf_sprintf_buffer(e,
" %s", (
const char *)e->lbuf);
4002 if ( (((
route_t *)cmd_head)->re.flags & 4) )
4004 if ( sceNetCnfAddress2String((
char *)e->lbuf,
sizeof(e->lbuf), &((
route_t *)cmd_head)->re.gateway) )
4006 result = do_netcnf_sprintf_buffer(e,
" gw %s", (
const char *)e->lbuf);
4010 if ( sceNetCnfAddress2String((
char *)e->lbuf,
sizeof(e->lbuf), &((
route_t *)cmd_head)->re.genmask) )
4012 result = do_netcnf_sprintf_buffer(e,
" netmask %s", (
const char *)e->lbuf);
4015 result = do_netcnf_sprintf_buffer(e,
"\n");
4022 if ( sceNetCnfAddress2String((
char *)e->lbuf,
sizeof(e->lbuf), &((
route_t *)cmd_head)->re.dstaddr) )
4024 result = do_netcnf_sprintf_buffer(e,
"route del %s\n", (
const char *)e->lbuf);
4032 if ( nameserverflag != -1 )
4034 if ( sceNetCnfAddress2String((
char *)e->lbuf,
sizeof(e->lbuf), &((
nameserver_t *)cmd_head)->address) )
4036 result = do_netcnf_sprintf_buffer(e,
"nameserver %s %s\n", nameserverflag ?
"add" :
"del", (
const char *)e->lbuf);
4049 for ( i = 0; i < (int)(
sizeof(ifc->phone_numbers) /
sizeof(ifc->phone_numbers[0])); i += 1 )
4051 if ( ifc->phone_numbers[i] )
4053 result = do_netcnf_sprintf_buffer(e,
"phone_number%d \"%S\"\n", i, ifc->phone_numbers[i]);
4065 for ( head = unknown_list->head; head; head = head->forw )
4069 result = do_netcnf_sprintf_buffer(e,
"%s\n", (
const char *)&head[1]);
4076static int do_write_netcnf(
sceNetCnfEnv_t *e,
const char *path,
int is_attach_cnf)
4079 const char *fullpath;
4081 memsize = (int)((
char *)e->mem_ptr - (
char *)e->mem_base);
4083 printf(
"netcnf: dir=%s path=%s\n", e->dir_name ? e->dir_name :
"NULL", path ? path :
"NULL");
4084 fullpath = do_handle_netcnf_prerw(e, path);
4089 printf(
"netcnf: writing \"%s\" as ", fullpath);
4090 if ( is_attach_cnf )
4091 printf(
"ATTACH_CNF");
4096 if ( !is_attach_cnf || e->f_no_decode )
4101 fd = do_open_netcnf(fullpath, 1538, 511);
4105 return (fd == -
EIO) ? -18 : -3;
4107 writeres = do_write_netcnf_no_encode(fd, e->mem_base, memsize);
4108 if ( memsize != writeres )
4111 do_close_netcnf(fd);
4112 return (writeres == -
EIO) ? -18 : -5;
4114 do_close_netcnf(fd);
4118 if ( do_write_netcnf_encode(fullpath, e->mem_base, memsize) < 0 )
4133 memalign = (
void *)(((uiptr)e->mem_base + 3) & (uiptr)~3);
4134 e->mem_base = memalign;
4135 e->mem_ptr = memalign;
4136 result = do_netcnf_sprintf_buffer(e,
"%s\n\n",
"# <Sony Computer Entertainment Inc.>");
4141 result = do_netcnf_other_write(e, g_options_attach_cnf, ifc);
4144 result = do_netcnf_phone_write(e, ifc);
4147 result = do_netcnf_net_write(e, ifc);
4150 result = do_netcnf_unknown_write(e, &ifc->unknown_list);
4153 return do_write_netcnf(e, arg_fname, 1);
4155 for ( pair_head = e->root->pair_head; pair_head; pair_head = pair_head->forw )
4157 result = do_netcnf_sprintf_buffer(
4158 e,
"interface \"%S\" \"%S\" \"%S\"\n", pair_head->display_name, pair_head->attach_ifc, pair_head->attach_dev);
4162 result = do_netcnf_other_write(e, g_options_net_cnf, e->root);
4165 result = do_netcnf_unknown_write(e, &e->root->unknown_list);
4168 return do_write_netcnf(e, arg_fname, 0);
4173 return ((e->req != 1 && e->req != 2) || do_export_netcnf_inner(e, e->arg_fname, (e->req == 1) ? 0 : e->ifc)) ? -1 : 0;
4176static char *do_address_to_string_inner_element(
char *dst,
int srcbyte)
4181 tmpstk_ptr = tmpstk;
4188 for ( ; srcbyte > 0; srcbyte /= 10 )
4190 *tmpstk_ptr = srcbyte % 10 +
'0';
4193 for ( ; tmpstk < tmpstk_ptr; tmpstk_ptr -= 1 )
4195 *dst = tmpstk_ptr[-1];
4201static void do_address_to_string_inner(
char *dst,
unsigned int srcint)
4205 elm1 = do_address_to_string_inner_element(dst, (srcint >> 24) & 0xFF);
4207 elm1 = do_address_to_string_inner_element(elm1 + 1, (srcint >> 16) & 0xFF);
4209 elm1 = do_address_to_string_inner_element(elm1 + 1, (srcint >> 8) & 0xFF);
4211 elm1 = do_address_to_string_inner_element(elm1 + 1, srcint & 0xFF);
4215static int do_name_2_address_inner(
unsigned int *dst,
const char *buf)
4220 unsigned int tmpstk1[4];
4223 for ( prefixchkn = 0; prefixchkn < (int)(
sizeof(tmpstk1) /
sizeof(tmpstk1[0])); prefixchkn += 1 )
4232 if ( *buf ==
'x' || *buf ==
'X' )
4238 for ( i = 0; isxdigit(*buf); i = i * base + (
unsigned int)offsbase1 )
4240 offsbase1 = *buf -
'0';
4241 if ( !isdigit(*buf) )
4243 offsbase1 = *buf -
'7';
4244 if ( !isupper(*buf) )
4245 offsbase1 = *buf -
'W';
4247 if ( offsbase1 >= (
int)base )
4251 if ( prefixchkn > 0 && (
unsigned int)tmpstk1[prefixchkn - 1] >= 0x100 )
4253 tmpstk1[prefixchkn] = i;
4258 if ( *buf && *buf !=
' ' )
4260 switch ( prefixchkn )
4267 i |= tmpstk1[0] << 24;
4272 i |= (tmpstk1[0] << 24) | (tmpstk1[1] << 16);
4277 i |= (tmpstk1[0] << 24) | (tmpstk1[1] << 16) | (tmpstk1[2] << 8);
4286static int do_conv_a2s_inner(
char *sp_,
char *dp_,
int len)
4288 int len_minus_three;
4294 len_minus_three = len - 3;
4296 if ( len_minus_three <= 0 )
4299 dp_ptroffs1 = dp_ + 1;
4303 dp_ptroffs2 = dp_ptroffs1 + 1;
4306 for ( ; *sp_ ==
' ' || *sp_ ==
'\t'; sp_ += 1 )
4310 if ( (*sp_ !=
'A' && *sp_ !=
'a') || (sp_[1] !=
'T' && sp_[1] !=
't') )
4312 for ( ; *sp_ && *sp_ !=
' ' && *sp_ !=
'\t'; sp_ += 1 )
4314 len_minus_three -= 1;
4315 if ( len_minus_three <= 0 )
4317 if ( *sp_ ==
'-' || *sp_ ==
'\\' || *sp_ ==
'"' || *sp_ ==
'^' )
4319 len_minus_three -= 1;
4320 if ( len_minus_three <= 0 )
4322 *dp_ptroffs2 =
'\\';
4325 *dp_ptroffs2 = *sp_;
4328 len_minus_three -= 4;
4329 if ( len_minus_three <= 0 )
4332 dp_ptroffs3 = dp_ptroffs2 + 1;
4338 dp_ptroffs2 = dp_ptroffs3 + 1;
4341 if ( curindx1 <= 0 )
4343 if ( (len_minus_three - 2) <= 0 )
4345 strcpy(dp_ptroffs2,
"\\c");
4349static int do_conv_s2a_inner(
char *sp_,
char *dp_,
int len)
4352 char *sp_minus_one1;
4359 for ( ; *sp_ ==
' ' || *sp_ ==
'\t'; sp_ += 1 )
4361 sp_minus_one1 = sp_;
4362 if ( *sp_minus_one1 !=
'"' || sp_minus_one1[1] !=
'"' || (sp_minus_one1[2] !=
' ' && sp_minus_one1[2] !=
'\t') )
4364 sp_ptroffs1 = sp_minus_one1 + 3;
4367 for ( ; *sp_ptroffs1 ==
' ' || *sp_ptroffs1 ==
'\t'; sp_ptroffs1 += 1 )
4369 sp_ptroffs2 = sp_ptroffs1;
4370 if ( !*sp_ptroffs2 || *sp_ptroffs2 ==
'\\' )
4372 if ( *sp_ptroffs2 !=
'\\' || sp_ptroffs2[1] !=
'c' )
4374 sp_ptroffs4 = sp_ptroffs2 + 2;
4375 for ( ; *sp_ptroffs4 ==
' ' || *sp_ptroffs4 ==
'\t'; sp_ptroffs4 += 1 )
4379 if ( curindx1 <= 0 )
4381 if ( (
int)(len - 1) < 0 )
4386 if ( (*sp_ptroffs2 !=
'A' && *sp_ptroffs2 !=
'a') || (sp_ptroffs2[1] !=
'T' && sp_ptroffs2[1] !=
't') )
4397 if ( (sp_ptroffs2[-1]) !=
' ' )
4400 while ( *sp_ptroffs2 !=
'\t' )
4405 if ( *sp_ptroffs2 ==
'\\' )
4407 if ( sp_ptroffs2[1] !=
'-' && sp_ptroffs2[1] !=
'\\' && sp_ptroffs2[1] !=
'"' && sp_ptroffs2[1] !=
'^' )
4411 *dp_ = *sp_ptroffs2;
4414 if ( !*sp_ptroffs2 || *sp_ptroffs2 ==
' ' )
4418 for ( ; *sp_ptroffs2 ==
' ' || *sp_ptroffs2 ==
'\t'; sp_ptroffs2 += 1 )
4420 sp_ptroffs3 = sp_ptroffs2;
4421 if ( *sp_ptroffs3 !=
'O' || sp_ptroffs3[1] !=
'K' || (sp_ptroffs3[2] !=
' ' && sp_ptroffs3[2] !=
'\t') )
4423 sp_ptroffs1 = sp_ptroffs3 + 3;
4428static int do_check_aolnet(
const char *auth_name)
4431 const char *periodpos;
4433 if ( strncmp(auth_name,
"aolnet/", 7) )
4435 periodpos = auth_name;
4436 for ( i = 0; periodpos; i += 1 )
4438 periodpos = strchr(periodpos,
'.');
4442 return (i != 5) ? 0 : -20;
4445static int do_check_authnet(
char *argst,
char *arged)
4450 for ( i = arged; argst < i && i[-1] <
'!'; i -= 1 )
4453 for ( j = argst; *j && isspace(*j); j += 1 )
4455 if ( !strncmp(j,
"auth_name", 9) )
4459 for ( ; *j && !isspace(*j); j += 1 )
4461 for ( ; *j && isspace(*j); j += 1 )
4465 result = do_check_aolnet(j);
4472static int do_read_check_netcnf(
const char *netcnf_path,
int type,
int no_check_magic,
int no_decode)
4490 read_res2 = no_decode ? do_read_netcnf_no_decode(netcnf_path, &g_read_check_netcnf_heapptr) :
4491 do_read_netcnf_decode(netcnf_path, &g_read_check_netcnf_heapptr);
4492 if ( read_res2 < 0 )
4494 heapmem = (
char *)do_alloc_heapmem(1024);
4498 do_free_heapmem(g_read_check_netcnf_heapptr);
4501 curheapptr1 = g_read_check_netcnf_heapptr;
4502 heapmem_2 = heapmem;
4505 && (read_res2 < 36 || strncmp(g_read_check_netcnf_heapptr,
"# <Sony Computer Entertainment Inc.>", 36)) )
4509 printf(
"netcnf: decoding error (magic=\"");
4510 for ( i = 0; i < read_res2 && i < 36; i += 1 )
4512 printf(
"%c", (
unsigned int)((u8)curheapptr1[i] - 32) >= 0x5F ?
'?' : (
char)(u8)curheapptr1[i]);
4517 if ( !errretres && read_res2 > 0 )
4520 for ( ; read_res2 > 0; read_res2 -= 1 )
4522 if ( *curheapptr1 ==
'\n' )
4524 if ( heapmem < heapmem_2 && heapmem_2[-1] ==
'\\' )
4531 errretres = do_check_authnet(heapmem, heapmem_2);
4532 heapmem_2 = heapmem;
4533 if ( errretres < 0 )
4539 if ( heapmem_2 < &heapmem[1023] && *curheapptr1 !=
'\r' )
4541 *heapmem_2 = *curheapptr1;
4548 if ( !errretres && heapmem < heapmem_2 )
4549 errretres = do_check_authnet(heapmem, heapmem_2);
4550 do_free_heapmem(g_read_check_netcnf_heapptr);
4551 do_free_heapmem(heapmem);
4555static int do_check_provider_inner(
const sceNetCnfEnv_t *e,
int type)
4564 if ( !e || !e->ifc )
4566 if ( e->ifc->auth_name )
4570 result = do_check_aolnet((
const char *)e->ifc->auth_name);
4581static const char *do_handle_netcnf_dirname(
const char *fpath,
const char *entry_buffer,
char *netcnf_file_path)
4583 const char *entry_buffer_1;
4584 const char *fpath_1;
4585 const char *fpath_1_minus_1;
4586 const char *fpath_2;
4588 const char *entry_buffer_2;
4590 if ( !entry_buffer || !*entry_buffer )
4592 for ( entry_buffer_1 = entry_buffer; *entry_buffer_1; entry_buffer_1 += 1 )
4594 if ( *entry_buffer_1 ==
':' )
4595 return entry_buffer;
4597 if ( !fpath || !*fpath )
4598 return entry_buffer;
4599 for ( fpath_1 = fpath; fpath_1[1]; fpath_1 += 1 )
4601 fpath_1_minus_1 = fpath_1 - 1;
4602 if ( fpath < fpath_1_minus_1 || *entry_buffer ==
'/' || *entry_buffer ==
'\\' )
4604 for ( ; fpath < fpath_1_minus_1 && *fpath_1_minus_1 !=
':'; fpath_1_minus_1 -= 1 )
4606 if ( fpath <= fpath_1_minus_1 && (*fpath_1_minus_1 ==
':' || *fpath_1_minus_1 ==
'/' || *fpath_1_minus_1 ==
'\\') )
4608 fpath_1_minus_1 += 1;
4611 else if ( fpath <= fpath_1_minus_1 && *fpath_1_minus_1 !=
':' )
4613 for ( ; fpath < fpath_1_minus_1 && *fpath_1_minus_1 !=
':' && *fpath_1_minus_1 !=
'/' && *fpath_1_minus_1 !=
'\\';
4614 fpath_1_minus_1 -= 1 )
4616 if ( *fpath_1_minus_1 ==
':' || *fpath_1_minus_1 ==
'/' || *fpath_1_minus_1 ==
'\\' )
4618 fpath_1_minus_1 += 1;
4622 for ( i = netcnf_file_path; fpath_2 < fpath_1_minus_1; i += 1 )
4627 for ( entry_buffer_2 = entry_buffer; *entry_buffer_2; entry_buffer_2 += 1 )
4629 *i = *entry_buffer_2;
4633 return netcnf_file_path;
4636static int do_get_filesize_inner(
int fd)
4639 int lseek_start_res;
4641 lseek_end_res = lseek(fd, 0, 2);
4642 if ( lseek_end_res < 0 )
4643 return (lseek_end_res != -
EIO) ? -6 : -18;
4644 lseek_start_res = lseek(fd, 0, 0);
4645 return (lseek_start_res < 0) ? ((lseek_start_res != -
EIO) ? -6 : -18) : lseek_end_res;
4648static int is_special_file_path(
const char *netcnf_path)
4650 switch ( g_callbacks.type )
4653 return !strncmp(netcnf_path,
"mc", 2) ? 1 : 0;
4655 return !strncmp(netcnf_path,
"ext", 3) ? 1 : 0;
4661static void do_init_callback_handles(
void)
4665 for ( i = 0; i < (int)(
sizeof(g_callback_handle_infos) /
sizeof(g_callback_handle_infos[0])); i += 1 )
4667 g_callback_handle_infos[i].m_fd = -1;
4668 g_callback_handle_infos[i].m_filesize = 0;
4669 g_callback_handle_infos[i].m_allocstate = 0;
4673static int do_get_empty_callback_handle(
int in_fd,
int in_allocstate)
4677 for ( i = 0; i < (int)(
sizeof(g_callback_handle_infos) /
sizeof(g_callback_handle_infos[0])); i += 1 )
4679 if ( g_callback_handle_infos[i].m_fd == -1 )
4681 g_callback_handle_infos[i].m_fd = in_fd;
4682 g_callback_handle_infos[i].m_allocstate = in_allocstate;
4683 g_open_callback_handle_count += 1;
4690static int do_filesize_callback_handles(
int in_fd,
int in_allocstate)
4694 for ( i = 0; i < (int)(
sizeof(g_callback_handle_infos) /
sizeof(g_callback_handle_infos[0])); i += 1 )
4697 g_callback_handle_infos[i].m_fd == in_fd
4698 && (g_callback_handle_infos[i].m_allocstate == in_allocstate || !in_allocstate) )
4706static void do_clear_callback_handles(
int fd,
int allocmatch)
4710 for ( i = 0; i < (int)(
sizeof(g_callback_handle_infos) /
sizeof(g_callback_handle_infos[0])); i += 1 )
4712 if ( g_callback_handle_infos[i].m_fd == fd && g_callback_handle_infos[i].m_allocstate == allocmatch )
4714 g_callback_handle_infos[i].m_fd = -1;
4715 g_callback_handle_infos[i].m_allocstate = 0;
4716 g_open_callback_handle_count -= 1;
4722static const char *do_colon_callback_handles(
const char *netcnf_path,
char *device)
4727 index_res = index(netcnf_path,
':');
4730 devnameend = (u32)(
int)(index_res - netcnf_path) + 1;
4731 if ( devnameend >= 17 )
4733 memcpy(device, netcnf_path, (u32)devnameend);
4734 device[devnameend] = 0;
4735 return (strlen(index_res + 1) + 1 < 257) ? (index_res + 1) : 0;
4738static int do_open_netcnf(
const char *netcnf_path,
int file_flags,
int file_mode)
4742 int empty_callback_handle;
4743 char pathconcat[16];
4746 if ( !g_callbacks.open || !is_special_file_path(netcnf_path) )
4747 return open(netcnf_path, file_flags, file_mode);
4748 if ( g_open_callback_handle_count >= (
int)(
sizeof(g_callback_handle_infos) /
sizeof(g_callback_handle_infos[0])) )
4750 cbind = do_colon_callback_handles(netcnf_path, pathconcat);
4753 openret1 = g_callbacks.open(pathconcat, cbind, file_flags, file_mode, &filesz1);
4756 empty_callback_handle = do_get_empty_callback_handle(openret1, 1);
4757 strcpy(g_callback_handle_infos[empty_callback_handle].m_device, pathconcat);
4758 strcpy(g_callback_handle_infos[empty_callback_handle].m_pathname, cbind);
4759 g_callback_handle_infos[empty_callback_handle].m_buf = 0;
4760 g_callback_handle_infos[empty_callback_handle].m_bufpos = 0;
4761 g_callback_handle_infos[empty_callback_handle].m_filesize = filesz1;
4765static int do_read_callback_handles(
int handlefd,
int fd,
void *ptr,
int size)
4769 cbh = &g_callback_handle_infos[handlefd];
4770 if ( !cbh->m_bufpos )
4772 cbh->m_buf = do_alloc_heapmem(cbh->m_filesize);
4775 if ( g_callbacks.read(fd, cbh->m_device, cbh->m_pathname, cbh->m_buf, 0, cbh->m_filesize) != cbh->m_filesize )
4777 do_free_heapmem(cbh->m_buf);
4782 memcpy(ptr, (
char *)cbh->m_buf + cbh->m_bufpos, (u32)size);
4783 cbh->m_bufpos += size;
4787static int do_readfile_netcnf(
int fd,
void *ptr,
int size)
4791 if ( !g_callbacks.read )
4792 return read(fd, ptr, size);
4793 cbind = do_filesize_callback_handles(fd, 1);
4794 return (cbind == -1) ? read(fd, ptr, size) : do_read_callback_handles(cbind, fd, ptr, size);
4797static int do_write_netcnf_no_encode(
int fd,
void *ptr,
int size)
4799 if ( !g_callbacks_set || g_callbacks.type == 2 )
4800 return write(fd, ptr, size);
4801 printf(
"[err] netcnf write()\n");
4805static int do_dopen_wrap(
const char *fn)
4807 if ( !g_callbacks_set || g_callbacks.type == 2 )
4816 printf(
"[err] netcnf dopen()\n");
4822 if ( !g_callbacks_set || g_callbacks.type == 2 )
4825 return dread(fn, buf);
4832 printf(
"[err] netcnf dread()\n");
4836static int do_remove_wrap(
const char *fn)
4838 if ( !g_callbacks_set || g_callbacks.type == 2 )
4840 printf(
"[err] netcnf remove()\n");
4844static void do_close_netcnf(
int fd)
4848 if ( !g_callbacks.close )
4853 cbind = do_filesize_callback_handles(fd, 1);
4859 g_callbacks.close(fd);
4860 do_free_heapmem(g_callback_handle_infos[cbind].m_buf);
4861 g_callback_handle_infos[cbind].m_buf = 0;
4862 do_clear_callback_handles(fd, 1);
4865static void do_dclose_wrap(
int fd)
4867 if ( !g_callbacks_set || g_callbacks.type == 2 )
4876 printf(
"[err] netcnf dclose()\n");
4879static int do_filesize_netcnf(
int fd)
4883 cbind = do_filesize_callback_handles(fd, 0);
4884 return (cbind == -1) ? do_get_filesize_inner(fd) : g_callback_handle_infos[cbind].m_filesize;
4887static void do_getstat_wrap(
const char *fn,
iox_stat_t *stx)
4889 if ( !g_callbacks_set || g_callbacks.type == 2 )
4898 stx->size = (
unsigned int)(
int)st.st_size;
4903 printf(
"[err] netcnf getstat()\n");
4906static void do_chstat_mode_copyprotect_wrap(
const char *fn)
4912 if ( !g_callbacks_set || g_callbacks.type == 2 )
4915 do_getstat_wrap(fn, &statmode);
4916 statmode.mode |= 8u;
4917 chstat(fn, &statmode, 1u);
4923 printf(
"[err] netcnf chstat()\n");
4930 g_callbacks.type = pcallback->type;
4931 g_callbacks.open = pcallback->open;
4932 g_callbacks.read = pcallback->read;
4933 g_callbacks.close = pcallback->close;
4934 g_callbacks_set = 1;
4938 memset(&g_callbacks, 0,
sizeof(g_callbacks));
4939 g_callbacks_set = 0;
4941 do_init_callback_handles();
4945static int do_init_heap(
void)
4947 if ( g_netcnf_heap )
4949 g_netcnf_heap = CreateHeap(1024, 1);
4950 return g_netcnf_heap ? 0 : -1;
4954static void *do_alloc_heapmem(
int nbytes)
4957 return AllocHeapMemory(g_netcnf_heap, nbytes);
4959 return malloc((
size_t)nbytes);
4963static void do_free_heapmem(
void *ptr)
4967 FreeHeapMemory(g_netcnf_heap, ptr);
4975static void do_delete_heap(
void)
4977 DeleteHeap(g_netcnf_heap);
int sceCdRI(u8 *buffer, u32 *result)