Move device registration out of lookup_devices(), now living in register_device().

set_mtu() hook implemented.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3272 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2003-05-20 23:41:42 +00:00
parent cf86e4612e
commit 885d94cdfd

View File

@ -27,6 +27,7 @@ enum {
typedef struct ethernet_interface {
ifnet_t ifnet;
int fd;
int max_frame_size;
} ethernet_interface;
#define ETHER_ADDR_LEN 6 /* Ethernet address length */
@ -44,6 +45,7 @@ typedef struct ether_addr {
} ether_addr_t;
status_t lookup_devices(char *root, void *cookie);
status_t register_device(const char *path, void *cookie);
status_t std_ops(int32 op, ...);
struct net_interface_module_info nimi;
@ -87,6 +89,7 @@ status_t send(ifnet_t *iface, net_data *data)
if (!data)
return B_ERROR;
// TODO!
return B_OK;
}
@ -128,7 +131,18 @@ status_t get_hardware_address(ifnet_t *iface, net_interface_hwaddr *hwaddr) { re
status_t get_multicast_addresses(ifnet_t *iface, net_interface_hwaddr **hwaddr, int nb_addresses) { return -1; }
status_t set_multicast_addresses(ifnet_t *iface, net_interface_hwaddr *hwaddr, int nb_addresses) { return -1; }
status_t set_mtu(ifnet_t *iface, uint32 mtu) { return -1; }
status_t set_mtu(ifnet_t *iface, uint32 mtu)
{
ethernet_interface *ei = (ethernet_interface *) iface;
if (mtu > ei->max_frame_size)
// hardware constraint always win!
mtu = ei->max_frame_size;
ei->ifnet.if_mtu = mtu;
return B_OK;
}
status_t set_promiscuous(ifnet_t *iface, bool enable) { return -1; }
status_t set_media(ifnet_t *iface, uint32 media) { return -1; }
@ -141,7 +155,6 @@ status_t lookup_devices(char *root, void *cookie)
struct stat st;
char path[1024];
status_t status;
int fd;
dir = opendir(root);
if (!dir) {
@ -165,76 +178,11 @@ status_t lookup_devices(char *root, void *cookie)
if (S_ISDIR(st.st_mode))
status = lookup_devices(path, cookie);
else if (S_ISCHR(st.st_mode)) { // char device = driver!
ifnet_t *iface;
ethernet_interface *ei;
int frame_size;
ether_addr_t mac_address;
if (strcmp(de->d_name, "stack") == 0 || // OBOS stack driver
strcmp(de->d_name, "api") == 0) // BONE stack driver
continue; // skip pseudo-entries
fd = open(path, O_RDWR);
if (fd < B_OK) {
printf("ethernet: Unable to open(%s) -> %d [%s]. Skipping...\n", path,
fd, strerror(fd));
status = fd;
continue;
};
// Init the network card
status = ioctl(fd, ETHER_INIT, NULL, 0);
if (status < B_OK) {
printf("ethernet: Failed to init %s: %ld [%s]. Skipping...\n", path,
status, strerror(status));
close(fd);
continue;
};
// get the MAC address...
status = ioctl(fd, ETHER_GETADDR, &mac_address, 6);
if (status < B_OK) {
printf("ethernet: Failed to get %s MAC address: %ld [%s]. Skipping...\n",
path, status, strerror(status));
close(fd);
continue;
};
// Try to determine the MTU to use
status = ioctl(fd, ETHER_GETFRAMESIZE, &frame_size, sizeof(frame_size));
if (status < B_OK) {
frame_size = ETHERMTU;
printf("ethernet: %s device don't support IF_GETFRAMESIZE; defaulting to %d\n",
path, frame_size);
};
printf("ethernet: interface '%s':\n"
"\tMAC address: %02x:%02x:%02x:%02x:%02x:%02x\n"
"\tMTU: %d bytes\n",
path,
mac_address.byte[0], mac_address.byte[1],
mac_address.byte[2], mac_address.byte[3],
mac_address.byte[4], mac_address.byte[5], frame_size);
ei = (ethernet_interface *) malloc(sizeof(*ei));
if (!ei)
break;
ei->fd = fd;
iface = &ei->ifnet;
iface->if_name = strdup(path);
iface->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
iface->if_type = 0x20;
iface->if_mtu = frame_size;
iface->module = &nimi;
status = g_stack->register_interface(iface);
status = register_device(path, cookie);
};
};
@ -243,6 +191,78 @@ status_t lookup_devices(char *root, void *cookie)
return status;
}
status_t register_device(const char *path, void *cookie)
{
ifnet_t *iface;
ethernet_interface *ei;
int frame_size;
ether_addr_t mac_address;
int fd;
status_t status;
fd = open(path, O_RDWR);
if (fd < B_OK) {
printf("ethernet: Unable to open(%s) -> %d [%s]. Skipping...\n", path,
fd, strerror(fd));
return fd;
};
// Init the network card
status = ioctl(fd, ETHER_INIT, NULL, 0);
if (status < B_OK) {
printf("ethernet: Failed to init %s: %ld [%s]. Skipping...\n", path,
status, strerror(status));
close(fd);
return status;
};
// get the MAC address...
status = ioctl(fd, ETHER_GETADDR, &mac_address, 6);
if (status < B_OK) {
printf("ethernet: Failed to get %s MAC address: %ld [%s]. Skipping...\n",
path, status, strerror(status));
close(fd);
return status;
};
// Try to determine the MTU to use
status = ioctl(fd, ETHER_GETFRAMESIZE, &frame_size, sizeof(frame_size));
if (status < B_OK) {
frame_size = ETHERMTU;
printf("ethernet: %s device don't support IF_GETFRAMESIZE; defaulting to %d\n",
path, frame_size);
};
printf("ethernet: interface '%s':\n"
"\tMAC address: %02x:%02x:%02x:%02x:%02x:%02x\n"
"\tMTU: %d bytes\n",
path,
mac_address.byte[0], mac_address.byte[1],
mac_address.byte[2], mac_address.byte[3],
mac_address.byte[4], mac_address.byte[5], frame_size);
ei = (ethernet_interface *) malloc(sizeof(*ei));
if (!ei) {
close(fd);
return B_NO_MEMORY;
};
ei->fd = fd;
ei->max_frame_size = frame_size;
iface = &ei->ifnet;
iface->if_name = strdup(path);
iface->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
iface->if_type = 0x20; // IFT_ETHER;
iface->if_mtu = frame_size;
iface->module = &nimi;
return g_stack->register_interface(iface);
}
// #pragma mark -
status_t std_ops(int32 op, ...)