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
@@ -27,6 +27,7 @@ enum {
typedef struct ethernet_interface { typedef struct ethernet_interface {
ifnet_t ifnet; ifnet_t ifnet;
int fd; int fd;
int max_frame_size;
} ethernet_interface; } ethernet_interface;
#define ETHER_ADDR_LEN 6 /* Ethernet address length */ #define ETHER_ADDR_LEN 6 /* Ethernet address length */
@@ -44,6 +45,7 @@ typedef struct ether_addr {
} ether_addr_t; } ether_addr_t;
status_t lookup_devices(char *root, void *cookie); status_t lookup_devices(char *root, void *cookie);
status_t register_device(const char *path, void *cookie);
status_t std_ops(int32 op, ...); status_t std_ops(int32 op, ...);
struct net_interface_module_info nimi; struct net_interface_module_info nimi;
@@ -87,6 +89,7 @@ status_t send(ifnet_t *iface, net_data *data)
if (!data) if (!data)
return B_ERROR; return B_ERROR;
// TODO!
return B_OK; 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 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_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_promiscuous(ifnet_t *iface, bool enable) { return -1; }
status_t set_media(ifnet_t *iface, uint32 media) { 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; struct stat st;
char path[1024]; char path[1024];
status_t status; status_t status;
int fd;
dir = opendir(root); dir = opendir(root);
if (!dir) { if (!dir) {
@@ -165,21 +178,34 @@ status_t lookup_devices(char *root, void *cookie)
if (S_ISDIR(st.st_mode)) if (S_ISDIR(st.st_mode))
status = lookup_devices(path, cookie); status = lookup_devices(path, cookie);
else if (S_ISCHR(st.st_mode)) { // char device = driver! else if (S_ISCHR(st.st_mode)) { // char device = driver!
if (strcmp(de->d_name, "stack") == 0 || // OBOS stack driver
strcmp(de->d_name, "api") == 0) // BONE stack driver
continue; // skip pseudo-entries
status = register_device(path, cookie);
};
};
closedir(dir);
return status;
}
status_t register_device(const char *path, void *cookie)
{
ifnet_t *iface; ifnet_t *iface;
ethernet_interface *ei; ethernet_interface *ei;
int frame_size; int frame_size;
ether_addr_t mac_address; ether_addr_t mac_address;
int fd;
if (strcmp(de->d_name, "stack") == 0 || // OBOS stack driver status_t status;
strcmp(de->d_name, "api") == 0) // BONE stack driver
continue; // skip pseudo-entries
fd = open(path, O_RDWR); fd = open(path, O_RDWR);
if (fd < B_OK) { if (fd < B_OK) {
printf("ethernet: Unable to open(%s) -> %d [%s]. Skipping...\n", path, printf("ethernet: Unable to open(%s) -> %d [%s]. Skipping...\n", path,
fd, strerror(fd)); fd, strerror(fd));
status = fd; return fd;
continue;
}; };
// Init the network card // Init the network card
@@ -188,7 +214,7 @@ status_t lookup_devices(char *root, void *cookie)
printf("ethernet: Failed to init %s: %ld [%s]. Skipping...\n", path, printf("ethernet: Failed to init %s: %ld [%s]. Skipping...\n", path,
status, strerror(status)); status, strerror(status));
close(fd); close(fd);
continue; return status;
}; };
// get the MAC address... // get the MAC address...
@@ -197,10 +223,9 @@ status_t lookup_devices(char *root, void *cookie)
printf("ethernet: Failed to get %s MAC address: %ld [%s]. Skipping...\n", printf("ethernet: Failed to get %s MAC address: %ld [%s]. Skipping...\n",
path, status, strerror(status)); path, status, strerror(status));
close(fd); close(fd);
continue; return status;
}; };
// Try to determine the MTU to use // Try to determine the MTU to use
status = ioctl(fd, ETHER_GETFRAMESIZE, &frame_size, sizeof(frame_size)); status = ioctl(fd, ETHER_GETFRAMESIZE, &frame_size, sizeof(frame_size));
if (status < B_OK) { if (status < B_OK) {
@@ -217,30 +242,25 @@ status_t lookup_devices(char *root, void *cookie)
mac_address.byte[2], mac_address.byte[3], mac_address.byte[2], mac_address.byte[3],
mac_address.byte[4], mac_address.byte[5], frame_size); mac_address.byte[4], mac_address.byte[5], frame_size);
ei = (ethernet_interface *) malloc(sizeof(*ei)); ei = (ethernet_interface *) malloc(sizeof(*ei));
if (!ei) if (!ei) {
break; close(fd);
return B_NO_MEMORY;
};
ei->fd = fd; ei->fd = fd;
ei->max_frame_size = frame_size;
iface = &ei->ifnet; iface = &ei->ifnet;
iface->if_name = strdup(path); iface->if_name = strdup(path);
iface->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST); iface->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST);
iface->if_type = 0x20; iface->if_type = 0x20; // IFT_ETHER;
iface->if_mtu = frame_size; iface->if_mtu = frame_size;
iface->module = &nimi; iface->module = &nimi;
status = g_stack->register_interface(iface); return g_stack->register_interface(iface);
};
};
closedir(dir);
return status;
} }
// #pragma mark - // #pragma mark -