1*433d6423SLionel Sambuc #include "inc.h"
2*433d6423SLionel Sambuc
3*433d6423SLionel Sambuc char buf_buf[BUF_SIZE + CLICK_SIZE];
4*433d6423SLionel Sambuc
5*433d6423SLionel Sambuc /* SEF functions and variables. */
6*433d6423SLionel Sambuc static void sef_local_startup(void);
7*433d6423SLionel Sambuc
8*433d6423SLionel Sambuc /*===========================================================================*
9*433d6423SLionel Sambuc * main *
10*433d6423SLionel Sambuc *===========================================================================*/
main(int argc,char ** argv)11*433d6423SLionel Sambuc int main(int argc, char **argv)
12*433d6423SLionel Sambuc {
13*433d6423SLionel Sambuc endpoint_t ep_self, ep_requestor;
14*433d6423SLionel Sambuc int fid_send, fid_get;
15*433d6423SLionel Sambuc cp_grant_id_t gid;
16*433d6423SLionel Sambuc char *buf;
17*433d6423SLionel Sambuc int i;
18*433d6423SLionel Sambuc
19*433d6423SLionel Sambuc /* SEF local startup. */
20*433d6423SLionel Sambuc env_setargs(argc, argv);
21*433d6423SLionel Sambuc sef_local_startup();
22*433d6423SLionel Sambuc
23*433d6423SLionel Sambuc /* Prepare work. */
24*433d6423SLionel Sambuc buf = (char*) CLICK_CEIL(buf_buf);
25*433d6423SLionel Sambuc fid_send = open(FIFO_GRANTOR, O_WRONLY);
26*433d6423SLionel Sambuc fid_get = open(FIFO_REQUESTOR, O_RDONLY);
27*433d6423SLionel Sambuc if(fid_get < 0 || fid_send < 0) {
28*433d6423SLionel Sambuc printf("GRANTOR: can't open fifo files.\n");
29*433d6423SLionel Sambuc return 1;
30*433d6423SLionel Sambuc }
31*433d6423SLionel Sambuc buf[0] = BUF_START;
32*433d6423SLionel Sambuc
33*433d6423SLionel Sambuc /* Get the requestor's endpoint. */
34*433d6423SLionel Sambuc read(fid_get, &ep_requestor, sizeof(ep_requestor));
35*433d6423SLionel Sambuc dprint(("GRANTOR: getting requestor's endpoint: %d\n", ep_requestor));
36*433d6423SLionel Sambuc
37*433d6423SLionel Sambuc /* Grant. */
38*433d6423SLionel Sambuc gid = cpf_grant_direct(ep_requestor, (long)buf, BUF_SIZE,
39*433d6423SLionel Sambuc CPF_READ | CPF_WRITE);
40*433d6423SLionel Sambuc ep_self = sef_self();
41*433d6423SLionel Sambuc dprint(("GRANTOR: sending my endpoint %d and gid %d\n", ep_self, gid));
42*433d6423SLionel Sambuc write(fid_send, &ep_self, sizeof(ep_self));
43*433d6423SLionel Sambuc write(fid_send, &gid, sizeof(gid));
44*433d6423SLionel Sambuc
45*433d6423SLionel Sambuc /* Wait till requestor is done. */
46*433d6423SLionel Sambuc FIFO_WAIT(fid_get);
47*433d6423SLionel Sambuc
48*433d6423SLionel Sambuc return 0;
49*433d6423SLionel Sambuc }
50*433d6423SLionel Sambuc
51*433d6423SLionel Sambuc /*===========================================================================*
52*433d6423SLionel Sambuc * sef_local_startup *
53*433d6423SLionel Sambuc *===========================================================================*/
sef_local_startup()54*433d6423SLionel Sambuc static void sef_local_startup()
55*433d6423SLionel Sambuc {
56*433d6423SLionel Sambuc /* Let SEF perform startup. */
57*433d6423SLionel Sambuc sef_startup();
58*433d6423SLionel Sambuc }
59*433d6423SLionel Sambuc
60