mmap: accept non-PROT_WRITE MAP_SHARED mappings
[minix3.git] / lib / libnetdriver / netdriver.c
blob2b6d0271b96f0c8ade3a080a48624df2c01c823d
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, sef_self());
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 /* Let non-datalink requests through regardless. */
63 if (!IS_DL_RQ(m_ptr->m_type)) {
64 return r;
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;
72 else {
73 continue;
77 break;
80 return OK;