s32 USBStorage2_Init(u32 port)
{
	if(hddInUse[port])
		return 0;

	/* Create heap */
	if (hid < 0)
	{
		hid = iosCreateHeap(UMS_HEAPSIZE);
		if (hid < 0) return IPC_ENOMEM;
	}

	/* Open USB device */
	if (fd < 0) fd = IOS_Open(fs, 0);
	if (fd < 0) fd = IOS_Open(fs2, 0);
	if (fd < 0) fd = IOS_Open(fs3, 0);
	if (fd < 0) return fd;

	USBStorage2_SetPort(port);

	/* Initialize USB storage */
	IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_INIT, ":");

	/* Get device capacity */
	if (USBStorage2_GetCapacity(port, &hdd_sector_size[port]) == 0)
		return IPC_ENOENT;

	hddInUse[port] = true;

	return 0; // 0->HDD, 1->DVD
}
Exemple #2
0
int Playlog_Update(const char * ID, const u16 * title)
{
	if(!ID || !title)
		return -1;

	//If not started from SystemMenu, create playlog
	Playlog_Create();

	s32 fd = -1, res = -1;
	u32 sum = 0;
	u8 i;

	//Open play_rec.dat
	fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW);
	if(fd == -106)
	{
		//In case the play_rec.dat wasn´t found create one and try again
		int ret = Playlog_Create();
		if(ret < 0)
			return ret;

		fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW);
	}

	if(fd < 0)
		return res;

	PlayRec * playrec_buf = memalign(32, ALIGN32(sizeof(PlayRec))); //! Should be 32 byte aligned
	if(!playrec_buf)
	{
		IOS_Close(fd);
		return res;
	}

	memset(playrec_buf, 0, sizeof(PlayRec));

	u64 stime = getWiiTime();
	playrec_buf->ticks_boot = stime;
	playrec_buf->ticks_last = stime;

	//Update channel name and ID
	memcpy(playrec_buf->name, title, 84);
	memcpy(playrec_buf->title_id, ID, 6);

	//Calculate and update checksum
	for(i = 0; i < 31; i++)
		sum += playrec_buf->data[i];

	playrec_buf->checksum = sum;

	//Write play_rec.dat
	if(IOS_Write(fd, playrec_buf, sizeof(PlayRec)) == sizeof(PlayRec))
		res = 0;

	IOS_Close(fd);

	free(playrec_buf);

	return res;
}
int Playlog_Update(const char ID[6], const u8 title[84])
{
	gprintf("Update Play log\n");
	u32 sum = 0;
	u8 i;

	//Open play_rec.dat
	s32 playrec_fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW);
	if(playrec_fd == -106)
	{
		gprintf("IOS_Open error ret: %i\n",playrec_fd);
		IOS_Close(playrec_fd);
		
		//In case the play_rec.dat wasn´t found create one and try again
		if(ISFS_CreateFile(PLAYRECPATH,0,3,3,3) < 0 )
			goto error_2;
			
		playrec_fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW);
		if(playrec_fd < 0)
			goto error_2;
	}
	else if(playrec_fd < 0)
		goto error_2;

    u64 stime = getWiiTime();
	playrec_buf.ticks_boot = stime;
	playrec_buf.ticks_last = stime;

	//Update channel name and ID
	memcpy(playrec_buf.name, title, 84);
	strcpy(playrec_buf.title_id, ID);

	memset(playrec_buf.padding2, 0, 18);

	//Calculate and update checksum
	for(i=0; i<31; i++)
		sum += playrec_buf.data[i];
	playrec_buf.checksum=sum;

	//Write play_rec.dat
	if(IOS_Write(playrec_fd, &playrec_buf, sizeof(playrec_buf)) != sizeof(playrec_buf))
		goto error_1;

	IOS_Close(playrec_fd);
	return 0;

error_1:
	gprintf("error_1\n");
	IOS_Close(playrec_fd);

error_2:
	gprintf("error_2\n");
	return -1;
}
int Playlog_Delete(void) //Make Wiiflow not show in playlog
{
	//Open play_rec.dat
	s32 playrec_fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW);
	if(playrec_fd < 0)
		goto error_2;

	//Read play_rec.dat
	if(IOS_Read(playrec_fd, &playrec_buf, sizeof(playrec_buf)) != sizeof(playrec_buf))
		goto error_1;

	if(IOS_Seek(playrec_fd, 0, 0) < 0)
		goto error_1;
    
	// invalidate checksum
	playrec_buf.checksum=0;

	if(IOS_Write(playrec_fd, &playrec_buf, sizeof(playrec_buf)) != sizeof(playrec_buf))
		goto error_1;

	IOS_Close(playrec_fd);
	return 0;

error_1:
	IOS_Close(playrec_fd);

error_2:
	return -1;
}
Exemple #5
0
s32 Sys_GetCerts(signed_blob **certs, u32 *len)
{
	static signed_blob certificates[CERTS_LEN] ATTRIBUTE_ALIGN(32);

	s32 fd, ret;

	/* Open certificates file */
	fd = IOS_Open(certs_fs, 1);
	if (fd < 0)
		return fd;

	/* Read certificates */
	ret = IOS_Read(fd, certificates, sizeof(certificates));

	/* Close file */
	IOS_Close(fd);

	/* Set values */
	if (ret > 0) {
		*certs = certificates;
		*len   = sizeof(certificates);
	}

	return ret;
}
Exemple #6
0
void tell_cIOS_to_return_to_channel(void)
	{
    if (TITLE_UPPER(old_title_id) > 1 && TITLE_LOWER(old_title_id) > 2) // Don't change anything for system menu or no title id
        {
		static u64 sm_title_id ATTRIBUTE_ALIGN(32);
		sm_title_id = old_title_id; // title id to be launched in place of the system menu
		
		int ret;
		
		static ioctlv vector[0x08] ATTRIBUTE_ALIGN(32);

		vector[0].data = &sm_title_id;
		vector[0].len = 8;

		int es_fd = IOS_Open("/dev/es", 0);
		if (es_fd < 0)
			{
			debug("Couldn't open ES module\n");
			return;
			}
		
		ret = IOS_Ioctlv(es_fd, 0xA1, 1, 0, vector);
		
		debug ("tell_cIOS_to_return_to_channel = %d\n", ret);

		IOS_Close(es_fd);
        }
	}
Exemple #7
0
void wii_keyboard_init()
{
	if (!keyboard_initialized) {
		//printf("init keyboard");
		initkeymap();
		queue = (lwp_queue*)malloc(sizeof(lwp_queue));	
		__lwp_queue_initialize(queue,0,0,0);
		keyboard_kb=IOS_Open("/dev/usb/kbd", 1);
		/*
		if (keyboard_kb>=0) {
			printf("keyboard kb ok\n");
		} else{
			printf("keyboard kb not ok\n");
			}*/
		sleep(2);
		key_data.message=0x0;
		key_data1.id=0;
		key_data2.id=0;
		keyboard_stop = 0;
		if(keyboard_kb>=0) 
			IOS_IoctlAsync(keyboard_kb,1,(void *) &key_data, 16,(void *) &key_data, 16, keyboard_callback, NULL);
		keyboard_initialized  = 1;
	} else {
		if(keyboard_kb>=0) 
			IOS_IoctlAsync(keyboard_kb,1,(void *) &key_data, 16,(void *) &key_data, 16, keyboard_callback, NULL);

	}
}
Exemple #8
0
s32 USB_GetDeviceList(const char *devpath,void *descr_buffer,u8 num_descr,u8 b0,u8 *cnt_descr)
{
	s32 fd,ret;
	char *path;
	u32 cntdevs;

	if(devpath==NULL || *devpath=='\0') return IPC_EINVAL;

	path = (char*)iosAlloc(hId,IPC_MAXPATH_LEN);
	if(path==NULL) return IPC_ENOMEM;
	
	strncpy(path,devpath,IPC_MAXPATH_LEN);
	fd = IOS_Open(path,IPC_OPEN_NONE);
	if(fd<0) {
		iosFree(hId,path);
		return fd;
	}

	cntdevs = 0;
	ret = IOS_IoctlvFormat(hId,fd,USB_IOCTL_GETDEVLIST,"bb:bd",num_descr,b0,&cntdevs,descr_buffer,(num_descr<<3));
	if(ret>=0) *cnt_descr = cntdevs;
	
	iosFree(hId,path);
	IOS_Close(fd);
	return ret;
}
Exemple #9
0
int Playlog_Delete(void)
{
	s32 res = -1;

	//Open play_rec.dat
	s32 fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW);
	if(fd < 0)
		return fd;

	PlayRec * playrec_buf = memalign(32, ALIGN32(sizeof(PlayRec)));
	if(!playrec_buf)
		goto cleanup;

	//Read play_rec.dat
	if(IOS_Read(fd, playrec_buf, sizeof(PlayRec)) != sizeof(PlayRec))
		goto cleanup;

	if(IOS_Seek(fd, 0, 0) < 0)
		goto cleanup;

	// invalidate checksum
	playrec_buf->checksum = 0;

	if(IOS_Write(fd, playrec_buf, sizeof(PlayRec)) != sizeof(PlayRec))
		goto cleanup;

	res = 0;

cleanup:
	free(playrec_buf);
	IOS_Close(fd);
	return res;
}
Exemple #10
0
s32 Nand_Enable(nandDevice *dev)
{
	s32 fd, ret;

	/* Open /dev/fs */
	fd = IOS_Open("/dev/fs", 0);
	if (fd < 0)
		return fd;

	memset(inbuf, 0, sizeof(inbuf));

	/* Set input buffer */
	if (IOS_GetRevision() >= 20)
	{
		// New method, fully enable full emulation
		inbuf[0] = dev->mode | 0x100;
	} else
	{
		// Old method
		inbuf[0] = dev->mode;
	}

	/* Enable NAND emulator */
	ret = IOS_Ioctl(fd, 100, inbuf, sizeof(inbuf), NULL, 0);

	/* Close /dev/fs */
	IOS_Close(fd);

	return ret;
} 
Exemple #11
0
s32 USB_DeviceInsertNotifyAsync(const char *devpath,u16 vid,u16 pid,usbcallback cb,void *usrdata)
{
	char *path;
	s32 fd = -1;
	s32 ret = IPC_ENOMEM;
	u16 *pvid = NULL;
	u16 *ppid = NULL;
	ioctlv *vec = NULL;
	struct _usb_cb *msgcb = NULL;

	if(devpath==NULL || *devpath=='\0') return IPC_EINVAL;

	path = (char*)iosAlloc(hId,IPC_MAXPATH_LEN);
	if(path==NULL) return IPC_ENOMEM;
	
	strncpy(path,devpath,IPC_MAXPATH_LEN);
	fd = IOS_Open(path,IPC_OPEN_NONE);
	if(fd<0) {
		ret = fd;
		goto done;
	}

	vec = iosAlloc(hId,sizeof(ioctlv)*2);
	if(vec==NULL) goto done;

	msgcb = iosAlloc(hId,sizeof(struct _usb_cb));
	if(msgcb==NULL) goto done;

	pvid = iosAlloc(hId,32);
	if(pvid==NULL) goto done;
	*pvid = vid;

	ppid = iosAlloc(hId,32);
	if(ppid==NULL) goto done;
	*ppid = pid;

	vec[0].data = pvid;
	vec[0].len = sizeof(u16);
	vec[1].data = ppid;
	vec[1].len = sizeof(u16);

	msgcb->fd = fd;
	msgcb->cb = cb;
	msgcb->vec = vec;
	msgcb->usrdata = usrdata;
	return IOS_IoctlvAsync(fd,USB_IOCTL_DEVINSERTHOOK,2,0,vec,__usb_device_notificationCB,msgcb);

done:
	if(ppid!=NULL) iosFree(hId,ppid);
	if(pvid!=NULL) iosFree(hId,pvid);
	if(msgcb!=NULL) iosFree(hId,msgcb);
	if(vec!=NULL) iosFree(hId,vec);
	if(path!=NULL) iosFree(hId,path);
	
	if(fd>=0) IOS_Close(fd);

	return ret;
}
Exemple #12
0
bool DIP::Initialize()
{
	LWP_MutexInit(&Mutex, false);
	if (Device_Handle < 0)
	{
		Device_Handle = IOS_Open("/dev/di", 0);
	}
	return (Device_Handle >= 0) ? true : false;
}
Exemple #13
0
s32 DVDEjectDisc( void )
{
	s32 fd = IOS_Open("/dev/di", 0 );
	if( fd < 0 )
		return fd;

	s32 r = IOS_Ioctl( fd, DVD_EJECT_DISC, NULL, 0, NULL, 0 );

	IOS_Close( fd );

	return r;
}
Exemple #14
0
s32 DVDGetGameCount( u32 *Count )
{
	s32 fd = IOS_Open("/dev/di", 0 );
	if( fd < 0 )
		return fd;

	s32 r = IOS_Ioctl( fd, DVD_GET_GAMECOUNT, NULL, 0, Count, sizeof(u32) );

	IOS_Close( fd );

	return r;
}
Exemple #15
0
s32 DVDLowPrepareCoverRegister( u32 *Cover )
{
	s32 fd = IOS_Open("/dev/di", 0 );
	if( fd < 0 )
		return fd;

	s32 r = IOS_Ioctl( fd, 0x7A, NULL, 0, Cover, sizeof(u32) );

	IOS_Close( fd );

	return r;
}
Exemple #16
0
s32 DVDConnected( void )
{
	s32 fd = IOS_Open("/dev/di", 0 );
	if( fd < 0 )
		return fd;

	s32 r = IOS_Ioctl( fd, DVD_CONNECTED, NULL, 0, NULL, 0);
	
	IOS_Close( fd );

	return r;
}
s32 WDVD_Init(void)
{
	if (di_fd < 0)
	{
		di_fd = IOS_Open( di_fs, 0 );
		if (di_fd < 0)
			return di_fd;
	}
	//gprintf("WDVD_Init() ok di_fd: %d\n", di_fd );

	return 0;
}
Exemple #18
0
s32 WDVD_Init(void)
{
	/* Open "/dev/di" */
	if(di_fd < 0)
	{
		di_fd = IOS_Open(di_fs, 0);
		wifi_printf("wdvd_WDVD_Init: di_fd value = %d\n", di_fd);
		if (di_fd < 0) 
			return di_fd;
	}
	return 0;
}
Exemple #19
0
s32 DVDInsertDisc( void )
{
	s32 fd = IOS_Open("/dev/di", 0 );
	if( fd < 0 )
		return fd;

	s32 r = IOS_Ioctl( fd, DVD_INSERT_DISC, NULL, 0, NULL, 0 );

	IOS_Close( fd );

	return r;
}
Exemple #20
0
s32 __STM_Init()
{
	if(__stm_initialized==1) return 1;
#ifdef DEBUG_STM
	printf("STM Init\n");
#endif

	__stm_vdinuse = 0;
	__stm_imm_fd = IOS_Open(__stm_imm_fs,0);
	if(__stm_imm_fd<0) return 0;

	__stm_eh_fd = IOS_Open(__stm_eh_fs,0);
	if(__stm_eh_fd<0) return 0;
	
#ifdef DEBUG_STM
	printf("STM FDs: %d, %d\n",__stm_imm_fd, __stm_eh_fd);
#endif
	
	__stm_initialized = 1;
	__STM_SetEventHook();
	return 1;
}
Exemple #21
0
BSPError
bspInitializeShimInterface()
{
   auto result = IOS_Open(make_stack_string("/dev/bsp"),
                          ios::OpenMode::None);

   if (IOS_FAILED(result)) {
      return BSPError::IosError;
   }

   sBspData->bspHandle = static_cast<IOSHandle>(result);
   return BSPError::OK;
}
Exemple #22
0
/* Open a specific controller under /dev/uhs */
int UhsOpenController(int controller_num)
{
	/* Symbol loading */
	unsigned int coreinit_handle;
	OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
	int (*IOS_Open)(char *path, int mode);
	OSDynLoad_FindExport(coreinit_handle, false, "IOS_Open", &IOS_Open);

	/* Build the path name and return a handle */
	char path[32];
	__os_snprintf(path, 32, "/dev/uhs/%d", controller_num);
	return IOS_Open(path, 0);
}
Exemple #23
0
u32 ssl_open(void){

	s32 ret;

	if (__ssl_fd < 0) {
		ret = IOS_Open(__ssl_fs,0);
		if(ret<0){
			return ret;
		}
		__ssl_fd = ret;
	}

	return 0;
}
bool shadow_mload()
{
	int ios = IOS_GetVersion();

	if(ios != 222 || ios != 223 || ios != 224)
		return false;

	int v51 = (5 << 4) & 1;
	if (IOS_GetRevision() >= 5 && mload_get_version() >= v51)
	{
		char fs[] ATTRIBUTE_ALIGN(32) = "/dev/mload/OFF";
		// shadow /dev/mload supported in hermes cios v5.1char fs[] ATTRIBUTE_ALIGN(32) = "/dev/usb2";
		IOS_Open(fs,0);
		return true;
	}
Exemple #25
0
/****************************************************************************
 * Get network IP
 ***************************************************************************/
bool ShutdownWC24() {
    bool onlinefix = IsNetworkInit();
    if (onlinefix) {
        s32 kd_fd, ret;
        STACK_ALIGN(u8, kd_buf, 0x20, 32);

        kd_fd = IOS_Open("/dev/net/kd/request", 0);
        if (kd_fd >= 0) {
            ret = IOS_Ioctl(kd_fd, 7, NULL, 0, kd_buf, 0x20);
            if (ret >= 0)
                onlinefix = false; // fixed no IOS reload needed
            IOS_Close(kd_fd);
        }
    }
    return onlinefix;
}
Exemple #26
0
s32 Nand_Unmount(nandDevice *dev)
{
	s32 fd, ret;

	/* Open FAT module */
	fd = IOS_Open("fat", 0);
	if (fd < 0)
		return fd;

	/* Unmount device */
	ret = IOS_Ioctlv(fd, dev->umountCmd, 0, 0, NULL);

	/* Close FAT module */
	IOS_Close(fd);

	return ret;
}
Exemple #27
0
s32 DVDWriteDIConfig( void *DIConfig )
{
	s32 fd = IOS_Open("/dev/di", 0 );
	if( fd < 0 )
		return fd;

	u32 *vec = (u32 *)malloca( sizeof(u32) * 1, 32 );
	vec[0] = (u32)DIConfig;

	s32 r = IOS_Ioctl( fd, DVD_WRITE_CONFIG, vec, sizeof(u32) * 1, NULL, 0 );

	IOS_Close( fd );

	free( vec );

	return r;
}
Exemple #28
0
s32 DVDSelectGame( u32 SlotID )
{
	s32 fd = IOS_Open("/dev/di", 0 );
	if( fd < 0 )
		return fd;

	u32 *vec = (u32 *)malloca( sizeof(u32) * 1, 32 );
	vec[0] = SlotID;

	s32 r = IOS_Ioctl( fd, DVD_SELECT_GAME, vec, sizeof(u32) * 1, NULL, 0 );

	IOS_Close( fd );

	free( vec );

	return r;
}
Exemple #29
0
bool SDHC_Init(void)
{
	s32 ret;

	if (sdhc_mode_sd) {
		return __io_wiisd.startup();
	}

	/* Already open */
	if (fd >= 0)
		return true;

	/* Create heap */
	if (hid < 0) {
		hid = iosCreateHeap(SDHC_HEAPSIZE);
		if (hid < 0)
			goto err;
	}

	// allocate buf2
	if (sdhc_buf2 == NULL) {
		sdhc_buf2 = SYS_AllocArena2MemLo(SDHC_MEM2_SIZE, 32);
	}

	/* Open SDHC device */
	fd = IOS_Open(fs, 0);
	if (fd < 0)
		goto err;

	/* Initialize SDHC */
	ret = IOS_IoctlvFormat(hid, fd, IOCTL_SDHC_INIT, ":");
	if (ret)
		goto err;

	return true;

err:
	/* Close SDHC device */
	if (fd >= 0) {
		IOS_Close(fd);
		fd = -1;
	}

	return false;
}
Exemple #30
0
s32 USB_OpenDevice(const char *device,u16 vid,u16 pid,s32 *fd)
{
	s32 _fd = -1;
	s32 ret = USB_OK;
	char *devicepath = NULL;

	devicepath = iosAlloc(hId,USB_MAXPATH);
	if(devicepath==NULL) return IPC_ENOMEM;

	snprintf(devicepath,USB_MAXPATH,"/dev/usb/%s/%x/%x",device,vid,pid);

	_fd = IOS_Open(devicepath,0);
	if(_fd<0) ret = _fd;

	*fd = _fd;

	if(devicepath!=NULL) iosFree(hId,devicepath);
	return ret;
}