xref: /minix/minix/lib/libnetdriver/netdriver.c (revision 83133719)
1 /* This file contains device independent network device driver interface.
2  *
3  * Changes:
4  *   Apr 01, 2010   Created  (Cristiano Giuffrida)
5  *
6  * The file contains the following entry points:
7  *
8  *   netdriver_announce: called by a network driver to announce it is up
9  *   netdriver_receive:	 receive() interface for network drivers
10  */
11 
12 #include <minix/drivers.h>
13 #include <minix/endpoint.h>
14 #include <minix/netdriver.h>
15 #include <minix/ds.h>
16 
17 static int conf_expected = TRUE;
18 
19 /*===========================================================================*
20  *			    netdriver_announce				     *
21  *===========================================================================*/
22 void netdriver_announce()
23 {
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.";
29 
30   /* Publish a driver up event. */
31   r = ds_retrieve_label_name(label, sef_self());
32   if (r != OK) {
33 	panic("driver_announce: unable to get own label: %d\n", r);
34   }
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);
39   }
40 
41   conf_expected = TRUE;
42 }
43 
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;
51 {
52 /* receive() interface for drivers. */
53   int r;
54 
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;
60 	}
61 
62 	/* Let non-datalink requests through regardless. */
63 	if (!IS_DL_RQ(m_ptr->m_type)) {
64 		return r;
65 	}
66 
67 	/* See if only DL_CONF is to be expected. */
68 	if(conf_expected) {
69 		if(m_ptr->m_type == DL_CONF) {
70 			conf_expected = FALSE;
71 		}
72 		else {
73 			continue;
74 		}
75 	}
76 
77 	break;
78   }
79 
80   return OK;
81 }
82 
83