Changeset 4f64a523 in mainline
- Timestamp:
- 2012-02-12T19:36:32Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- df15e5f
- Parents:
- 1493811
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/iplink_srv.c
r1493811 r4f64a523 41 41 #include <inet/iplink_srv.h> 42 42 43 static void iplink_get_mtu_srv(iplink_ conn_t *conn, ipc_callid_t callid,43 static void iplink_get_mtu_srv(iplink_srv_t *srv, ipc_callid_t callid, 44 44 ipc_call_t *call) 45 45 { … … 47 47 size_t mtu; 48 48 49 rc = conn->srv->ops->get_mtu(conn, &mtu);49 rc = srv->ops->get_mtu(srv, &mtu); 50 50 async_answer_1(callid, rc, mtu); 51 51 } 52 52 53 static void iplink_send_srv(iplink_ conn_t *conn, ipc_callid_t callid,53 static void iplink_send_srv(iplink_srv_t *srv, ipc_callid_t callid, 54 54 ipc_call_t *call) 55 55 { … … 66 66 } 67 67 68 rc = conn->srv->ops->send(conn, &sdu);68 rc = srv->ops->send(srv, &sdu); 69 69 free(sdu.data); 70 70 async_answer_0(callid, rc); 71 } 72 73 void iplink_srv_init(iplink_srv_t *srv) 74 { 75 fibril_mutex_initialize(&srv->lock); 76 srv->connected = false; 77 srv->ops = NULL; 78 srv->arg = NULL; 79 srv->client_sess = NULL; 71 80 } 72 81 … … 74 83 { 75 84 iplink_srv_t *srv = (iplink_srv_t *)arg; 76 iplink_conn_t conn;77 85 int rc; 86 87 fibril_mutex_lock(&srv->lock); 88 if (srv->connected) { 89 fibril_mutex_unlock(&srv->lock); 90 async_answer_0(iid, EBUSY); 91 return EBUSY; 92 } 93 94 srv->connected = true; 95 fibril_mutex_unlock(&srv->lock); 78 96 79 97 /* Accept the connection */ … … 84 102 return ENOMEM; 85 103 86 conn.srv = srv; 87 conn.client_sess = sess; 104 srv->client_sess = sess; 88 105 89 rc = srv->ops->open( &conn);106 rc = srv->ops->open(srv); 90 107 if (rc != EOK) 91 108 return rc; … … 104 121 switch (method) { 105 122 case IPLINK_GET_MTU: 106 iplink_get_mtu_srv( &conn, callid, &call);123 iplink_get_mtu_srv(srv, callid, &call); 107 124 break; 108 125 case IPLINK_SEND: 109 iplink_send_srv( &conn, callid, &call);126 iplink_send_srv(srv, callid, &call); 110 127 break; 111 128 default: … … 114 131 } 115 132 116 return srv->ops->close( &conn);133 return srv->ops->close(srv); 117 134 } 118 135 119 int iplink_ev_recv(iplink_ conn_t *conn, iplink_srv_sdu_t *sdu)136 int iplink_ev_recv(iplink_srv_t *srv, iplink_srv_sdu_t *sdu) 120 137 { 121 async_exch_t *exch = async_exchange_begin(conn->client_sess); 138 if (srv->client_sess == NULL) 139 return EIO; 140 141 async_exch_t *exch = async_exchange_begin(srv->client_sess); 122 142 123 143 ipc_call_t answer; -
uspace/lib/c/include/inet/iplink_srv.h
r1493811 r4f64a523 37 37 38 38 #include <async.h> 39 #include <fibril_synch.h> 40 #include <bool.h> 39 41 #include <sys/types.h> 40 42 … … 42 44 43 45 typedef struct { 46 fibril_mutex_t lock; 47 bool connected; 44 48 struct iplink_ops *ops; 45 49 void *arg; 50 async_sess_t *client_sess; 46 51 } iplink_srv_t; 47 48 typedef struct {49 iplink_srv_t *srv;50 async_sess_t *client_sess;51 } iplink_conn_t;52 52 53 53 typedef struct { … … 68 68 69 69 typedef struct iplink_ops { 70 int (*open)(iplink_ conn_t *);71 int (*close)(iplink_ conn_t *);72 int (*send)(iplink_ conn_t *, iplink_srv_sdu_t *);73 int (*get_mtu)(iplink_ conn_t *, size_t *);70 int (*open)(iplink_srv_t *); 71 int (*close)(iplink_srv_t *); 72 int (*send)(iplink_srv_t *, iplink_srv_sdu_t *); 73 int (*get_mtu)(iplink_srv_t *, size_t *); 74 74 } iplink_ops_t; 75 75 76 extern void iplink_srv_init(iplink_srv_t *); 77 76 78 extern int iplink_conn(ipc_callid_t, ipc_call_t *, void *); 77 extern int iplink_ev_recv(iplink_ conn_t *, iplink_srv_sdu_t *);79 extern int iplink_ev_recv(iplink_srv_t *, iplink_srv_sdu_t *); 78 80 79 81 #endif -
uspace/srv/ethip/ethip.c
r1493811 r4f64a523 52 52 #define NAME "eth" 53 53 54 static int ethip_open(iplink_ conn_t *conn);55 static int ethip_close(iplink_ conn_t *conn);56 static int ethip_send(iplink_ conn_t *conn, iplink_srv_sdu_t *sdu);57 static int ethip_get_mtu(iplink_ conn_t *conn, size_t *mtu);54 static int ethip_open(iplink_srv_t *srv); 55 static int ethip_close(iplink_srv_t *srv); 56 static int ethip_send(iplink_srv_t *srv, iplink_srv_sdu_t *sdu); 57 static int ethip_get_mtu(iplink_srv_t *srv, size_t *mtu); 58 58 59 59 static void ethip_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); … … 95 95 log_msg(LVL_DEBUG, "ethip_iplink_init()"); 96 96 97 iplink_srv_init(&nic->iplink); 97 98 nic->iplink.ops = ðip_iplink_ops; 98 99 nic->iplink.arg = nic; … … 148 149 } 149 150 150 static int ethip_open(iplink_ conn_t *conn)151 static int ethip_open(iplink_srv_t *srv) 151 152 { 152 153 log_msg(LVL_DEBUG, "ethip_open()"); … … 154 155 } 155 156 156 static int ethip_close(iplink_ conn_t *conn)157 { 158 log_msg(LVL_DEBUG, "ethip_ open()");159 return EOK; 160 } 161 162 static int ethip_send(iplink_ conn_t *conn, iplink_srv_sdu_t *sdu)163 { 164 ethip_nic_t *nic = (ethip_nic_t *) conn->srv->arg;157 static int ethip_close(iplink_srv_t *srv) 158 { 159 log_msg(LVL_DEBUG, "ethip_close()"); 160 return EOK; 161 } 162 163 static int ethip_send(iplink_srv_t *srv, iplink_srv_sdu_t *sdu) 164 { 165 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 165 166 eth_frame_t frame; 166 167 void *data; … … 188 189 int ethip_received(iplink_srv_t *srv, void *data, size_t size) 189 190 { 191 log_msg(LVL_DEBUG, "ethip_received(): srv=%p", srv); 192 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 190 193 eth_frame_t frame; 191 194 iplink_srv_sdu_t sdu; 192 195 int rc; 193 196 197 log_msg(LVL_DEBUG, "ethip_received()"); 198 199 log_msg(LVL_DEBUG, " - eth_pdu_decode"); 194 200 rc = eth_pdu_decode(data, size, &frame); 195 if (rc != EOK) 196 return rc; 197 201 if (rc != EOK) { 202 log_msg(LVL_DEBUG, " - eth_pdu_decode failed"); 203 return rc; 204 } 205 206 log_msg(LVL_DEBUG, " - construct SDU"); 207 sdu.lsrc.ipv4 = (192 << 24) | (168 << 16) | (0 << 8) | 1; 208 sdu.ldest.ipv4 = (192 << 24) | (168 << 16) | (0 << 8) | 4; 198 209 sdu.data = frame.data; 199 210 sdu.size = frame.size; 200 (void) sdu;201 //rc = iplink_ev_recv(conn, &sdu);211 log_msg(LVL_DEBUG, " - call iplink_ev_recv"); 212 rc = iplink_ev_recv(&nic->iplink, &sdu); 202 213 203 214 free(frame.data); … … 205 216 } 206 217 207 static int ethip_get_mtu(iplink_ conn_t *conn, size_t *mtu)218 static int ethip_get_mtu(iplink_srv_t *srv, size_t *mtu) 208 219 { 209 220 log_msg(LVL_DEBUG, "ethip_get_mtu()"); -
uspace/srv/ethip/ethip_nic.c
r1493811 r4f64a523 158 158 } 159 159 160 rc = nic_set_state(nic->sess, NIC_STATE_ACTIVE);161 if (rc != EOK) {162 log_msg(LVL_ERROR, "Failed activating NIC '%s'.",163 nic->svc_name);164 goto error;165 }166 167 160 log_msg(LVL_DEBUG, "Opened NIC '%s'", nic->svc_name); 168 161 list_append(&nic->nic_list, ðip_nic_list); … … 172 165 if (rc != EOK) 173 166 goto error; 167 168 rc = nic_set_state(nic->sess, NIC_STATE_ACTIVE); 169 if (rc != EOK) { 170 log_msg(LVL_ERROR, "Failed activating NIC '%s'.", 171 nic->svc_name); 172 goto error; 173 } 174 174 175 175 log_msg(LVL_DEBUG, "Initialized IP link service."); … … 205 205 size_t size; 206 206 207 log_msg(LVL_DEBUG, "ethip_nic_received() ");207 log_msg(LVL_DEBUG, "ethip_nic_received() nic=%p", nic); 208 208 209 209 rc = async_data_write_accept(&data, false, 0, 0, 0, &size); … … 213 213 } 214 214 215 log_msg(LVL_DEBUG, "call ethip_received"); 215 216 rc = ethip_received(&nic->iplink, data, size); 217 log_msg(LVL_DEBUG, "free data"); 216 218 free(data); 217 219 … … 228 230 static void ethip_nic_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 229 231 { 230 ethip_nic_t *nic ;232 ethip_nic_t *nic = (ethip_nic_t *)arg; 231 233 232 234 log_msg(LVL_DEBUG, "ethnip_nic_cb_conn()");
Note:
See TracChangeset
for help on using the changeset viewer.