11#include "irx_imports.h"
14IRX_ID(
"Netcnf_Interface", 2, 30);
33 char dhcp_host_name[256];
37 char dns1_address[256];
38 char dns2_address[256];
39 char phone_numbers1[256];
40 char phone_numbers2[256];
41 char phone_numbers3[256];
47 char chat_additional[256];
48 char outside_number[256];
49 char outside_delay[256];
81 char new_usr_name[256];
84static void sceNetcnfifInterfaceStart(
void *userdata);
85static void sceNetcnfifInterfaceStop(
void);
86static void sceNetcnfifDataInit(sceNetcnfifData_t *data);
87static void sceNetcnfifEnvInit(
sceNetCnfEnv_t *env,
void *mem_area,
int size,
int f_no_decode);
88static int sceNetcnfifReadEnv(sceNetcnfifData_t *data,
sceNetCnfEnv_t *e,
int type);
89static int sceNetcnfifWriteEnv(
sceNetCnfEnv_t *e, sceNetcnfifData_t *data,
int type);
90static int sceNetcnfifSendEE(
unsigned int data,
unsigned int addr,
unsigned int size);
91static int sceNetcnfifDmaCheck(
int id);
92static void sce_callback_initialize(
void);
93static int sce_callback_open(
const char *device,
const char *pathname,
int flags,
int mode,
int *filesize);
94static int sce_callback_read(
int fd,
const char *device,
const char *pathname,
void *buf,
int offset,
int size);
95static int sce_callback_close(
int fd);
96static int my_create_heap(
void);
97static void *my_alloc(
int size);
98static void my_free(
void *ptr);
99static void my_delete_heap(
void);
103static void *mem_area;
105static int mem_area_size;
110static sceNetcnfifData_t data;
111static char dp[0x100];
112static int rpc_buf[1024];
121static int gbuf[1024];
123static void usage(
void)
125 printf(
"Usage: netcnfif <option>\n");
126 printf(
" <option>:\n");
127 printf(
" thpri=<digit> - set thread priority\n");
128 printf(
" thstack=<digit>KB - set thread stack size(Kbyte)\n");
129 printf(
" thstack=<digit> - set thread stack size(byte)\n");
130 printf(
" -help - print usage\n");
133static int module_start(
int argc,
char *argv[],
void *startaddr,
ModuleInfo_t *mi)
146 for ( i = 1; i < argc; i += 1 )
151 if ( !strncmp(
"thpri=", argv[i], 6) )
154 if ( !isdigit(argv[i][bp]) )
157 return MODULE_NO_RESIDENT_END;
159 thpri = strtol(&argv[i][bp], 0, 10);
160 if ( (
unsigned int)(thpri - 9) >= 0x73 )
163 return MODULE_NO_RESIDENT_END;
165 for ( ; argv[i][bp] && isdigit(argv[i][bp]); bp += 1 )
172 else if ( !strncmp(
"thstack=", argv[i], 8) )
175 if ( !isdigit(argv[i][bp]) )
178 return MODULE_NO_RESIDENT_END;
180 thstack = strtol(&argv[i][bp], 0, 10);
181 for ( ; argv[i][bp] && isdigit(argv[i][bp]); bp += 1 )
183 if ( !strcmp(&argv[i][bp],
"KB") )
192 return MODULE_NO_RESIDENT_END;
194 if ( xflg && argv[i][bp] )
197 return MODULE_NO_RESIDENT_END;
200 retres1 = RegisterLibraryEntries(&_exp_netcnfif);
203 printf(
"netcnfif: RegisterLibraryEntries(%d)\n", retres1);
204 return MODULE_NO_RESIDENT_END;
206 retres2 = my_create_heap();
209 th_param.attr = TH_C;
210 th_param.thread = sceNetcnfifInterfaceStart;
211 th_param.priority = thpri;
212 th_param.stacksize = thstack;
214 g_tid = CreateThread(&th_param);
219 retres3 = StartThread(g_tid, 0);
223 return MODULE_REMOVABLE_END;
225 if ( mi && ((mi->
newflags & 2) != 0) )
227 return MODULE_RESIDENT_END;
230 printf(
"netcnfif: s_thread(%d)\n", retres3);
231 TerminateThread(g_tid);
236 printf(
"netcnfif: c_thread(%d)\n", g_tid);
242 printf(
"netcnfif: c_heap(%d)\n", retres2);
244 ReleaseLibraryEntries(&_exp_netcnfif);
245 return MODULE_NO_RESIDENT_END;
248static int module_stop(
void)
250 sceNetcnfifInterfaceStop();
251 TerminateThread(g_tid);
254 ReleaseLibraryEntries(&_exp_netcnfif);
255 return MODULE_NO_RESIDENT_END;
258int _start(
int ac,
char *av[],
void *startaddr,
ModuleInfo_t *mi)
260 return (ac >= 0) ? module_start(ac, av, startaddr, mi) : module_stop();
263static void *sceNetcnfifInterfaceServer(
int fno,
sceNetcnfifArg_t *buf,
int size)
267 sceNetcnfifList_t *list_ee;
277 retres1 = sceNetCnfGetCount(buf->fname, buf->type);
280 retres1 = sceNetCnfGetCount(buf->fname, buf->type);
287 list_ee = (sceNetcnfifList_t *)my_alloc(
sizeof(sceNetcnfifList_t) * buf->data);
290 retres1 = sceNetCnfGetList(buf->fname, buf->type, list_iop);
295 for ( i = 0; i < buf->data && i < retres1; i += 1 )
300 dmatid1 = sceNetcnfifSendEE((
unsigned int)list_ee, buf->addr,
sizeof(sceNetcnfifList_t) * buf->data);
301 while ( sceNetcnfifDmaCheck(dmatid1) )
314 sceNetcnfifEnvInit(&env, mem_area, mem_area_size, buf->f_no_decode);
315 retres1 = sceNetCnfLoadEntry(buf->fname, buf->type, buf->usr_name, &env);
318 sceNetcnfifDataInit(&data);
319 retres1 = sceNetcnfifReadEnv(&data, &env, buf->type);
322 dmatid2 = sceNetcnfifSendEE((
unsigned int)&data, buf->addr,
sizeof(sceNetcnfifData_t));
323 while ( sceNetcnfifDmaCheck(dmatid2) )
327 sceNetcnfifEnvInit(&env, mem_area, mem_area_size, buf->f_no_decode);
328 retres1 = sceNetcnfifWriteEnv(&env, &data, buf->type);
330 retres1 = sceNetCnfAddEntry(buf->fname, buf->type, buf->usr_name, &env);
333 sceNetcnfifEnvInit(&env, mem_area, mem_area_size, buf->f_no_decode);
334 retres1 = sceNetCnfLoadEntry(buf->fname, buf->type, buf->usr_name, &env);
337 env.mem_ptr = (
void *)(((
int)env.mem_ptr + 3) & ~3);
338 env.mem_base = env.mem_ptr;
339 retres1 = sceNetcnfifWriteEnv(&env, &data, buf->type);
341 retres1 = sceNetCnfEditEntry(buf->fname, buf->type, buf->usr_name, buf->new_usr_name, &env);
345 retres1 = sceNetCnfDeleteEntry(buf->fname, buf->type, buf->usr_name);
348 retres1 = sceNetCnfSetLatestEntry(buf->fname, buf->type, buf->usr_name);
351 retres1 = sceNetCnfDeleteAll(buf->fname);
354 retres1 = sceNetCnfCheckCapacity(buf->fname);
357 retres1 = sceNetCnfConvA2S(buf->fname, dp,
sizeof(buf->fname));
360 sceNetcnfifEnvInit(&env, mem_area, mem_area_size, buf->f_no_decode);
361 retres1 = sceNetCnfCheckSpecialProvider(buf->fname, buf->type, buf->usr_name, &env);
364 callback.open = sce_callback_open;
365 callback.read = sce_callback_read;
366 callback.close = sce_callback_close;
367 callback.type = buf->type;
368 sce_callback_initialize();
369 sceNetCnfSetCallback(&callback);
372 sceNetCnfSetCallback(0);
375 buf->addr = (int)&data;
382 mem_area_size = buf->data;
383 mem_area = my_alloc(mem_area_size);
394 sceNetcnfifEnvInit(&env, mem_area, mem_area_size, buf->f_no_decode);
395 retres1 = sceNetcnfifWriteEnv(&env, &data, buf->type);
398 if ( env.root && env.root->pair_head && env.root->pair_head->ifc )
403 for ( i = 0; i < (int)(
sizeof(env.root->pair_head->ifc->phone_numbers)
404 /
sizeof(env.root->pair_head->ifc->phone_numbers[0]));
407 if ( i < 3 && i >= 0 && env.root->pair_head->ifc->phone_numbers[i] )
410 env.root->pair_head->ifc->redial_count = redial_count - 1;
411 if ( env.root->pair_head->ifc->pppoe != 1 && env.root->pair_head->ifc->type != 2 )
412 env.root->pair_head->ifc->type = env.root->pair_head->dev->type;
414 buf->addr = (int)&env;
423static void sceNetcnfifInterfaceStart(
void *userdata)
428 sceSifSetRpcQueue(&qd, GetThreadId());
429 sceSifRegisterRpc(&sd, 0x80001101, (SifRpcFunc_t)sceNetcnfifInterfaceServer, rpc_buf, 0, 0, &qd);
433static void sceNetcnfifInterfaceStop(
void)
441 sceSifRemoveRpc(&sd, &qd);
442 sceSifRemoveRpcQueue(&qd);
445static void sceNetcnfifDataInit(sceNetcnfifData_t *data)
447 memset(data, 0,
sizeof(sceNetcnfifData_t));
450 data->ifc_idle_timeout = -1;
452 data->phy_config = -1;
453 data->dialing_type = -1;
454 data->dev_idle_timeout = -1;
456 data->dns1_nego = -1;
457 data->dns2_nego = -1;
463 data->accm_nego = -1;
466static void sceNetcnfifEnvInit(
sceNetCnfEnv_t *env,
void *mem_area,
int size,
int f_no_decode)
469 env->mem_ptr = mem_area;
470 env->mem_base = mem_area;
471 env->mem_last = (
char *)mem_area + size;
472 env->f_no_decode = f_no_decode;
487 sceNetCnfAddress2String(data->dns1_address,
sizeof(data->dns1_address), &((
nameserver_t *)p)->address);
491 sceNetCnfAddress2String(data->dns2_address,
sizeof(data->dns2_address), &((
nameserver_t *)p)->address);
500 return sceNetCnfAddress2String(data->gateway,
sizeof(data->gateway), &((
route_t *)p)->re.gateway);
519 data->ifc_type = p->type;
520 data->dhcp = p->dhcp;
521 if ( p->dhcp_host_name )
522 strcpy(data->dhcp_host_name, (
const char *)p->dhcp_host_name);
524 strcpy(data->address, (
const char *)p->address);
526 strcpy(data->netmask, (
const char *)p->netmask);
528 for ( cmd_head = p->cmd_head; cmd_head; cmd_head = cmd_head->forw )
530 cmd = get_cmd(data, cmd_head, &ns_count);
534 for ( i = 0; i < (int)(
sizeof(p->phone_numbers) /
sizeof(p->phone_numbers[0])); i += 1 )
536 if ( !p->phone_numbers[i] )
543 strcpy(data->phone_numbers1, (
const char *)p->phone_numbers[i]);
546 strcpy(data->phone_numbers2, (
const char *)p->phone_numbers[i]);
549 strcpy(data->phone_numbers3, (
const char *)p->phone_numbers[i]);
554 strcpy(data->auth_name, (
const char *)p->auth_name);
556 strcpy(data->auth_key, (
const char *)p->auth_key);
558 strcpy(data->peer_name, (
const char *)p->peer_name);
559 data->dns1_nego = p->want.dns1_nego;
560 data->dns2_nego = p->want.dns2_nego;
561 data->f_auth = p->allow.f_auth;
562 data->auth = p->allow.auth;
563 data->pppoe = p->pppoe;
564 data->prc_nego = p->want.prc_nego;
565 data->acc_nego = p->want.acc_nego;
566 data->accm_nego = p->want.accm_nego;
568 data->ifc_idle_timeout = p->idle_timeout;
573 data->dev_type = p->type;
575 strcpy(data->vendor, (
const char *)p->vendor);
577 strcpy(data->product, (
const char *)p->product);
578 data->phy_config = p->phy_config;
580 !((
char *)p->chat_additional)
581 || (cmd = sceNetCnfConvS2A((
char *)p->chat_additional, data->chat_additional,
sizeof(p->chat_additional)), cmd >= 0) )
583 if ( p->outside_number )
584 strcpy(data->outside_number, (
const char *)p->outside_number);
585 if ( p->outside_delay )
586 strcpy(data->outside_delay, (
const char *)p->outside_delay);
587 data->dialing_type = p->dialing_type;
588 data->dev_idle_timeout = p->idle_timeout;
604 for ( pair = p->pair_head; pair; pair = pair->forw )
606 sceNetcnfifDataInit(data);
607 strcpy(data->attach_ifc, (
const char *)pair->attach_ifc);
608 strcpy(data->attach_dev, (
const char *)pair->attach_dev);
610 i = get_attach(data, pair->ifc, 1);
612 i = get_attach(data, pair->dev, 2);
617static int sceNetcnfifReadEnv(sceNetcnfifData_t *data,
sceNetCnfEnv_t *e,
int type)
620 return get_net(data, e->root);
621 if ( type >= 0 && type < 3 )
622 return get_attach(data, e->ifc, type);
623 printf(
"[%s] unknown type (%d)\n",
"sceNetcnfifReadEnv", type);
631 retval = (
char *)sceNetCnfAllocMem(e, strlen((
const char *)str) + 1, 0);
634 strcpy(retval, (
const char *)str);
644 ifc->dhcp_host_name = 0;
649 for ( i = 0; i < 3; i += 1 )
651 ifc->phone_numbers[i] = 0;
653 ifc->want.dns1_nego = -1;
654 ifc->want.dns2_nego = -1;
656 ifc->want.prc_nego = -1;
657 ifc->want.acc_nego = -1;
658 ifc->want.accm_nego = -1;
662 ifc->allow.f_auth = 0;
665 ifc->phy_config = -1;
668 ifc->chat_additional = 0;
669 ifc->outside_number = 0;
670 ifc->outside_delay = 0;
671 ifc->dialing_type = -1;
672 ifc->idle_timeout = -1;
675static int check_address(
char *str)
680 for ( ; *str; str += 1 )
682 if ( *str !=
'.' && *str !=
'0' )
692 memset(&gateway, 0,
sizeof(gateway));
693 gateway.cmd.code = 3;
694 gateway.cmd.back = e->ifc->cmd_tail;
695 if ( gateway.cmd.back )
696 gateway.cmd.back->forw = &gateway.cmd;
698 e->ifc->cmd_head = &gateway.cmd;
699 gateway.cmd.forw = 0;
700 e->ifc->cmd_tail = &gateway.cmd;
703 retres = sceNetCnfName2Address(&gateway.re.dstaddr, 0);
706 retres = sceNetCnfName2Address(&gateway.re.gateway, gw);
709 retres = sceNetCnfName2Address(&gateway.re.genmask, 0);
712 gateway.re.flags |= 4u;
716 retres = sceNetCnfName2Address(&gateway.re.dstaddr, 0);
719 retres = sceNetCnfName2Address(&gateway.re.gateway, 0);
722 retres = sceNetCnfName2Address(&gateway.re.genmask, 0);
725 gateway.re.flags = 0;
752 ns1->cmd.back = e->ifc->cmd_tail;
753 if ( e->ifc->cmd_tail )
754 e->ifc->cmd_tail->forw = &ns1->cmd;
756 e->ifc->cmd_head = &ns1->cmd;
758 e->ifc->cmd_tail = &ns1->cmd;
759 return sceNetCnfName2Address(&ns1->address, ns);
766 retres = !data->dhcp ? put_gw(e, (data->gateway[0] && check_address(data->gateway)) ? data->gateway : 0) : 0;
767 if ( data->dns1_address[0] && check_address(data->dns1_address) )
769 retres = put_ns(e, data->dns1_address, 1);
770 if ( data->dns2_address[0] && check_address(data->dns2_address) )
771 return put_ns(e, data->dns2_address, 2);
790 e->root->version = 3;
791 e->root->redial_count = -1;
792 e->root->redial_interval = -1;
793 e->root->dialing_type = -1;
795 if ( !root || !root->pair_head )
811 pair_tail = e->root->pair_tail;
817 e->root->pair_tail = p;
823 root->pair_head->ifc = e->ifc;
826 e->root->pair_head->dev = e->ifc;
834static int put_attach(
sceNetCnfEnv_t *e, sceNetcnfifData_t *data,
int type)
838 char chat_additional[256];
846 sceNetCnfInitIFC(e->ifc);
849 init_usrntcnf(e->ifc);
853 if ( data->ifc_type != -1 )
856 e->ifc->type = data->ifc_type;
858 if ( data->dhcp != 255 )
861 e->ifc->dhcp = data->dhcp;
863 if ( data->dhcp_host_name[0] )
866 e->ifc->dhcp_host_name = dup_string(e, (u8 *)data->dhcp_host_name);
868 if ( data->address[0] )
871 e->ifc->address = dup_string(e, (u8 *)data->address);
873 if ( data->netmask[0] )
876 e->ifc->netmask = dup_string(e, (u8 *)data->netmask);
878 retres = put_cmd(e, data);
885 if ( data->phone_numbers1[0] )
888 e->ifc->phone_numbers[0] = dup_string(e, (u8 *)data->phone_numbers1);
890 if ( data->phone_numbers2[0] )
893 e->ifc->phone_numbers[1] = dup_string(e, (u8 *)data->phone_numbers2);
895 if ( data->phone_numbers3[0] )
898 e->ifc->phone_numbers[2] = dup_string(e, (u8 *)data->phone_numbers3);
900 if ( data->auth_name[0] )
903 e->ifc->auth_name = dup_string(e, (u8 *)data->auth_name);
905 if ( data->auth_key[0] )
908 e->ifc->auth_key = dup_string(e, (u8 *)data->auth_key);
910 if ( data->peer_name[0] )
913 e->ifc->peer_name = dup_string(e, (u8 *)data->peer_name);
915 if ( data->dns1_nego != 255 )
918 e->ifc->want.dns1_nego = data->dns1_nego;
920 if ( data->dns2_nego != 255 )
923 e->ifc->want.dns2_nego = data->dns2_nego;
928 e->ifc->allow.f_auth = data->f_auth;
930 e->ifc->allow.auth = data->auth;
931 if ( data->pppoe != 255 )
934 e->ifc->pppoe = data->pppoe;
936 if ( data->prc_nego != 255 )
939 e->ifc->want.prc_nego = data->prc_nego;
941 if ( data->acc_nego != 255 )
944 e->ifc->want.acc_nego = data->acc_nego;
946 if ( data->accm_nego != 255 )
949 e->ifc->want.accm_nego = data->accm_nego;
951 if ( data->mtu != -1 )
954 e->ifc->mtu = data->mtu;
956 if ( data->ifc_idle_timeout != -1 )
959 e->ifc->idle_timeout = data->ifc_idle_timeout;
963 if ( data->dev_type != -1 )
966 e->ifc->type = data->dev_type;
968 if ( data->vendor[0] )
971 e->ifc->vendor = dup_string(e, (u8 *)data->vendor);
973 if ( data->product[0] )
976 e->ifc->product = dup_string(e, (u8 *)data->product);
978 if ( data->phy_config != -1 )
981 e->ifc->phy_config = data->phy_config;
983 if ( data->chat_additional[0] )
985 retres = sceNetCnfConvA2S(data->chat_additional, chat_additional,
sizeof(data->chat_additional));
989 e->ifc->chat_additional = dup_string(e, (u8 *)chat_additional);
991 if ( data->outside_number[0] )
994 e->ifc->outside_number = dup_string(e, (u8 *)data->outside_number);
996 if ( data->outside_delay[0] )
999 e->ifc->outside_delay = dup_string(e, (u8 *)data->outside_delay);
1001 if ( data->dialing_type != -1 )
1004 e->ifc->dialing_type = data->dialing_type;
1006 if ( data->dev_idle_timeout != -1 )
1009 e->ifc->idle_timeout = data->dev_idle_timeout;
1019 return (!init_flag) ? ((!e->alloc_err) ? retres : -2) : -100;
1028 char display_name[256];
1030 if ( !data->attach_ifc[0] || !data->attach_dev[0] )
1038 e->root->version = 3;
1039 e->root->redial_count = -1;
1040 e->root->redial_interval = -1;
1041 e->root->dialing_type = -1;
1042 p = e->root->pair_head;
1048 pair_tail = e->root->pair_tail;
1049 p->back = pair_tail;
1052 pair_tail->forw = p;
1054 e->root->pair_tail = p;
1056 strcpy(display_name, data->attach_ifc);
1057 strcat(display_name,
" + ");
1058 strcat(display_name, data->attach_dev);
1059 p->display_name = dup_string(e, (u8 *)display_name);
1060 p->attach_ifc = dup_string(e, (u8 *)data);
1061 p->attach_dev = dup_string(e, (u8 *)data->attach_dev);
1062 for ( i = 0; i < 2; i += 1 )
1065 attachres1 = put_attach(e, data, i + 1);
1066 if ( attachres1 < 0 && attachres1 != -100 )
1068 attachres1 = root_link(e, i + 1);
1069 if ( attachres1 < 0 )
1072 return (!e->alloc_err) ? attachres1 : -2;
1075static int sceNetcnfifWriteEnv(
sceNetCnfEnv_t *e, sceNetcnfifData_t *data,
int type)
1083 retres1 = put_net(e, data);
1089 retres1 = put_attach(e, data, type);
1092 retres1 = root_link(e, type);
1096 printf(
"[%s] unknown type (%d)\n",
"sceNetcnfifWriteEnv", type);
1101 e->mem_ptr = (
void *)(((
int)e->mem_ptr + 3) & ~3);
1102 e->mem_base = e->mem_ptr;
1107static int sceNetcnfifSendEE(
unsigned int data,
unsigned int addr,
unsigned int size)
1112 dmat.src = (
void *)data;
1113 dmat.dest = (
void *)addr;
1114 dmat.size = (size & ~0x3F) + ((size & 0x3F) ? 64 : 0);
1120 dmatid = sceSifSetDma(&dmat, 1);
1126static int sceNetcnfifDmaCheck(
int id)
1128 return sceSifDmaStat(
id) >= 0;
1131static void sce_callback_initialize(
void)
1137 if ( sceSifBindRpc(&gcd, 0x80001101, 0) < 0 )
1142 while ( sceSifCheckStatRpc(&gcd) )
1146 for ( i = 0xFFFF; i != 0; i -= 1 )
1151static int sce_callback_open(
const char *device,
const char *pathname,
int flags,
int mode,
int *filesize)
1155 gbuf[2] = strlen(device) + 1;
1156 gbuf[3] = strlen(pathname) + 1;
1157 memcpy(&gbuf[4], device, strlen(device) + 1);
1158 memcpy((
char *)&gbuf[4] + strlen(device) + 1, pathname, strlen(pathname) + 1);
1159 if ( sceSifCallRpc(&gcd, 12, 0, gbuf, (strlen(pathname) + strlen(device) + 1 + 80) & ~0x3F, gbuf, 64, 0, 0) >= 0 )
1161 *filesize = gbuf[1];
1167static int sce_callback_read(
int fd,
const char *device,
const char *pathname,
void *buf,
int offset,
int size)
1170 gbuf[1] = strlen(device) + 1;
1171 gbuf[2] = strlen(pathname) + 1;
1174 memcpy(&gbuf[5], device, strlen(device) + 1);
1175 memcpy((
char *)&gbuf[5] + strlen(device) + 1, pathname, strlen(pathname) + 1);
1178 &gcd, 13, 0, gbuf, (strlen(pathname) + strlen(device) + 1 + 84) & ~0x3F, gbuf, (size + 67) & ~0x3F, 0, 0)
1181 memcpy(buf, &gbuf[1], size);
1185static int sce_callback_close(
int fd)
1188 return (sceSifCallRpc(&gcd, 14, 0, gbuf, 64, gbuf, 64, 0, 0) >= 0) ? gbuf[0] : -1;
1191static int my_create_heap(
void)
1195 g_heap = CreateHeap(1024, 1);
1196 return g_heap ? 0 : -1;
1199static void *my_alloc(
int size)
1201 return AllocHeapMemory(g_heap, size);
1204static void my_free(
void *ptr)
1207 FreeHeapMemory(g_heap, ptr);
1210static void my_delete_heap(
void)
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)