FreeBSD/sys/mips/nlm/dev/sec/nlmrsa.c
/*
 * Allocate a new 'session' and return an encoded session id.  'sidp'
 * contains our registration id, and should contain an encoded session
 * id on successful allocation.
 */
Allocate a new 'session' and return an encoded session id.  'sidp'
contains our registration id, and should contain an encoded session
id on successful allocation.
Allocate a new ' session ' and return an encoded session id . ' sidp ' contains our registration id and should contain an encoded session id on successful allocation .
static int
xlp_rsa_newsession(device_t dev, u_int32_t *sidp, struct cryptoini *cri)
{
	struct xlp_rsa_softc *sc = device_get_softc(dev);
	struct xlp_rsa_session *ses = NULL;
	int sesn;
	if (sidp == NULL || cri == NULL || sc == NULL)
		return (EINVAL);
	if (sc->sc_sessions == NULL) {
		ses = sc->sc_sessions = malloc(sizeof(struct xlp_rsa_session),
		    M_DEVBUF, M_NOWAIT);
		if (ses == NULL)
			return (ENOMEM);
		sesn = 0;
		sc->sc_nsessions = 1;
	} else {
		for (sesn = 0; sesn < sc->sc_nsessions; sesn++) {
			if (!sc->sc_sessions[sesn].hs_used) {
				ses = &sc->sc_sessions[sesn];
				break;
			}
		}
		if (ses == NULL) {
			sesn = sc->sc_nsessions;
			ses = malloc((sesn + 1) * sizeof(*ses),
			    M_DEVBUF, M_NOWAIT);
			if (ses == NULL)
				return (ENOMEM);
			bcopy(sc->sc_sessions, ses, sesn * sizeof(*ses));
			bzero(sc->sc_sessions, sesn * sizeof(*ses));
			free(sc->sc_sessions, M_DEVBUF);
			sc->sc_sessions = ses;
			ses = &sc->sc_sessions[sesn];
			sc->sc_nsessions++;
		}
	}
	bzero(ses, sizeof(*ses));
	ses->sessionid = sesn;
	ses->hs_used = 1;
	*sidp = XLP_RSA_SID(device_get_unit(sc->sc_dev), sesn);
	return (0);
}
static int xlp_rsa_newsession ( device_t dev , u_int32_t * sidp , struct cryptoini * cri ) { struct xlp_rsa_softc * sc = device_get_softc ( dev ) ; struct xlp_rsa_session * ses = NULL ; int sesn ; if ( sidp == NULL || cri == NULL || sc == NULL ) return ( EINVAL ) ; if ( sc -> sc_sessions == NULL ) { ses = sc -> sc_sessions = malloc ( sizeof ( struct xlp_rsa_session ) , M_DEVBUF , M_NOWAIT ) ; if ( ses == NULL ) return ( ENOMEM ) ; sesn = 0 ; sc -> sc_nsessions = 1 ; } else { for ( sesn = 0 ; sesn < sc -> sc_nsessions ; sesn ++ ) { if ( ! sc -> sc_sessions [ sesn ] . hs_used ) { ses = & sc -> sc_sessions [ sesn ] ; break ; } } if ( ses == NULL ) { sesn = sc -> sc_nsessions ; ses = malloc ( ( sesn + 1 ) * sizeof ( * ses ) , M_DEVBUF , M_NOWAIT ) ; if ( ses == NULL ) return ( ENOMEM ) ; bcopy ( sc -> sc_sessions , ses , sesn * sizeof ( * ses ) ) ; bzero ( sc -> sc_sessions , sesn * sizeof ( * ses ) ) ; free ( sc -> sc_sessions , M_DEVBUF ) ; sc -> sc_sessions = ses ; ses = & sc -> sc_sessions [ sesn ] ; sc -> sc_nsessions ++ ; } } bzero ( ses , sizeof ( * ses ) ) ; ses -> sessionid = sesn ; ses -> hs_used = 1 ; * sidp = XLP_RSA_SID ( device_get_unit ( sc -> sc_dev ) , sesn ) ; return ( 0 ) ; }
Allocate a new 'session' and return an encoded session id.
Allocate a new ' session ' and return an encoded session id .