Broadband adapter

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Chilly Willy
DC Developer
DC Developer
Posts: 414
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Broadband adapter

Post by Chilly Willy »

Okay, I got my BBA and it works fine with PlanetWeb 3.0. The issue now is how to use it in the homebrew... first, it doesn't seem that you get any ISP settings in the flashrom with PW3. This

Code: Select all

	if (flashrom_get_ispcfg(&cfg) < 0) {
		printf("Couldn't find any IP-related config info!\n");
		sprintf(dc_net_ipaddr, "127.0.0.1");
		dc_net_available = 0;
	} else {
		if (cfg.valid_fields & FLASHROM_ISP_IP) {
			sprintf(dc_net_ipaddr, "%d.%d.%d.%d", cfg.ip[0], cfg.ip[1], cfg.ip[2], cfg.ip[3]);
			printf("Local IP: %s\n", dc_net_ipaddr);
			dc_net_available = 1;
		}
		if (cfg.valid_fields & FLASHROM_ISP_DNS) {
			dc_net_dnssrv.sin_family = AF_INET;
			dc_net_dnssrv.sin_port = htons(53);
			dc_net_dnssrv.sin_addr.s_addr = htonl(*(int *)cfg.dns[0]);
			printf(" DNS: %x\n", dc_net_dnssrv.sin_addr.s_addr);
		}
	}
tells me there's nothing in the flash for the BBA. Looking around, PW3 seems to write a file to the VMU called "PW_BROADBAND" - a look at netcfg_load() shows that such a file isn't even considered... it's looking for something called "net.cfg". Maybe a brief overview on how to init the DC network would be nice... how to get the local IP address given it's not in the flash. Once the DC part is out of the way, the rest is just sockets. It's that DC part that's giving me problems.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Broadband adapter

Post by BlueCrab »

I didn't (and still don't) have a copy of PlanetWeb 3.0 when I wrote the expanded ISP configuration functionality. You might try using the

Code: Select all

int flashrom_get_pw_ispcfg(flashrom_ispcfg_t *out)
function to see if you get anything out of PlanetWeb 3.0, but I somewhat doubt it with broadband (it should pick up the Dial-Up ISP configuration properly though).

The way to get ISP configuration in there that the flashrom_get_ispcfg() function will read properly (and if you're using the built-in network stack, will auto-configure the BBA) is to use DreamPassport (a later version that supports the BBA) or Phantasy Star Online v2 (US or JP) to configure the ISP settings.
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Broadband adapter

Post by Chilly Willy »

Hmm - sounds like a homebrew is needed for setting this info.

I'm using lwip, using

Code: Select all

  net_init();
  lwip_kos_init();
To init things as the "example" shows. Will that "auto-configure" the BBA? If so, then is there a lwip way of getting the local IP address? The example simply inits then looks for any incoming packet... not very helpful. There also seems to be a dearth of games using networking so far... probably for the same reasons I'm having trouble.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Broadband adapter

Post by BlueCrab »

I've honestly not touched lwIP for an extremely long time (so much so that I'm surprised that I've been told it still works, especially with all the changes made to the non-lwIP stack), so unfortunately I have no idea how to go about things using lwIP.... Sorry....
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Broadband adapter

Post by Chilly Willy »

Well, how about the KOS networking? I know from other threads it just does UDP, but that's all that's needed anyway. Are you aware of other DC stuff with source that uses networking I can use as an example? Otherwise I'm gonna have to dig through all the source... which is always a pain. :( :grin:
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Broadband adapter

Post by BlueCrab »

Chilly Willy wrote:Well, how about the KOS networking? I know from other threads it just does UDP, but that's all that's needed anyway. Are you aware of other DC stuff with source that uses networking I can use as an example? Otherwise I'm gonna have to dig through all the source... which is always a pain. :( :grin:
If you're just using UDP things should "Just Work" if you put NET_INIT in your KOS_INIT_FLAGS (including the dcload terminal and all). If you just use net_init, then things should also pretty much "Just Work" other than the dcload terminal/fs (assuming the network card has been configured in a way that it can be read with the flashrom_get_ispcfg() function.

Also, if you have DHCP on your network, which I'm sure almost everyone probably does, the built-in stack supports DHCP as well. I don't believe it will ever by default use DHCP to configure things, but that's just a simple case of calling net_dhcp_request() to actually handle setting that up.

Other than those few things, everything should just work like a normal machine that supports BSD-like sockets. The main header files are there, as are the main functions. I wrote most of that functionality, so if you have any specific questions, just let me know.

I'll try to throw together a working simple example a bit later, if you'd like me to.
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Broadband adapter

Post by Chilly Willy »

BlueCrab wrote:
Chilly Willy wrote:Well, how about the KOS networking? I know from other threads it just does UDP, but that's all that's needed anyway. Are you aware of other DC stuff with source that uses networking I can use as an example? Otherwise I'm gonna have to dig through all the source... which is always a pain. :( :grin:
If you're just using UDP things should "Just Work" if you put NET_INIT in your KOS_INIT_FLAGS (including the dcload terminal and all). If you just use net_init, then things should also pretty much "Just Work" other than the dcload terminal/fs (assuming the network card has been configured in a way that it can be read with the flashrom_get_ispcfg() function.

Also, if you have DHCP on your network, which I'm sure almost everyone probably does, the built-in stack supports DHCP as well. I don't believe it will ever by default use DHCP to configure things, but that's just a simple case of calling net_dhcp_request() to actually handle setting that up.

Other than those few things, everything should just work like a normal machine that supports BSD-like sockets. The main header files are there, as are the main functions. I wrote most of that functionality, so if you have any specific questions, just let me know.

I'll try to throw together a working simple example a bit later, if you'd like me to.
That would be helpful, thanks. In the meantime, I'll look over the KOS net stuff a bit more. And yes, I'm using DHCP in the router for all local computers/consoles.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Broadband adapter

Post by BlueCrab »

BlueCrab wrote:Also, if you have DHCP on your network, which I'm sure almost everyone probably does, the built-in stack supports DHCP as well. I don't believe it will ever by default use DHCP to configure things, but that's just a simple case of calling net_dhcp_request() to actually handle setting that up.
I take back the statement of it never automatically configuring things. I took another look at the code, and the built-in network code will try to initialize DHCP if the network device does not have a IP address after the initialization happens.

Practically, this means that unless there's stuff in the Dreamcast's flashrom for a static configuration of the BBA, it will always try DHCP to configure it at the end of net_init() (whether it gets called implicitly through the KOS_INIT_FLAGS or directly in your code).

Anyway... sorry for not putting up an example program for using KOS' built-in networking, but I honestly couldn't think of anything to show an example of. Really, there's little difference between KOS' built-in network stack and that which you would find on anything else that has BSD sockets. The only differences at the moment are:
  • No select() or poll() -- This is something I'd like to fix sometime soon.
  • No fcntl() or ioctl() -- In most cases the only time you'd use these is to set a socket to be non-blocking. There's a function for that specific case: fs_socket_setflags() which is in <kos/fs_socket.h>.
  • No socket types available other than UDP.
I wrote the sockets code to mostly comply with the Single UNIX Specification, so it should very much match what you'd expect on any computer.

Anyway, here's a really lame example of something somewhat interesting you can do with the KOS network stack... A really crappy "ping" program:

Code: Select all

/* KallistiOS ##version##

   ping.c
   Copyright (C) 2009 Lawrence Sebald

   This example is a very basic "ping" program, much like you might find on
   any computer. However, this version lacks many of the niceties you might find
   on a real OS' ping program.

*/

#include <stdio.h>

#include <arch/arch.h>
#include <kos/net.h>
#include <kos/thread.h>

KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET);

#define DATA_SIZE 56

int main(int argc, char *argv[]) {
    uint8 addr[4] = { 127, 0, 0, 1 };
    uint8 data[DATA_SIZE];
    int i;

    for(i = 0; i < DATA_SIZE; ++i) {
        data[i] = (uint8)i;
    }

    for(i = 0; i < 10; ++i) {
        net_icmp_send_echo(net_default_dev, addr, data, DATA_SIZE);
        thd_sleep(250);
    }

    thd_sleep(2 * 1000);

    return 0;
}
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Broadband adapter

Post by Chilly Willy »

Great! Thanks a bunch. Good thing you mentioned the setting non-blocking - that's the first thing the Doom networking does after creating the socket - set it to non-blocking. :grin:

You mentioned it getting the IP address in the init - what's the easiest way to find that IP address to display it? I do that in Doom to help people with their local IP address for local network games. Obviously, you just use something like http://www.whatismyip.com in a browser to get your IP address for non-local network games.

EDIT: I'm currently using the ip_addr from net_default_dev... giving that a try now to see what happens. :grin:
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Broadband adapter

Post by Chilly Willy »

Really odd - calling net_init() crashes the DC. If the ethernet cable is plugged in, it sits for a few seconds, then resets the DC and starts without a display. If the cable isn't plugged in, it resets almost instantly and goes back to the initial DC startup display.

I tried it again with net_init() removed and it comes up with the GUI fine, so it's definitely net_init() crashing. The code is simple:

Code: Select all

void dc_net_init (void)
{
#if 0
	if (net_init() != 0) {
		dc_net_available = 0;
	} else {
		netif_t *netdef = net_default_dev;
		dc_net_available = 1;
		sprintf(dc_net_ipaddr, "%d.%d.%d.%d", netdef->ip_addr[0], netdef->ip_addr[1], netdef->ip_addr[2], netdef->ip_addr[3]);
		dc_net_dnssrv.sin_family = AF_INET;
		dc_net_dnssrv.sin_port = htons(53);
		dc_net_dnssrv.sin_addr.s_addr = htonl(*(int *)netdef->dns[0]);
	}
#else
	dc_net_available = 0;
#endif
}
Set to 0, fine. Set to 1, DC crashes. I'm using the latest KOS checked out of the svn repo.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Broadband adapter

Post by BlueCrab »

If you use the INIT_NET in the KOS_INIT_FLAGS, then you should not call net_init() yourself -- it will do that for you. If you haven't set INIT_NET in the KOS_INIT_FLAGS, then I guess there's actually a bug somewhere... :?

Either way, it shouldn't crash... I'll take a look when I get a chance to do so.
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Broadband adapter

Post by Chilly Willy »

I'll try the flag... just need another way to check if the network initialized. Guess I could look to see if both net_default_dev is set and it has an IP address.

I don't use any of the init flags right now... perhaps the default is to init the net and so when I call net_init() it crashes because it's already initialized? I haven't looked into the DC startup that close yet.
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Broadband adapter

Post by Chilly Willy »

I added

Code: Select all

KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET);
and changed the init to

Code: Select all

void dc_net_init (void)
{
	netif_t *netdev = net_default_dev;

	if (netdev && netdev->ip_addr[0]) {
		dc_net_available = 1;
		sprintf(dc_net_ipaddr, "%d.%d.%d.%d", netdev->ip_addr[0], netdev->ip_addr[1], netdev->ip_addr[2], netdev->ip_addr[3]);
		dc_net_dnssrv.sin_family = AF_INET;
		dc_net_dnssrv.sin_port = htons(53);
		dc_net_dnssrv.sin_addr.s_addr = htonl(*(int *)&netdev->dns[0]);
	} else {
		dc_net_available = 0;
	}
}
and the behavior is dofferent - if you don't have the ethernet connected, it goes to the GUI like it should, if a few seconds slower than before. If you DO have the ethernet connected, if crashes before calling main. So I guess wherever the net is initialized in the code added by the flag is where it goes boom now. It's very interesting that it doesn't crash without the connection now where it did when calling net_init() explicitly.

The crash is a little different as well - where before it would crash and reset without video, it now crashes and goes to the DC startup with video.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Broadband adapter

Post by BlueCrab »

How are you running the program? Are you using dcload/dctool-ip (the network adapter version)?

If so, could you try running dcload with the -n flag and see if it still crashes? Unfortunately debugging the network setup is a bit.... difficult due to the fact that the dcload syscalls can't be used until the whole network stack is up and running (since when you're using networking KOS takes over the network interrupt), so the underlying dcload syscalls don't end up being called. Thus from the time right before net_init gets called until the time when fs_dclsocket is initialized, nothing will come out on the terminal.

Debugging networking related issues is always a bit of a pain...
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Broadband adapter

Post by Chilly Willy »

SBInducer made disc. I guess it's possible that that has something to do with it. I didn't have a network connection before, so obviously I couldn't have been using it. Can dcload/dctool-ip be run under linux?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Broadband adapter

Post by BlueCrab »

dc-tool was originally written for Linux, so of course it will. All you do is burn a dcload disc, and use dc-tool to upload your binaries. Nice and simple.
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Broadband adapter

Post by Chilly Willy »

BlueCrab wrote:dc-tool was originally written for Linux, so of course it will. All you do is burn a dcload disc, and use dc-tool to upload your binaries. Nice and simple.
Cool - I'll definitely have to try it... I've burned 57 CDRs in testing Doom - CDRs are cheap, but they add up eventually. With dcload/dctool, the BBA will have paid for itself pretty quick. :lol:
User avatar
Quzar
Dream Coder
Dream Coder
Posts: 7497
Joined: Wed Jul 31, 2002 12:14 am
Location: Miami, FL
Has thanked: 4 times
Been thanked: 9 times
Contact:

Re: Broadband adapter

Post by Quzar »

Chilly Willy wrote:
BlueCrab wrote:dc-tool was originally written for Linux, so of course it will. All you do is burn a dcload disc, and use dc-tool to upload your binaries. Nice and simple.
Cool - I'll definitely have to try it... I've burned 57 CDRs in testing Doom - CDRs are cheap, but they add up eventually. With dcload/dctool, the BBA will have paid for itself pretty quick. :lol:
57! You know you can just leave the disc open and tack on extra sessions right? I've never done it (as I started dev when I got my Coder's Cable) but that used to be the preferred way for many.
"When you post fewer lines of text than your signature, consider not posting at all." - A Wise Man
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Broadband adapter

Post by BlueCrab »

Quzar wrote:
Chilly Willy wrote:
BlueCrab wrote:dc-tool was originally written for Linux, so of course it will. All you do is burn a dcload disc, and use dc-tool to upload your binaries. Nice and simple.
Cool - I'll definitely have to try it... I've burned 57 CDRs in testing Doom - CDRs are cheap, but they add up eventually. With dcload/dctool, the BBA will have paid for itself pretty quick. :lol:
57! You know you can just leave the disc open and tack on extra sessions right? I've never done it (as I started dev when I got my Coder's Cable) but that used to be the preferred way for many.
That's how I started out before I got a Coder's Cable.
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Broadband adapter

Post by Chilly Willy »

Quzar wrote:57! You know you can just leave the disc open and tack on extra sessions right? I've never done it (as I started dev when I got my Coder's Cable) but that used to be the preferred way for many.
Clearly I didn't. :lol:

So why isn't that in a sticky? Oh well, learn something new every day.

Uh - quick question: since the BBA is using DHCP, how do I find the local IP address on the DC? It's not like it has ifconfig. That's part of the reason Doom shows the local IP address in the GUI - so that people know what to use on the other local systems they'll be playing against (assuming a local net game). I need the local IP address for dcload... it's actually hardcoded in the makefile.

Maybe a packet capture app and look for something I DON'T know what it is...
Post Reply