Debian Codegraph @

res/res_geolocation/wiki/AsteriskImplementation.md

raw
1 {section:border=false}
2 {column:width=70%}
3
4 h1. Introduction
5
6 The Geolocation capabilities are implemented in Asterisk with the res_geolocation and res_pjsip_geolocation modules and the geolocation.conf configuration file. There are also dialplan functions which allow you to manipulate location information as it's passed through the dialplan.
7
8 h1. Location Information Flow
9
10 Location information can be supplied to Asterisk from several sources during the call flow...
11 * Sent by a caller in a SIP INVITE message.
12 * Provided by a geolocation profile attached to the caller's endpoint.
13 * Provided by the dialplan via the Geolocation apps and functions.
14 * Provided by a geolocation profile attached to the callee's endpoint.
15
16 These sources aren't mutually exclusive and may, in fact, provide conflicting information or present the same information in multiple formats. Given that, there's no way for Asterisk to merge information nor is there a way for Asterisk to automatically determine which source should take precedence. However, you can use the geolocation profiles and the dialplan functions to tell Asterisk what to do with the location information received from the previous step in the call flow.
17
18 h1. Core Configuration
19 The bulk of the geolocation support is implemented in the res_geolocation module and configured in the geolocation.conf file. The file contains two main objects, Location and Profile.
20
21 h2. Common Behavior
22
23 h3. Sub-parameters
24 Some of the parameters in each object are actually lists of comma-separated name-value "sub-parameters". For example, the {{location_info}} parameter in the Location object contains a list of sub-parameters that are specific to the location type. For instance, a GML Circle might look like this:
25 {code}
26 location_info = shape=Circle, pos="39.12345 -105.98766", radius=100
27 {code}
28 Spaces around the equals signs and commas are ignored so you must double quote sub-parameter values with spaces or commas in them.
29
30 For readability, parameters that use sub-parameters can be split over more than one line. For example:
31 {code}
32 location_info = country=US,A1="New York"
33 location_info = HNO=1633,PRD=W,RD=46th
34 {code}
35 would be equivalent to:
36 {code}
37 location_info = country=US,A1="New York",HNO=1633,PRD=W,RD=46th
38 {code}
39
40 h3. Variable substitution
41 Some of the parameters can contain references to channel variables and dialplan functions. For example, you might have a URI location object that contains a reference to the {{EXTEN}} channel variable:
42 {code}
43 location_info = URI=http://some.example.com?key=${EXTEN}
44 {code}
45 When a call is processed that uses this location object, {{$\{EXTEN\}}} would be replaced with the channel's extension and would result in a URI such as {{http://some.example.com?key=1000}}. You'd set up your web server to return a location document based on the value of "key".
46
47 You can also use dialplan functions such as {{CURL}} and {{ODBC_SQL}} to supply values just as you would in extensions.conf.
48
49 h2. Configuration Objects
50 h3. Location
51 The Location object defines a discrete location or defines a template that can be used to define a discrete location on a per-call basis.
52
53 h4. Parameters
54
55 * *type*: Object type. Must be "location"
56 ** Required: yes
57 ** Uses channel variables: no
58 ** Sub-parameters: none
59 ** Default: none
60 ** Example:
61 {{type=location}}
62
63 * *format*: Must be one of "civicAddress", "GML" or "URI" to indicate how the location is expressed.
64 ** Required: yes
65 ** Uses channel variables: no
66 ** Sub-parameters: none
67 ** Default: none
68 ** Example:
69 {{format=civicAddress}}
70
71 * *method*: If provided, it MUST be one of "GPS", "A-GPS", "Manual", "DHCP", "Triangulation", "Cell", "802.11"
72 ** Required: no
73 ** Uses channel variables: no
74 ** Sub-parameters: none
75 ** Default: none
76 ** Example:
77 {{method=Manual}}
78
79 * *location_source*: If provided, it MUST be a fully qualified domain name. IP addresses are specifically not allowed. See [RFC8787|Geolocation Reference Information#rfc8787] for the exact definition of this parameter.
80 ** Required: no
81 ** Uses channel variables: no
82 ** Sub-parameters: none
83 ** Default: none
84 ** Example:
85 {{location_source=some.domain.net}}
86
87 * *location_info*: Sub-parameters that describe the location. Dependent on the format selected.
88 ** Required: yes
89 ** Uses channel variables: yes
90 ** Sub-parameters: yes
91 ** Default: none
92 ** Examples:
93 *** [URI] format: (see the [URI] page for more info)
94 {{location_info = URI=http://some.example.com}}
95 *** [civicAddress|Civic Address] format: ( See the [civicAddress|Civic Address] page for more info)
96 {{location_info = country=US, A1="New York", A3="New York", ...}}
97 *** [GML|Geography Markup Language] format: (See the [GML|Geography Markup Language] page for more info)
98 {{location_info = shape=Circle, pos="39.12345 -105.98766", radius=100}}
99
100 * *confidence*: This is a rarely used field in the specification that would indicate the confidence in the location specified. See [RFC7459|https://www.rfc-editor.org/rfc/rfc7459] for exact details.
101 ** Required: no
102 ** Uses channel variables: no
103 ** Sub-parameters: yes
104 *** *pdf*: One of: "unknown", "normal", "rectangular".
105 *** *value*: 0-100 percent indicating the confidence level.
106 ** Default: none
107 ** Example:
108 {{confidence = pdf=normal, confidence=95
109
110 h4. Example
111
112 {code}
113 [mylocation]
114 type = location
115 format = civicAddress
116 method = Manual
117 location_info = country=US, A1="New York", A3="New York",
118 location_info = HNO=1633, PRD=W, RD=46th, STS=Street, PC=10222
119 {code}
120
121
122 h3. Profile
123 The Profile object defines how a location is used and is referenced by channel drivers.
124
125 h4. Parameters
126
127 * *type*: Object type. Must be "profile"
128 ** Required: yes
129 ** Uses channel variables: no
130 ** Sub-parameters: none
131 ** Default: none
132 ** Example:
133 {{type=profile}}
134
135 * *location_reference*: Specifies the id of a Location object to use.
136 ** Required: no
137 ** Uses channel variables: no
138 ** Sub-parameters: none
139 ** Default: none
140 ** Example:
141 {{location_reference=mylocation}}
142
143 * *pidf_element*: For Civic Address and GML location formats, this parameter specifies the PIDF element that will carry the location description on outgoing SIP requests. Must be one of "tuple", "device" or "person".
144 ** Required: no
145 ** Uses channel variables: no
146 ** Sub-parameters: none
147 ** Default: device
148 ** Example:
149 {{pidf_element = tuple}}
150
151 * *allow_routing_use*: This value controls the value of the {{Geolocation-Routing}} header sent on SIP requests, Must be "yes" or "no". See [RFC6442|Geolocation Reference Information#rfc6442] for more information.
152 ** Required: no
153 ** Uses channel variables: no
154 ** Sub-parameters: none
155 ** Default: no
156 ** Example:
157 {{allow_routing_use = yes}}
158
159 * *profile_precedence*: Specifies which of the available profiles (configured or incoming) takes precedence. NOTE: On an incoming call leg/channel, the "incoming" profile is the one received by the channel driver from the calling party in the SIP INVITE and the "configured" profile is the one attached to the calling party's pjsip endpoint. On an outgoing call segment/channel, the "incoming" profile is the one received by the channel driver from the Asterisk core/dialplan and the "configured" profile one is the one attached to the called party's pjsip endpoint.
160 ** Valid values:
161 *** {{prefer_incoming}}: Use the incoming profile if it exists and has location information, otherwise use the configured profile if it has location information. If neither profile has location information, nothing is passed on.
162 *** {{prefer_config}}: Use the configured profile if it exists and has location information, otherwise use the incoming profile if it has location information. If neither profile has location information, nothing is passed on.
163 *** {{discard_incoming}}: Discard the incoming profile and use the configured profile if it has location information. If it doesn't, nothing is passed on.
164 *** {{discard_config}}: Discard the configured profile and use the incoming profile if it has location information. If it doesn't, nothing is passed on.
165 ** Required: no
166 ** Uses channel variables: no
167 ** Sub-parameters: none
168 ** Default: discard_incoming
169 ** Example:
170 {{profile_precedence = prefer_incoming}}
171
172 * *usage_rules*: For Civic Address and GML location formats, this parameter specifies the contents of the {{usage-rules}} PIDF-LO element. See [RFC4119|Geolocation Reference Information#rfc4119] for the exact definition of this parameter.
173 ** Required: no
174 ** Uses channel variables: yes
175 ** Sub-parameters: yes
176 *** *retransmission-allowed*: Must be "yes" or "no".
177 *** *retention-expires*: An ISO-format timestamp after which the recipient MUST discard and location information associated with this request. The default is 24 hours after the request was sent. You can use dialplan functions to create a timestamp yourself if needed.
178 ** Default: retransmission-allowed=no, retention-expires=<current time + 24 hours>
179 ** Example:
180 {{usage_rules = retransmission-allowed=yes,retention-expires="$\{STRFTIME($[$\{EPOCH\}+3600],UTC,%FT%TZ)\}"}}
181
182 * *suppress_empty_ca_elements*: For Civic Address outgoing PIDF-LO documents, don't output empty elements. This can be useful when you dynamically set values of elements in the dialplan that could evaluate to an empty string. For instance, if you set the street suffix STS element from a dialplan variable and it happens to be empty, the default behavior would be to send an empty {{<STS/>}} element. If this parameter is set to "yes" however, we'd just not print the element at all.
183 ** Required: no
184 ** Uses channel variables: no
185 ** Sub-parameters: no
186 ** Default: no
187 ** Example
188 {{suppress_empty_ca_elements = yes}}
189
190 * *location_info_refinement*: This parameter can be used to refine referenced location by adding these sub-parameters to the {{location_info}} parameter of the referenced location object. For example, you could have Civic Address referenced object describe a building, then have this profile refine it by adding floor, room, etc. Another profile could then also reference the same location object and refine it by adding a different floor, room, etc.
191 ** Required: no
192 ** Uses channel variables: yes
193 ** Sub-parameters: yes (any that can appear in a location's location_info parameter)
194 ** Default: none
195 ** Example:
196 Add a room to the civicAddress specified by location_reference.
197 {{location_reference = myCivicAddress = ROOM=23A4}}
198 {{location_info_refinement = ROOM=23A4}}
199
200 * *location_variables*: Any parameter than can use channel variables can also use the arbitrary variables defined in this parameter. For example {{location_variables = MYVAR1=something, MYVAR2="something else"}} would allow you to use {{$\{MYVAR1\}}} and {{$\{MYVAR2\}}} in any other parameter that can accept channel variables.
201 ** Required: no
202 ** Uses channel variables: yes
203 ** Sub-parameters: yes (one or more name=value pairs)
204 ** Default: none
205 ** Example:
206 {{location_variables = MYVAR1=something, MYVAR2="something else"}}
207
208 * *notes*: The specifications allow a free-form "note-well" element to be added to the location description. Any text entered here will be present on all outgoing Civic Address and GML requests.
209 ** Required: no
210 ** Uses channel variables: no
211 ** Sub-parameters: no
212 ** Default: none
213 ** Example:
214 {{notes = "anything you want"}}
215
216 h4. Additional Parameters
217 In addition to the profile-specific parameters defined above, any location-object parameters can be specified as well. This is a convenient shortcut if you have a 1<>1 relationship between profile and location.
218
219 h4. Built-in Profiles
220 In addition to the profiles you define in geolocation.conf, 4 built-in profiles are also available They're named after their profile_precedence setting:
221 * *<prefer_incoming>*
222 * *<prefer_config>*
223 * *<discard_incoming>*
224 * *<discard_config>*
225
226 The rest of the profile parameters are set to their defaults.
227
228 h1. chan_pjsip Configuration
229 Two new parameters have been added to pjsip endpoints:
230
231 h2. Parameters
232
233 * *geoloc_incoming_call_profile*: Should be set to the name of a geolocation profile to use for calls coming into Asterisk from this remote endpoint. If not set, no geolocation processing will occur and any location descriptions present on the incoming request will be silently dropped. Any of the 4 built-in profiles can be used.
234
235 * *geoloc_outgoing_call_profile*: Should be set to the name of a geolocation profile to use for calls Asterisk sends to this remote endpoint. If not set, no geolocation processing will occur and any location descriptions coming from the associated incoming channel or the dialplan will be silently dropped and not conveyed to the endpoint. Any of the 4 built-in profiles can be used.
236
237 Example:
238 {code}
239 [myendpoint]
240 type = endpoint
241 ...
242 geoloc_incoming_call_profile = <discard_incoming>
243 geoloc_outgoing_call_profile = myendpoint_profile
244 {code}
245
246 h1. Dialplan Function
247 A new dialplan function has been added to allow a dialplan author to manipulate geolocation information.
248
249 h2. GEOLOC_PROFILE
250 This function can get or set any of the fields in a specific profile. The available fields are those in _both_ the Location and Profile configuration objects. See the fuinction help for more information.
251
252 h1. Example Call Flows
253
254 h2. Simple Example 1
255 Alice and Bob work in the same building so in geolocation.conf, we can define a location that describes the building and profiles for Bob and Alice that add floor and room. We're assuming here that Bob's and Alice's phones don't send any location information themselves.
256 {code}
257 [building1]
258 type = location
259 format = civicAddress
260 location_info = country=US, A1="New York", A3="New York",
261 location_info = HNO=1633, PRD=W, RD=46th, STS=Street, PC=10222
262 method = Manual
263
264 [alice]
265 type = profile
266 location_reference = building1
267 location_refinement = FLR=4, ROOM=4B20
268
269 [bob]
270 type = profile
271 location_reference = building1
272 location_refinement = FLR=32, ROOM=32A6
273 {code}
274
275 In pjsip.conf, we can now associate those profiles to endpoints.
276 {code}
277 [bob]
278 type = endpoint
279 geoloc_incoming_call_profile = bob
280
281 [alice]
282 type = endpoint
283 geoloc_incoming_call_profile = alice
284 {code}
285 You'll notice that neither bob nor alice set {{geoloc_outgoing_call_profile}} because we never want to send location information _to_ them.
286
287 Now when Alice makes a call, Asterisk will construct an effective profile (including any defaults and variable substitutions) that looks like this...
288 {code}
289 format = civicAddress
290 location_info = country=US, A1="New York", A3="New York",
291 location_info = HNO=1633, RD=46th, STS=Street, PC=10222, FLR=4, ROOM=4B20
292 method = Manual
293 usage_rules = retransmission-allowed=no
294 usage_rules = retention-expires="${STRFTIME($[${EPOCH}+86400],UTC,%FT%TZ)}"
295 allow_routing = no
296 pidf_element = device
297 {code}
298
299 Bob's effective profile would be exactly the same except for {{FLR}} and {{ROOM}}
300
301 This effective profile will then be forwarded to the dialplan. The dialplan application can then use GEOLOC_PROFILE to make changes before the effective profile is forwarded to the outgoing channel. It can also use GeolocProfileDelete to just delete the effective profile and pass nothing.
302
303 {column}
304 {column:width=30%}
305 Table of Contents:
306 {toc}
307
308
309 Geolocation:
310 {pagetree:root=Geolocation|expandCollapseAll=true}
311 {column}
312 {section}