-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FR] Migrate to Smbv2 or Smbv3 [SMB] #86
Comments
This is related to the PS2SDK as well, FYI. Both will have to be upgraded, for the transition to a new SMB standard to be complete. |
@beatstick (Whuuuaaat? What a name! :'-D): Technically it is quite possible... However, SMB-Support is a BIT 'hackish' since it's introduction into 'USBLD' (thus making it the first OPL)... We are 'driving' the IOP like a race-car (or Koenigsegg Agera, or a rocket-center) while it actually is a 'Lada' or a 'Trabant'... I am not sure, if SMBv2/3 would introduce a lot overhead on the IOP's RAM and/or CPU-Usage, which is my main concern (especially due to game-compatibility)... :-/ |
I wonder if nfs or plain http would make more sense. The latter might be problematic wrt VMC, but it could be pretty simple. |
I have started work on one, since it doesn't seem like anybody is. It will be done when I can. Please refer to ps2dev/ps2sdk#72 for any progress updates. I plan to update the driver within the PS2SDK first, before adding a micro-driver here. |
is nfs not an option? |
If people are still working on this, please see It is a very portable high performance, small footprint, smb2/3 client that builds on almost anything. It connects and interoperates with samba, windows, azure, osx, and pretty much any smb2/3 capable server. The size of the code for the full blown library is ~120kb, but can be stripped down to ~60-70kb by removing features such as |
Hi and welcome! It sounds like a great alternative/improvement to the SMB implementation we have right now. I'm also a big fan of using standard software instead of ps2 specific software, becouse it makes maintaining things more easy on the ps2 side. If it runs on an ESP32, then maybe it can run on the ps2. However, the network adapter and tcp/ip stack are not located on the 300MHz EE CPU, but on the 33MHz IOP CPU. I'm not sure how familiar you are with the ps2, but the IOP (I/O Processor) is the old 33MHz MIPS R3000 Playstation1 CPU. It's got 2MiB of ram total, to do all IO processing. Like controllers, memorycard, sound, usb, etc... It runs something similar to a tiny real time os. We use LwIP as our tcp/ip stack. On the other side of the library we need to interface to the IOP file system, using the iop_device_ops_t structure: So to make it work we need something like this: Do you know if libsmb2 works together with LwIP? Would it be difficult to use the library from a structure like the iop_device_ops_t? |
I had a look at LwIP and it does support an optional Berkley socket layer so that should be all we need. Without looking too deeply into LwIP right now, as it is a very small and limited stack, I see only 3 potential issues. All three would be easy to handle on libsmb2 side. 1, non-blocking socket support. libsmb2 should work even is LwIP does not support this but I have not tested it in a while. Would be a bug and easy for me to fix if it doesn't work. 2, Support for getaddrinfo() to resolve names. 3, IPv6. Libsmb2 currently assumes that all platforms have ipv6 support. If LwIP does not have IPv6 support we will need to add some #ifndef PS2 conditionals to 3-4 places in libsmb2:lib/socket.c to remove the dependency of it. Memory and CPU requirements. 33MHz should be fine. It is not going to be super-fast but libsmb2 should be faster than the current SMB1 implementation (which I assume is based on old version of libsmbclient or the old smb1 implementation in vlc). iop_device_ops_t So as long as you have a budget for ~100-150kb for the object code (we can strip this down) and a few tens of kb for RAM it should be fine. I am more than happy to work with you and do all the modifications and fix all the issues you encounter to get this working on PS2. This would be awesome! |
Why would a blocking call waste CPU cycles? Isn't that depending on how LwIP blocks? Busy waiting is a bad idea on the IOP, becouse it would block other IO from being processed. Like sound or the controller input.
Yes, an
LwIP does have IPv6 support, but that does not mean we use it or need it. I would choose something like
Yes, sounds like a good idea.
Great! That does look simple to implement from the posix side. We do have ~100-150kb, but there's a catch. If writing our own programs we control the budget, and we can use whatever memory we like. However, when emulating a game from DVD, the game controls the budget, and we have 'hide' our emulation in whatever memory is left. So the more memory we use, the less compatibility will be.
I would love to work on this but unfortunately I do now have the time to take up another project. Besides work and life, I'm also working on the software for an SD adapter (search ps2 sio2sd), and I'm trying to upgrade GCC to the latest version (we're still using gcc 3.2.3). |
I misremembered. Sorry.
Ok. Getting the object size down to ~90kb would be almost trivial by just getting rid of encryption, signing and dcerpc (used for share enumeration). This I can make possible with almost no effort by just adding a few #ifdefs and doocument them. I will do that regardless of if you want to work on this. I have planned to modularize the featureset to slim down the footprint to handle even smaller and more constrained embedded devices. Getting from ~90kb to ~70 is possible with almost no effort too by shedding the authentication layer. That would mean only "guest" access to the share will work. No username/password. That would also be almost no effort required. That would bring the code size to ~70kb and then the run-time memory requirement to ~3-4kb. It is possible to get even smaller but by now all low hanging fruit is gone so everything below ~70kb would become significantly more effort. Not impossible, just a lot more work. And if we need to, I will do it.
I understand the scarcity of spare time for projects well. Maybe an alternative would be to get libsmb2 to compile and work in PS2/LwIP would be to get some homebrew to use it first. |
No thanks. I would rather not spend time on PS2 projects these days. Our existing code might be original, tailored for the PS2. In-game OPL has a heavily customized version, which had the authentication part split off into a non-resident module - all done in the name of reducing footprint. |
Fair enough. Just out of curiosity. How small footprint do you think it needs to have to be viable for OPL? |
Back in my day, we were supposed to be always short of memory. I don't know about now, but I suppose you got to find the OPL developers and ask them about it... For the ultimate compatibility, I believe the memory consumed by the new IOP modules must not exceed the memory consumed by the original modules. |
I have created two separate branches of libsmb2 if someone wants to give it a try in the future. The "small" branch which is a stripped down, read-only, but mostly complete version of libsmb2 that can be used to authenticate, scan directories and open a file handle. This compiles down into ~35kb. And a "super-small" branch that compiles down into ~4kb. This branch ONLY implements smb2_read() and smb2_read_async() but will accept the context and handle that were opened from the "small" module. So a potential flow could be: This would allow you to reading from a file using only a 4kb foot-print for the smb2 module. This was fun, and useful. In particular the "small" branch will become useful for me and I will merge parts of it mack into mainline since it will allow constrained devices to optionally shed un-needed functionality. If someone wants to try add smb2 support to OPL in the future, I will leave the "small" and "super-small" branches on github. |
Thank you, I can't promise anything but I would like to try in the future.
I think this could work for OPL. The GUI would use the "small" module and the "ingame" could use the "super-small" version. If we separate like this the "small" version could even be a lot larger, as long as the "super-small" version stays as small as possible ;). |
Cool. I tested this by creating a test program based on the example in "samples/network/tcpip-basic/" in the sdk and added calls to libsmb2 to connect, authenticate, and map a SMB2/3 share from the network. I ran the resulting elf binary from a ps2 slim and it worked. Wooohooo. To compile : |
Please check my ps2 branch and the super-small branch. (the small read-only branch might be redundant) In the "ps2" branch, we have a full libsmb2, with everything and it compiles into a libsmb2.a without compiler warnings for I have tested PS2_EE and it works with sample programs on a ps2 slim as far as my testing goes. I have not tested PS2_IOP because I can not easily build applications for it (or even know how to do so) but the IOP builds and links to a libsmb2.a library without any compiler warnings so I assume it should mostly work. |
A basic example on how to authenticate and connect to a share using libsmb2:
smb2_connect_share is sync and blocking interface, use smb2_connect_share_async() to use the async event driven API. After these calls are done and you are connected to the share you can use calls such as smb2_opendir(_async)(), smb2_open(_async)() ... |
I tried to fix up the ps2 branch with the full libsmb2 to build as a irx and it almost does. If we can solve the issue with errno, and get it to work as an irx for IOP for the ps2 branch (full blown libsmb2) it should be easy to port the changes to the super-small branch. |
Sorry for yet more spam, The ps2 branch, which is the full blown libsmb2 with ps2 ee/iop support is about ~180kb when built as an irx. So, if this works, we should be able to have a system where And we are now in full smb2/3 support for reading the sectors for a game with even ~25kb less RAM used than with the current smbman.irx. Victory! |
Congratulations and thank you for the 'spam' ;). I'm on vacation and reading your messages with much interest. |
I tried to start building it as a filesystem module with an iop_device_ops_t like smbman I tried to fixup labs/smblab as that looks like a nice example on how to use smbman running on the iop by fixing the makefile The ps2 branch contains my changes to build an initial iop_device_ops_t containing only an init and deinit function. |
Any help now is appreciated. I can't get any further right now. |
You need to load the module, perhaps with something like LoadModule(). The right function to use, depends on what and where you are loading the module from. Homebrew software generally use the default modules that come with the PS2, which are a standard set of modules from the first SCPH-10000 to the last SCPH-90000 model made. According to what Sony wrote about the TOOL PS2's testing mode, those IOP modules are functionally equivalent to the modules from the official release 1.3.4 - which is very old (from 1999). Please note that the IOP kernel has restrictions, to prevent licensees from loading unsigned code from user-writable media. LoadModuleBuffer()'s SIF RPC was not implemented as of the PS2's release, which is why it must be enabled with sbv_patch_enable_lmb(). Sony also had to do this, for the HDD Browser. Remember to check the return value. It should be a positive number that represents the module ID. This is a running number, so it is not supposed to be a large value. While negative numbers indicate an error, calling the SifLoadModuleBuffer() RPC before it is fixed, will cause an undefined value to be returned - which might be still a positive number. |
@sahlberg @rickgaiser any updates on this one? This would easyly be one of the hugest improovements over the last years. |
No update and no progress. I did spend a lot of time on this but I don't really know PS2 development. I have zero experience in PS2 homebrew development or debugging. TBH. It would be very nice to have smb2 support, but really, a fat ps2 with a gamestar adapter for 30$AUD is a much better solution. Sure no SMB support but faster and cheaper and it works. |
My two cents here: I believe SMB and HDD approach are extremely different and should not be compared. It's like going to work using a car or public transport. HDD SMB Somebody prefers HDD, other SMB, according to what they have and need. |
No worries for not making progress, you already did quite a lot to bring SMBv2/3 support forward! Its good to hear you still have this on your mind though. I was hoping for @rickgaiser of @sp193 to have a look into integrating this further, as this might be one of the most awaited features in a while (primarily because of the security implications of running a SMBv1 instance). Also as version 1.0 was officially released a few days ago, there might be more time availabe to spend on the integration task now? Surely using an HDD might be feasible too, but I agree to @auanasgheps that especially for those owning a single slim ps2 it might not be an option. I fully understand this whole project is driven by a few people in their free time and do not want to urge anybody to take care of this soon, but I'd already be happy to hear, that this is is at least considered as an important feature and might be worked on in the near future. :) |
I made a little progress on this - I created a barebones IRX that simply calls My IRX is able to connect to my host by using the Thanks @sahlberg for bringing the IOP stuff in libsmb2 into master. I wish I noticed your |
No problem. It works so far that in devctl I have a logging system where I connect to an smb2 share and open a file for logging. |
Email me and I can send you the sources for smb2man I have so far. |
I have created SMB2MAN irx and it is avaliable at https://github.com/sahlberg/ps2sdk/tree/smb2man It builds an IRX that is ~165kb in size, but this is the full blown libsmb2 so there is space to make this smaller by slimming down libsmbs. For example getting rid of the DCERPC layer as well as all the strings used in the nt-error to string mappings. Using a modified OPL, that links with this SMB2MAN instead of SMBMAN and just calls the CONNECT devctl You will need to do some hacking on OPL to even get it to use smb2man but it is not too hard to do. I can send a temporary hack/patch I used with hardcoded share settings if someone wants to try. But it is probably better to have someone that knows opl to do a proper patch instead. My hacked up OPL can not launch any games. It just goes black screen and hangs. Maybe the irx is too big? |
This is an astonishing result. Thanks for keeping us updated! |
So I will try to describe what I think needs doing now. I am not sure if this actually can/will work, it all depends on :
IF that is possible. I think one way to get SMB2 into OPL is to: 4, Load a new smaller IRX. This would be a tiny version of SMB2MAN and libsmb2 which only implements the lseek and read fucntions. My supersmall branch of libsmb2 can illustrate how you can cut down libsmb2 like that. That I think has potential to work, but it depends on that a filedescriptor and allocated memory block will remain available even after the IRX that opened it is unloaded. I won't have any time to work on this myself for the forseeable future so someone will have to test it. |
I wanted to say @sahlberg it's great to see so much progress on this and reading this has been very interesting (not that I can fully grasp it). I wanted to add on to what @auanasgheps said and mention also that SMB has some pretty major advantages for multi console environments since you can use one storage location to feed multiple consoles and removes unnecessary duplication of data/effort. Speaking of VMC files, it sounds like the version of libsmb2 that would be running while a game is running will currently lack write functionality. I'm unsure of how the VMC system works (I'm trying to read and figure it out but I'm new) but I would think that would break VMC on SMB functionality since when the game would go to save it would be unable to write to the share hosting the file. |
I just came to tell you that I admire your work and knowledge . I wish I could help you even a little but I don’t know anything about ps2 programming.all be safe and do what you really love!I m waiting patiently to see if any progress ll be made on this subject because it ll be really dope! |
Is SMBv1 still a requirement for the server hosting the Samba share? Has there been any more progress on this task? |
I think SMB1 or SMB2/3 are probably the wrong solution for OPL. The protocol is stateful and does need a decent amount of code just to run. For libsmb2 I estimate that without authentication and without encryption, with decently big effort, you could probably get the compiled minimal object down to 60-80kb in size. Maybe. A much better solution and SMALLER client code would be the (is it still beta?/prototype?) UDPDB support. That will do all smb1/2/3 can do but faster and with significantly smaller footprint. |
The server part seems to rely on Smbv1. I cannot connect the ps2 to a server running win7 or libreelec. Smbv1 is disabled on both systems, as it is deemed insecure nowadays. (Vulnerable to Ransomware).
Would you consider migrating to a more secure version of Samba? Otherwise a hint inside the readme would be great that Smbv1 needs to be activated to run opl and maybe that the server should not be connected to the internet for security reasons.
The text was updated successfully, but these errors were encountered: