MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_h4_open

Function ng_h4_open

freebsd/netgraph/bluetooth/drivers/h4/ng_h4.c:152–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150 */
151
152static int
153ng_h4_open(struct cdev *dev, struct tty *tp)
154{
155 struct thread *td = curthread;
156 char name[NG_NODESIZ];
157 ng_h4_info_p sc = NULL;
158 int error;
159
160 /* Super-user only */
161 error = priv_check(td, PRIV_NETGRAPH_TTY); /* XXX */
162 if (error != 0)
163 return (error);
164
165 /* Initialize private struct */
166 sc = malloc(sizeof(*sc), M_NETGRAPH_H4, M_NOWAIT|M_ZERO);
167 if (sc == NULL)
168 return (ENOMEM);
169
170 sc->tp = tp;
171 sc->debug = NG_H4_WARN_LEVEL;
172
173 sc->state = NG_H4_W4_PKT_IND;
174 sc->want = 1;
175 sc->got = 0;
176
177 mtx_init(&sc->outq.ifq_mtx, "ng_h4 node+queue", NULL, MTX_DEF);
178 IFQ_SET_MAXLEN(&sc->outq, NG_H4_DEFAULTQLEN);
179 ng_callout_init(&sc->timo);
180
181 NG_H4_LOCK(sc);
182
183 /* Setup netgraph node */
184 error = ng_make_node_common(&typestruct, &sc->node);
185 if (error != 0) {
186 NG_H4_UNLOCK(sc);
187
188 printf("%s: Unable to create new node!\n", __func__);
189
190 mtx_destroy(&sc->outq.ifq_mtx);
191 bzero(sc, sizeof(*sc));
192 free(sc, M_NETGRAPH_H4);
193
194 return (error);
195 }
196
197 /* Assign node its name */
198 snprintf(name, sizeof(name), "%s%d", typestruct.name, ng_h4_node ++);
199
200 error = ng_name_node(sc->node, name);
201 if (error != 0) {
202 NG_H4_UNLOCK(sc);
203
204 printf("%s: %s - node name exists?\n", __func__, name);
205
206 NG_NODE_UNREF(sc->node);
207 mtx_destroy(&sc->outq.ifq_mtx);
208 bzero(sc, sizeof(*sc));
209 free(sc, M_NETGRAPH_H4);

Callers

nothing calls this directly

Calls 9

mallocFunction · 0.85
mtx_initFunction · 0.85
bzeroFunction · 0.85
snprintfFunction · 0.85
priv_checkFunction · 0.50
ng_make_node_commonFunction · 0.50
printfFunction · 0.50
freeFunction · 0.50
ng_name_nodeFunction · 0.50

Tested by

no test coverage detected