summaryrefslogtreecommitdiffstats
path: root/example/pp-location-update.c
blob: 099fbc07f51b6d56cc1e5eff1005b56408e57d88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * DECT PP location update example
 *
 * Copyright (c) 2010 Patrick McHardy <kaber@trash.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <stdio.h>

#include <dect/libdect.h>
#include <dect/auth.h>
#include "common.h"

static void mm_locate_cfm(struct dect_handle *dh, struct dect_mm_endpoint *mme,
			  bool accept, struct dect_mm_locate_param *param)
{
	struct dect_mm_identity_assign_param reply = {};

	if (param->portable_identity)
		dect_mm_identity_assign_res(dh, mme, true, &reply);

	dect_event_loop_stop();
}

static int mm_locate_req(struct dect_handle *dh, struct dect_mm_endpoint *mme)
{
	struct dect_ie_portable_identity portable_identity;
	struct dect_ie_location_area location_area;
	struct dect_ie_terminal_capability terminal_capability;
	struct dect_mm_locate_param param = {
		.portable_identity	= &portable_identity,
		.location_area		= &location_area,
		.terminal_capability	= &terminal_capability,
	};

	portable_identity.type	= DECT_PORTABLE_ID_TYPE_IPUI;
	portable_identity.ipui	= ipui;

	location_area.type	= DECT_LOCATION_AREA_LEVEL;
	location_area.level	= 36;

	dect_pp_init_terminal_capability(&terminal_capability);

	return dect_mm_locate_req(dh, mme, &param);
}

static struct dect_mm_ops mm_ops = {
	.mm_locate_cfm		= mm_locate_cfm,
};

static struct dect_ops ops = {
	.mm_ops			= &mm_ops,
};

int main(int argc, char **argv)
{
	const struct dect_fp_capabilities *fpc;
	struct dect_mm_endpoint *mme;

	dect_pp_common_options(argc, argv);
	dect_pp_common_init(&ops, cluster, &ipui);

	fpc = dect_llme_fp_capabilities(dh);
	if (!(fpc->hlc & DECT_HLC_LOCATION_REGISTRATION)) {
		fprintf(stderr, "FP does not support location registration\n");
		goto out;
	}

	mme = dect_mm_endpoint_alloc(dh, &ipui);
	if (mme == NULL)
		pexit("dect_mm_endpoint_alloc");

	mm_locate_req(dh, mme);
	dect_event_loop();
out:
	dect_common_cleanup(dh);
	return 0;
}