FreeBSD/sys/dev/usb/misc/udbp.c
/*
 * Get a netgraph control message.
 * Check it is one we understand. If needed, send a response.
 * We could save the address for an async action later, but don't here.
 * Always free the message.
 * The response should be in a malloc'd region that the caller can 'free'.
 * A response is not required.
 * Theoretically you could respond defferently to old message types if
 * the cookie in the header didn't match what we consider to be current
 * (so that old userland programs could continue to work).
 */
Get a netgraph control message.
Check it is one we understand. If needed, send a response.
We could save the address for an async action later, but don't here.
Always free the message.
The response should be in a malloc'd region that the caller can 'free'.
A response is not required.
Theoretically you could respond defferently to old message types if
the cookie in the header didn't match what we consider to be current
(so that old userland programs could continue to work).
Get a netgraph control message . Check it is one we understand . If needed send a response . We could save the address for an async action later but don ' t here . Always free the message . The response should be in a malloc ' d region that the caller can ' free ' . A response is not required . Theoretically you could respond defferently to old message types if the cookie in the header didn ' t match what we consider to be current ( so that old userland programs could continue to work ) .
static int
ng_udbp_rcvmsg(node_p node, item_p item, hook_p lasthook)
{
	struct udbp_softc *sc = NG_NODE_PRIVATE(node);
	struct ng_mesg *resp = NULL;
	int error = 0;
	struct ng_mesg *msg;
	NGI_GET_MSG(item, msg);
	switch (msg->header.typecookie) {
	case NGM_UDBP_COOKIE:
		switch (msg->header.cmd) {
		case NGM_UDBP_GET_STATUS:
			{
				struct ngudbpstat *stats;
				NG_MKRESPONSE(resp, msg, sizeof(*stats), M_NOWAIT);
				if (!resp) {
					error = ENOMEM;
					break;
				}
				stats = (struct ngudbpstat *)resp->data;
				mtx_lock(&sc->sc_mtx);
				stats->packets_in = sc->sc_packets_in;
				stats->packets_out = sc->sc_packets_out;
				mtx_unlock(&sc->sc_mtx);
				break;
			}
		case NGM_UDBP_SET_FLAG:
			if (msg->header.arglen != sizeof(uint32_t)) {
				error = EINVAL;
				break;
			}
			DPRINTF("flags = 0x%08x\n",
			    *((uint32_t *)msg->data));
			break;
		default:
			error = EINVAL;	
			break;
		}
		break;
	default:
		error = EINVAL;		
		break;
	}
	NG_RESPOND_MSG(error, node, item, resp);
	NG_FREE_MSG(msg);
	return (error);
}
static int ng_udbp_rcvmsg ( node_p node , item_p item , hook_p lasthook ) { struct udbp_softc * sc = NG_NODE_PRIVATE ( node ) ; struct ng_mesg * resp = NULL ; int error = 0 ; struct ng_mesg * msg ; NGI_GET_MSG ( item , msg ) ; switch ( msg -> header . typecookie ) { case NGM_UDBP_COOKIE : switch ( msg -> header . cmd ) { case NGM_UDBP_GET_STATUS : { struct ngudbpstat * stats ; NG_MKRESPONSE ( resp , msg , sizeof ( * stats ) , M_NOWAIT ) ; if ( ! resp ) { error = ENOMEM ; break ; } stats = ( struct ngudbpstat * ) resp -> data ; mtx_lock ( & sc -> sc_mtx ) ; stats -> packets_in = sc -> sc_packets_in ; stats -> packets_out = sc -> sc_packets_out ; mtx_unlock ( & sc -> sc_mtx ) ; break ; } case NGM_UDBP_SET_FLAG : if ( msg -> header . arglen != sizeof ( uint32_t ) ) { error = EINVAL ; break ; } DPRINTF ( " \n " , * ( ( uint32_t * ) msg -> data ) ) ; break ; default : error = EINVAL ; break ; } break ; default : error = EINVAL ; break ; } NG_RESPOND_MSG ( error , node , item , resp ) ; NG_FREE_MSG ( msg ) ; return ( error ) ; }
Get a netgraph control message.
Get a netgraph control message .
/* Deal with message according to cookie and command */ /* unknown command */ /* unknown cookie type */ /* Take care of synchronous response, if any */