pkgin_all: script to auto-install all packages
[minix.git] / lib / libnetdriver / netdriver.c
blob8b49017d469cf9f9edc8da116432f7ce2f9f477e
1 /* This file contains device independent network device driver interface.
3 * Changes:
4 * Apr 01, 2010 Created (Cristiano Giuffrida)
6 * The file contains the following entry points:
8 * netdriver_announce: called by a network driver to announce it is up
9 * netdriver_receive: receive() interface for network drivers
12 #include <minix/drivers.h>
13 #include <minix/endpoint.h>
14 #include <minix/netdriver.h>
15 #include <minix/ds.h>
17 static int conf_expected = TRUE;
19 /*===========================================================================*
20 * netdriver_announce *
21 *===========================================================================*/
22 void netdriver_announce()
24 /* Announce we are up after a fresh start or restart. */
25 int r;
26 char key[DS_MAX_KEYLEN];
27 char label[DS_MAX_KEYLEN];
28 char *driver_prefix = "drv.net.";
30 /* Publish a driver up event. */
31 r = ds_retrieve_label_name(label, getprocnr());
32 if (r != OK) {
33 panic("driver_announce: unable to get own label: %d\n", r);
35 snprintf(key, DS_MAX_KEYLEN, "%s%s", driver_prefix, label);
36 r = ds_publish_u32(key, DS_DRIVER_UP, DSF_OVERWRITE);
37 if (r != OK) {
38 panic("driver_announce: unable to publish driver up event: %d\n", r);
41 conf_expected = TRUE;
44 /*===========================================================================*
45 * netdriver_receive *
46 *===========================================================================*/
47 int netdriver_receive(src, m_ptr, status_ptr)
48 endpoint_t src;
49 message *m_ptr;
50 int *status_ptr;
52 /* receive() interface for drivers. */
53 int r;
55 while (TRUE) {
56 /* Wait for a request. */
57 r = sef_receive_status(src, m_ptr, status_ptr);
58 if (r != OK) {
59 return r;
62 /* See if only DL_CONF is to be expected. */
63 if(conf_expected) {
64 if(m_ptr->m_type == DL_CONF) {
65 conf_expected = FALSE;
67 else {
68 continue;
72 break;
75 return OK;