Run indent on files.

This commit is contained in:
Manoel Rebelo Abranches 2011-06-07 21:59:53 -03:00
parent 423a1849ef
commit 4700d08bb4
8 changed files with 307 additions and 288 deletions

View file

@ -13,7 +13,7 @@
static int fd;
static grub_err_t
static grub_err_t
send_card_buffer (struct grub_net_card *dev __attribute__ ((unused)),
struct grub_net_buff *pack)
{
@ -22,7 +22,7 @@ send_card_buffer (struct grub_net_card *dev __attribute__ ((unused)),
actual = write (fd, pack->data, pack->tail - pack->data);
if (actual < 0)
return grub_error (GRUB_ERR_IO, "couldn't send packets");
return GRUB_ERR_NONE;
}
@ -32,32 +32,32 @@ get_card_packet (struct grub_net_card *dev __attribute__ ((unused)),
{
ssize_t actual;
grub_netbuff_clear(pack);
grub_netbuff_clear (pack);
actual = read (fd, pack->data, 1500);
if (actual < 0)
return -1;
grub_netbuff_put (pack, actual);
return actual;
return actual;
}
static struct grub_net_card_driver emudriver =
{
.name = "emu",
.send = send_card_buffer,
.recv = get_card_packet
};
{
.name = "emu",
.send = send_card_buffer,
.recv = get_card_packet
};
static struct grub_net_card emucard =
{
.name = "emu0",
.driver = &emudriver,
.default_address = {
.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET,
{ .mac = { 0, 1, 2, 3, 4, 5} }
},
.flags = 0
};
{
.name = "emu0",
.driver = &emudriver,
.default_address = {
.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET,
{.mac = {0, 1, 2, 3, 4, 5}}
},
.flags = 0
};
GRUB_MOD_INIT(emunet)
{
@ -84,6 +84,3 @@ GRUB_MOD_FINI(emunet)
grub_net_card_unregister (&emucard);
}
}

View file

@ -7,15 +7,18 @@
GRUB_MOD_LICENSE ("GPLv3+");
static grub_err_t
static grub_err_t
card_open (struct grub_net_card *dev)
{
int status;
struct grub_ofnetcard_data *data = dev->data;
char path[grub_strlen(data->path) + grub_strlen(":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512") + 1];
char path[grub_strlen (data->path) +
grub_strlen (":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512") + 1];
/* The full string will prevent a bootp packet to be sent. Just put some valid ip in there. */
grub_snprintf(path,sizeof(path),"%s%s",data->path,":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512");
status = grub_ieee1275_open (path,&(data->handle));
grub_snprintf (path, sizeof (path), "%s%s", data->path,
":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512");
status = grub_ieee1275_open (path, &(data->handle));
if (status)
return grub_error (GRUB_ERR_IO, "Couldn't open network card.");
@ -23,23 +26,23 @@ card_open (struct grub_net_card *dev)
return GRUB_ERR_NONE;
}
static grub_err_t
static grub_err_t
card_close (struct grub_net_card *dev)
{
struct grub_ofnetcard_data *data = dev->data;
if (data->handle)
grub_ieee1275_close (data->handle);
return GRUB_ERR_NONE;
}
static grub_err_t
static grub_err_t
send_card_buffer (struct grub_net_card *dev, struct grub_net_buff *pack)
{
{
int actual;
int status;
struct grub_ofnetcard_data *data = dev->data;
status = grub_ieee1275_write (data->handle, pack->data,
pack->tail - pack->data, &actual);
@ -56,27 +59,27 @@ get_card_packet (struct grub_net_card *dev, struct grub_net_buff *nb)
struct grub_ofnetcard_data *data = dev->data;
grub_uint64_t start_time;
grub_netbuff_clear (nb);
grub_netbuff_clear (nb);
start_time = grub_get_time_ms ();
do
rc = grub_ieee1275_read (data->handle, nb->data, data->mtu, &actual);
while ((actual <= 0 || rc < 0) && (grub_get_time_ms () - start_time < 200));
if (actual)
{
grub_netbuff_put (nb, actual);
grub_netbuff_put (nb, actual);
return actual;
}
return -1;
}
static struct grub_net_card_driver ofdriver =
{
.name = "ofnet",
.init = card_open,
.fini = card_close,
.send = send_card_buffer,
.recv = get_card_packet
};
static struct grub_net_card_driver ofdriver =
{
.name = "ofnet",
.init = card_open,
.fini = card_close,
.send = send_card_buffer,
.recv = get_card_packet
};
static const struct
{
@ -84,23 +87,23 @@ static const struct
int offset;
}
bootp_response_properties[] =
{
{ .name = "bootp-response", .offset = 0 },
{ .name = "dhcp-response", .offset = 0 },
{ .name = "bootpreply-packet", .offset = 0x2a },
};
bootp_response_properties[] =
{
{ .name = "bootp-response", .offset = 0},
{ .name = "dhcp-response", .offset = 0},
{ .name = "bootpreply-packet", .offset = 0x2a},
};
static grub_bootp_t
grub_getbootp_real ( void )
static grub_bootp_t
grub_getbootp_real (void)
{
grub_bootp_t packet = grub_malloc (sizeof *packet);
char *bootp_response;
char *bootp_response;
grub_ssize_t size;
unsigned int i;
for ( i = 0; i < ARRAY_SIZE (bootp_response_properties); i++)
if (grub_ieee1275_get_property_length (grub_ieee1275_chosen,
for (i = 0; i < ARRAY_SIZE (bootp_response_properties); i++)
if (grub_ieee1275_get_property_length (grub_ieee1275_chosen,
bootp_response_properties[i].name,
&size) >= 0)
break;
@ -111,8 +114,7 @@ grub_getbootp_real ( void )
bootp_response = grub_malloc (size);
if (grub_ieee1275_get_property (grub_ieee1275_chosen,
bootp_response_properties[i].name,
bootp_response ,
size, 0) < 0)
bootp_response, size, 0) < 0)
return NULL;
grub_memcpy (packet, bootp_response + bootp_response_properties[i].offset, sizeof (*packet));
@ -120,52 +122,55 @@ grub_getbootp_real ( void )
return packet;
}
static
void grub_ofnet_findcards (void)
static void
grub_ofnet_findcards (void)
{
struct grub_net_card *card;
grub_ieee1275_phandle_t devhandle;
grub_net_link_level_address_t lla;
grub_net_link_level_address_t lla;
int i = 0;
auto int search_net_devices (struct grub_ieee1275_devalias *alias);
int search_net_devices (struct grub_ieee1275_devalias *alias)
{
if ( !grub_strcmp (alias->type,"network") )
{
card = grub_malloc (sizeof (struct grub_net_card));
struct grub_ofnetcard_data *ofdata = grub_malloc (sizeof (struct grub_ofnetcard_data));
ofdata->path = grub_strdup (alias->path);
grub_ieee1275_finddevice (ofdata->path, &devhandle);
if (grub_ieee1275_get_integer_property
(devhandle, "max-frame-size", &(ofdata->mtu), sizeof (ofdata->mtu), 0))
return grub_error (GRUB_ERR_IO, "Couldn't retrieve mtu size.");
{
if (!grub_strcmp (alias->type, "network"))
{
if (grub_ieee1275_get_property (devhandle, "mac-address", &(lla.mac), 6, 0))
return grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address.");
lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
card->default_address = lla;
card = grub_malloc (sizeof (struct grub_net_card));
struct grub_ofnetcard_data *ofdata =
grub_malloc (sizeof (struct grub_ofnetcard_data));
ofdata->path = grub_strdup (alias->path);
card->driver = NULL;
card->data = ofdata;
grub_ieee1275_finddevice (ofdata->path, &devhandle);
if (grub_ieee1275_get_integer_property
(devhandle, "max-frame-size", &(ofdata->mtu),
sizeof (ofdata->mtu), 0))
return grub_error (GRUB_ERR_IO, "Couldn't retrieve mtu size.");
if (grub_ieee1275_get_property
(devhandle, "mac-address", &(lla.mac), 6, 0))
return grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address.");
lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
card->default_address = lla;
card->driver = NULL;
card->data = ofdata;
card->flags = 0;
card->name = grub_xasprintf("eth%d",i++); // grub_strdup (alias->name);
grub_net_card_register (card);
card->name = grub_xasprintf ("eth%d", i++);
grub_net_card_register (card);
return 0;
}
return 0;
}
return 0;
}
/* Look at all nodes for devices of the type network. */
grub_ieee1275_devices_iterate (search_net_devices);
}
static
void grub_ofnet_probecards (void)
static void
grub_ofnet_probecards (void)
{
struct grub_net_card *card;
struct grub_net_card_driver *driver;
@ -175,19 +180,21 @@ void grub_ofnet_probecards (void)
grub_net_network_level_netaddress_t net;
bootp_pckt = grub_getbootp ();
/* Assign correspondent driver for each device. */
/* Assign correspondent driver for each device. */
FOR_NET_CARDS (card)
{
FOR_NET_CARD_DRIVERS (driver)
{
if (driver->init(card) == GRUB_ERR_NONE)
if (driver->init (card) == GRUB_ERR_NONE)
{
card->driver = driver;
if (bootp_pckt && grub_memcmp(bootp_pckt->chaddr,card->default_address.mac,6) == 0)
if (bootp_pckt
&& grub_memcmp (bootp_pckt->chaddr, card->default_address.mac, 6) == 0)
{
addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
addr.ipv4 = bootp_pckt->yiaddr;
grub_net_add_addr ("bootp_cli_addr", card, addr, card->default_address, 0);
grub_net_add_addr ("bootp_cli_addr", card, addr,
card->default_address, 0);
FOR_NET_NETWORK_LEVEL_INTERFACES (inter)
if (grub_strcmp (inter->name, "bootp_cli_addr") == 0)
break;
@ -197,30 +204,27 @@ void grub_ofnet_probecards (void)
grub_net_add_route ("bootp-router", net, inter);
}
break;
}
}
}
}
grub_free (bootp_pckt);
}
GRUB_MOD_INIT (ofnet)
GRUB_MOD_INIT(ofnet)
{
struct grub_net_card *card;
grub_getbootp = grub_getbootp_real;
grub_net_card_driver_register (&ofdriver);
grub_ofnet_findcards ();
grub_ofnet_probecards ();
FOR_NET_CARDS (card)
grub_ofnet_findcards ();
grub_ofnet_probecards ();
FOR_NET_CARDS (card)
if (card->driver == NULL)
grub_net_card_unregister (card);
}
GRUB_MOD_FINI (ofnet)
GRUB_MOD_FINI(ofnet)
{
grub_net_card_driver_unregister (&ofdriver);
grub_getbootp = NULL;
}