mirror of
				https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
				synced 2025-11-04 05:53:26 +00:00 
			
		
		
		
	Compare commits
	
		
			465 Commits
		
	
	
		
			laforge/si
			...
			on-waves/0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					51a4bcc96a | ||
| 
						 | 
					d6238120dd | ||
| 
						 | 
					7407aec921 | ||
| 
						 | 
					e575ce69ce | ||
| 
						 | 
					c1ca0ff091 | ||
| 
						 | 
					661e68b78f | ||
| 
						 | 
					376e146cfb | ||
| 
						 | 
					eb3ab2f85b | ||
| 
						 | 
					ebc38e4f26 | ||
| 
						 | 
					e2ab44a439 | ||
| 
						 | 
					8b3cced773 | ||
| 
						 | 
					3d1b0770f4 | ||
| 
						 | 
					99743fb7ec | ||
| 
						 | 
					a2a42a7561 | ||
| 
						 | 
					ebd57da87d | ||
| 
						 | 
					b0ee082bb0 | ||
| 
						 | 
					81f6a4c0bf | ||
| 
						 | 
					3978de52c1 | ||
| 
						 | 
					7faf692cb7 | ||
| 
						 | 
					0cf25d5154 | ||
| 
						 | 
					08db178271 | ||
| 
						 | 
					936d8c1b64 | ||
| 
						 | 
					3170305e56 | ||
| 
						 | 
					0f3490dd03 | ||
| 
						 | 
					61e5e7bd8b | ||
| 
						 | 
					f7b06fbe0c | ||
| 
						 | 
					45403b1804 | ||
| 
						 | 
					6782cea4bf | ||
| 
						 | 
					ec7ecab66f | ||
| 
						 | 
					d1287e379b | ||
| 
						 | 
					3fb44f3e61 | ||
| 
						 | 
					d48bfe0e93 | ||
| 
						 | 
					41cdaf520d | ||
| 
						 | 
					f94418a129 | ||
| 
						 | 
					88b299ca24 | ||
| 
						 | 
					58a2758e78 | ||
| 
						 | 
					be3fdc2c6e | ||
| 
						 | 
					6a8d765334 | ||
| 
						 | 
					adebbfdfa7 | ||
| 
						 | 
					afccfb9380 | ||
| 
						 | 
					0f7a8258f0 | ||
| 
						 | 
					2aa7f10939 | ||
| 
						 | 
					37ba5b3e35 | ||
| 
						 | 
					9f63d2b4ad | ||
| 
						 | 
					d21b5de8c0 | ||
| 
						 | 
					12b63716e2 | ||
| 
						 | 
					184961ea3e | ||
| 
						 | 
					a9ec86029f | ||
| 
						 | 
					d1b19f3308 | ||
| 
						 | 
					33f531fd12 | ||
| 
						 | 
					b051b3b161 | ||
| 
						 | 
					479a3aa707 | ||
| 
						 | 
					fd2a877e25 | ||
| 
						 | 
					53f797305f | ||
| 
						 | 
					691b40e834 | ||
| 
						 | 
					e511d54dd0 | ||
| 
						 | 
					6edf7b9a51 | ||
| 
						 | 
					e4045679a8 | ||
| 
						 | 
					52ae9a461b | ||
| 
						 | 
					5bd9493257 | ||
| 
						 | 
					c92fd5d9d3 | ||
| 
						 | 
					01cf14d679 | ||
| 
						 | 
					840447e2bf | ||
| 
						 | 
					3f7586d571 | ||
| 
						 | 
					b74a9f13e5 | ||
| 
						 | 
					bbc2c6e765 | ||
| 
						 | 
					7e3724ad18 | ||
| 
						 | 
					569dccf947 | ||
| 
						 | 
					89a378e9aa | ||
| 
						 | 
					4a78c7b250 | ||
| 
						 | 
					c71013091a | ||
| 
						 | 
					4b1cde10fe | ||
| 
						 | 
					0f5a2345d1 | ||
| 
						 | 
					ae81ff95ea | ||
| 
						 | 
					e5981edf6a | ||
| 
						 | 
					93cc16ae4f | ||
| 
						 | 
					119a1976f5 | ||
| 
						 | 
					c53c2ab524 | ||
| 
						 | 
					32423500f6 | ||
| 
						 | 
					c3a6a1dbe5 | ||
| 
						 | 
					f4f090ee36 | ||
| 
						 | 
					2a554bfcc4 | ||
| 
						 | 
					a12dea66ca | ||
| 
						 | 
					ec59bb04df | ||
| 
						 | 
					4417f7f477 | ||
| 
						 | 
					39563af27c | ||
| 
						 | 
					242faaafd1 | ||
| 
						 | 
					f77c0cd428 | ||
| 
						 | 
					4103a3e5b9 | ||
| 
						 | 
					4aca7f621f | ||
| 
						 | 
					507d536ce8 | ||
| 
						 | 
					cb618c7980 | ||
| 
						 | 
					3c0702d3c5 | ||
| 
						 | 
					caf24567d1 | ||
| 
						 | 
					1d34c6ac5a | ||
| 
						 | 
					1506f8e465 | ||
| 
						 | 
					f044c585e2 | ||
| 
						 | 
					6d17dd1314 | ||
| 
						 | 
					7cb6867ea3 | ||
| 
						 | 
					d8138c43a1 | ||
| 
						 | 
					46d9b94477 | ||
| 
						 | 
					4f705b9f99 | ||
| 
						 | 
					c592e697ce | ||
| 
						 | 
					ebb6b99c63 | ||
| 
						 | 
					e08253a3f7 | ||
| 
						 | 
					5e86095364 | ||
| 
						 | 
					a7c144888d | ||
| 
						 | 
					7897c4446b | ||
| 
						 | 
					ff9e09b2bc | ||
| 
						 | 
					ecf5cc294d | ||
| 
						 | 
					82126763a7 | ||
| 
						 | 
					a380c89a9c | ||
| 
						 | 
					bedaf5da64 | ||
| 
						 | 
					2b08aa35a6 | ||
| 
						 | 
					c24632930a | ||
| 
						 | 
					f140348eff | ||
| 
						 | 
					b5de1b0781 | ||
| 
						 | 
					b022cc3b8e | ||
| 
						 | 
					e8396c9663 | ||
| 
						 | 
					941839b300 | ||
| 
						 | 
					23a0e46f11 | ||
| 
						 | 
					cb8fd6e99e | ||
| 
						 | 
					e66bea8ad7 | ||
| 
						 | 
					e8a9f471ef | ||
| 
						 | 
					c2d66bdf5a | ||
| 
						 | 
					80b584bbe7 | ||
| 
						 | 
					15c21e8eec | ||
| 
						 | 
					c0a1fff064 | ||
| 
						 | 
					77fa4d2386 | ||
| 
						 | 
					9be8752541 | ||
| 
						 | 
					2b57b3cea4 | ||
| 
						 | 
					00c531709a | ||
| 
						 | 
					a094108f84 | ||
| 
						 | 
					61e73eec3f | ||
| 
						 | 
					1aa2798919 | ||
| 
						 | 
					b829eac9bc | ||
| 
						 | 
					7b1719327d | ||
| 
						 | 
					493645eda9 | ||
| 
						 | 
					8614cd0be7 | ||
| 
						 | 
					19bd74d093 | ||
| 
						 | 
					4821b5a847 | ||
| 
						 | 
					84df56d577 | ||
| 
						 | 
					4e23d5f87f | ||
| 
						 | 
					4346424987 | ||
| 
						 | 
					520656e004 | ||
| 
						 | 
					9dac231fe4 | ||
| 
						 | 
					2bb518a3bd | ||
| 
						 | 
					476940f747 | ||
| 
						 | 
					8deab8cdee | ||
| 
						 | 
					a54f9e81c8 | ||
| 
						 | 
					ed4390747f | ||
| 
						 | 
					242d098d32 | ||
| 
						 | 
					f795164f04 | ||
| 
						 | 
					b6c6d43daa | ||
| 
						 | 
					82df124c8e | ||
| 
						 | 
					189587f428 | ||
| 
						 | 
					45ab581f37 | ||
| 
						 | 
					f48776ea6a | ||
| 
						 | 
					7fc17cff64 | ||
| 
						 | 
					a5a7075fe5 | ||
| 
						 | 
					2b4e366083 | ||
| 
						 | 
					bf1eb64b02 | ||
| 
						 | 
					f0fbae94ea | ||
| 
						 | 
					8fe4df503c | ||
| 
						 | 
					8da7103070 | ||
| 
						 | 
					f73f6fad8c | ||
| 
						 | 
					25cb84be12 | ||
| 
						 | 
					d9ae25c1bf | ||
| 
						 | 
					5c011366c9 | ||
| 
						 | 
					79e2d4230d | ||
| 
						 | 
					8ecd029b12 | ||
| 
						 | 
					3c0508e94a | ||
| 
						 | 
					f535aad612 | ||
| 
						 | 
					d0ac8866f1 | ||
| 
						 | 
					73f9a65f12 | ||
| 
						 | 
					b2c55c49a8 | ||
| 
						 | 
					8dc241959c | ||
| 
						 | 
					f99709430a | ||
| 
						 | 
					b9bc45b1b0 | ||
| 
						 | 
					65d10c1320 | ||
| 
						 | 
					414ba77f75 | ||
| 
						 | 
					59f2470650 | ||
| 
						 | 
					339dfdb624 | ||
| 
						 | 
					9e2e2e04d1 | ||
| 
						 | 
					2ab6db0153 | ||
| 
						 | 
					6cb97bdebe | ||
| 
						 | 
					8c3694a282 | ||
| 
						 | 
					191d23a889 | ||
| 
						 | 
					a5963097ac | ||
| 
						 | 
					221fb37518 | ||
| 
						 | 
					4ec8a390cc | ||
| 
						 | 
					cf3f1c8b3d | ||
| 
						 | 
					984f3b8047 | ||
| 
						 | 
					ec1f15d513 | ||
| 
						 | 
					b76cd5ed7e | ||
| 
						 | 
					1592550d98 | ||
| 
						 | 
					5cdf42b1a4 | ||
| 
						 | 
					3a6b1a41fb | ||
| 
						 | 
					1b5b3bbfdb | ||
| 
						 | 
					3a67035411 | ||
| 
						 | 
					cb1937a4c5 | ||
| 
						 | 
					3cfd5d6a02 | ||
| 
						 | 
					6cc4dbfd46 | ||
| 
						 | 
					9960d59fff | ||
| 
						 | 
					161bd6d253 | ||
| 
						 | 
					add3472e9f | ||
| 
						 | 
					33b0bee457 | ||
| 
						 | 
					6949db1bd8 | ||
| 
						 | 
					8ae0080e21 | ||
| 
						 | 
					546c296c4a | ||
| 
						 | 
					86f42eb6a5 | ||
| 
						 | 
					494c086dca | ||
| 
						 | 
					6b18c8f3b6 | ||
| 
						 | 
					87f6d26c2e | ||
| 
						 | 
					fab2ff34c4 | ||
| 
						 | 
					06d353e02e | ||
| 
						 | 
					dfe47549c6 | ||
| 
						 | 
					c70e8c2103 | ||
| 
						 | 
					b462a03c35 | ||
| 
						 | 
					6e0ec5b6fa | ||
| 
						 | 
					6768387f16 | ||
| 
						 | 
					5ef1234dd3 | ||
| 
						 | 
					581e58d166 | ||
| 
						 | 
					e308bb466a | ||
| 
						 | 
					e4be5394ef | ||
| 
						 | 
					81e1edd3e6 | ||
| 
						 | 
					cfd1c28604 | ||
| 
						 | 
					3ba8963a1d | ||
| 
						 | 
					238d156481 | ||
| 
						 | 
					516c4f073a | ||
| 
						 | 
					fa22aa6bbd | ||
| 
						 | 
					4072ceed32 | ||
| 
						 | 
					cf6bf63a0d | ||
| 
						 | 
					88b614110f | ||
| 
						 | 
					d9b825a5f5 | ||
| 
						 | 
					b91e5f1da4 | ||
| 
						 | 
					07bb509434 | ||
| 
						 | 
					08db6ca509 | ||
| 
						 | 
					6446ded81c | ||
| 
						 | 
					7b8f6064d6 | ||
| 
						 | 
					c6a1fe773d | ||
| 
						 | 
					729d468fdf | ||
| 
						 | 
					b37ce4c5a4 | ||
| 
						 | 
					5cd62c0ba5 | ||
| 
						 | 
					1e1acafafd | ||
| 
						 | 
					fb83b7a86d | ||
| 
						 | 
					ef0b641f63 | ||
| 
						 | 
					27e0bfd3c7 | ||
| 
						 | 
					bbfff6ec39 | ||
| 
						 | 
					dc0914df09 | ||
| 
						 | 
					0db691dcf6 | ||
| 
						 | 
					bb45b73b20 | ||
| 
						 | 
					5f5c1b6bcb | ||
| 
						 | 
					e51cf4f946 | ||
| 
						 | 
					749ba7f5ad | ||
| 
						 | 
					860c8955c3 | ||
| 
						 | 
					c33701c4e5 | ||
| 
						 | 
					44d92b4728 | ||
| 
						 | 
					8aaec620da | ||
| 
						 | 
					a5a4014d67 | ||
| 
						 | 
					9d519189ae | ||
| 
						 | 
					f0fc618782 | ||
| 
						 | 
					c57575bea8 | ||
| 
						 | 
					8cdfe9fc37 | ||
| 
						 | 
					0959f8cbe6 | ||
| 
						 | 
					f21028985e | ||
| 
						 | 
					483b768ab2 | ||
| 
						 | 
					82cb311c4f | ||
| 
						 | 
					2980442e33 | ||
| 
						 | 
					fa7afb31e9 | ||
| 
						 | 
					7513b3a1c2 | ||
| 
						 | 
					135d99b36e | ||
| 
						 | 
					5aaf7c164c | ||
| 
						 | 
					790db1e01b | ||
| 
						 | 
					81a8975662 | ||
| 
						 | 
					fd876b7488 | ||
| 
						 | 
					2ffe7aa340 | ||
| 
						 | 
					538ea6d5c6 | ||
| 
						 | 
					e14ec0dab4 | ||
| 
						 | 
					8252b9b947 | ||
| 
						 | 
					9fb88021dd | ||
| 
						 | 
					b031d6ecae | ||
| 
						 | 
					fcfdde5390 | ||
| 
						 | 
					571ba8e4da | ||
| 
						 | 
					bed6234e26 | ||
| 
						 | 
					9d24578812 | ||
| 
						 | 
					a087c4e75d | ||
| 
						 | 
					6b64b26d8b | ||
| 
						 | 
					22252a98e3 | ||
| 
						 | 
					957bc93244 | ||
| 
						 | 
					18bbe2e8a0 | ||
| 
						 | 
					1b17913cbc | ||
| 
						 | 
					ce2a36840d | ||
| 
						 | 
					0e09feccb0 | ||
| 
						 | 
					40a1de699a | ||
| 
						 | 
					d906a366c8 | ||
| 
						 | 
					d44d4c8c8b | ||
| 
						 | 
					af0e1d7a85 | ||
| 
						 | 
					d21b4d7f98 | ||
| 
						 | 
					3bdaa69fb2 | ||
| 
						 | 
					5c0132882a | ||
| 
						 | 
					ed443e949e | ||
| 
						 | 
					1df69f3c64 | ||
| 
						 | 
					d7cafafeee | ||
| 
						 | 
					e09348d366 | ||
| 
						 | 
					5f1b7c14f5 | ||
| 
						 | 
					5b3e9198f0 | ||
| 
						 | 
					f0b21dfd25 | ||
| 
						 | 
					e165d1aaa4 | ||
| 
						 | 
					649496eb57 | ||
| 
						 | 
					135a45c833 | ||
| 
						 | 
					1a3d9dbabf | ||
| 
						 | 
					a91d15df7e | ||
| 
						 | 
					3368e2a3d1 | ||
| 
						 | 
					929d788e21 | ||
| 
						 | 
					6958065f85 | ||
| 
						 | 
					097c82b2bc | ||
| 
						 | 
					abaeb3f55f | ||
| 
						 | 
					f42e29c79c | ||
| 
						 | 
					3177580cc1 | ||
| 
						 | 
					cbe77e1657 | ||
| 
						 | 
					3cedc4738f | ||
| 
						 | 
					0834fd9b85 | ||
| 
						 | 
					7b65c986eb | ||
| 
						 | 
					17d751531e | ||
| 
						 | 
					facb5cdfc2 | ||
| 
						 | 
					aebea482f5 | ||
| 
						 | 
					12f20d369c | ||
| 
						 | 
					2008d3f54c | ||
| 
						 | 
					a26ebe40f5 | ||
| 
						 | 
					a52f1cacb3 | ||
| 
						 | 
					f5e71415a2 | ||
| 
						 | 
					82a8d6e393 | ||
| 
						 | 
					1226c93937 | ||
| 
						 | 
					b9c520f9b3 | ||
| 
						 | 
					8a7ca57d3e | ||
| 
						 | 
					29f9f9fc79 | ||
| 
						 | 
					d512e454b3 | ||
| 
						 | 
					22481bf76d | ||
| 
						 | 
					b973955295 | ||
| 
						 | 
					9d51a36528 | ||
| 
						 | 
					ba3bbe55c1 | ||
| 
						 | 
					0619478073 | ||
| 
						 | 
					f8f184edab | ||
| 
						 | 
					d838951302 | ||
| 
						 | 
					f8e1b45a78 | ||
| 
						 | 
					dd2c9fdbcf | ||
| 
						 | 
					9991421cfb | ||
| 
						 | 
					e30f0e1c75 | ||
| 
						 | 
					18598ff66d | ||
| 
						 | 
					8882c9e3a8 | ||
| 
						 | 
					fdc64f6806 | ||
| 
						 | 
					16b331d14f | ||
| 
						 | 
					ab46372e2a | ||
| 
						 | 
					be807e4250 | ||
| 
						 | 
					71ddbf5c4f | ||
| 
						 | 
					63bb29fac0 | ||
| 
						 | 
					04b4f915a7 | ||
| 
						 | 
					4d95ab2231 | ||
| 
						 | 
					17944f7285 | ||
| 
						 | 
					d2964b6cd1 | ||
| 
						 | 
					1ce5d7c8b7 | ||
| 
						 | 
					846457b10a | ||
| 
						 | 
					e7b9771c4d | ||
| 
						 | 
					d709900efa | ||
| 
						 | 
					55b4f5cc2e | ||
| 
						 | 
					1ac5ac75a9 | ||
| 
						 | 
					5cf38ed1ab | ||
| 
						 | 
					35d1531089 | ||
| 
						 | 
					47e3777caa | ||
| 
						 | 
					710f3c615c | ||
| 
						 | 
					3111560e8a | ||
| 
						 | 
					7396afbba4 | ||
| 
						 | 
					52a72e217e | ||
| 
						 | 
					ff0a562f9a | ||
| 
						 | 
					556008d724 | ||
| 
						 | 
					0094f84f30 | ||
| 
						 | 
					86069143ff | ||
| 
						 | 
					44f0be88a3 | ||
| 
						 | 
					5d88b372d7 | ||
| 
						 | 
					71c7bf5907 | ||
| 
						 | 
					869033148c | ||
| 
						 | 
					bc0f7c0988 | ||
| 
						 | 
					7d06063cfb | ||
| 
						 | 
					4e42b637fd | ||
| 
						 | 
					f44de9942b | ||
| 
						 | 
					3a110ae60b | ||
| 
						 | 
					bb84adc465 | ||
| 
						 | 
					8d123ea3c0 | ||
| 
						 | 
					88ca894df7 | ||
| 
						 | 
					42b0d6b494 | ||
| 
						 | 
					82d8b0457b | ||
| 
						 | 
					433d6ee1a2 | ||
| 
						 | 
					203a6eddf8 | ||
| 
						 | 
					56ef6249e3 | ||
| 
						 | 
					b2a96b1be7 | ||
| 
						 | 
					d4c29c1574 | ||
| 
						 | 
					3d947e6d67 | ||
| 
						 | 
					b62c9a19cf | ||
| 
						 | 
					ff5957568f | ||
| 
						 | 
					7d2e1ca4be | ||
| 
						 | 
					7ce2e0c8b0 | ||
| 
						 | 
					78d442420b | ||
| 
						 | 
					8cd2709ebf | ||
| 
						 | 
					41a1780102 | ||
| 
						 | 
					2f84715984 | ||
| 
						 | 
					7253154fc5 | ||
| 
						 | 
					6c1c76683f | ||
| 
						 | 
					a92fe9a4ca | ||
| 
						 | 
					e83a3f584e | ||
| 
						 | 
					118ddebc36 | ||
| 
						 | 
					bb53004d47 | ||
| 
						 | 
					6af20842cb | ||
| 
						 | 
					cc41cb07e7 | ||
| 
						 | 
					d6fb23523a | ||
| 
						 | 
					2aa0b45cc0 | ||
| 
						 | 
					619df61ad2 | ||
| 
						 | 
					893ea65f38 | ||
| 
						 | 
					64b811f113 | ||
| 
						 | 
					91fc9bf862 | ||
| 
						 | 
					111a58dd37 | ||
| 
						 | 
					d1a2563a74 | ||
| 
						 | 
					7d3ef919ce | ||
| 
						 | 
					cba98d87d6 | ||
| 
						 | 
					5c18ad0829 | ||
| 
						 | 
					0d9ed87d5c | ||
| 
						 | 
					ec7be0c969 | ||
| 
						 | 
					9be3347601 | ||
| 
						 | 
					3eef7b7d81 | ||
| 
						 | 
					9de4a6daa9 | ||
| 
						 | 
					851ace9f33 | ||
| 
						 | 
					d1dd069b48 | ||
| 
						 | 
					401db32ca2 | ||
| 
						 | 
					17e03d21d2 | ||
| 
						 | 
					26a9bff201 | ||
| 
						 | 
					80fb260a60 | ||
| 
						 | 
					55a0716da7 | ||
| 
						 | 
					c88fb75616 | ||
| 
						 | 
					d55a4dc326 | ||
| 
						 | 
					a4e6f2e6e1 | ||
| 
						 | 
					7f71d99cc3 | ||
| 
						 | 
					b92167cf80 | ||
| 
						 | 
					4b6a6dbe7e | ||
| 
						 | 
					763e8c7766 | ||
| 
						 | 
					823ff16088 | ||
| 
						 | 
					6f93c6a1e0 | ||
| 
						 | 
					f97e48b0de | ||
| 
						 | 
					761600b0fd | ||
| 
						 | 
					8549462bc6 | ||
| 
						 | 
					436e5c6308 | ||
| 
						 | 
					f8b9d844c1 | ||
| 
						 | 
					58ec07d580 | ||
| 
						 | 
					71465c21f4 | ||
| 
						 | 
					16d0a833f8 | ||
| 
						 | 
					ea72b62cac | ||
| 
						 | 
					49a84ec6e9 | ||
| 
						 | 
					42c636b6c8 | ||
| 
						 | 
					a0a55f555e | ||
| 
						 | 
					23ed00e410 | ||
| 
						 | 
					3fe910b9f1 | ||
| 
						 | 
					097bdeb77d | ||
| 
						 | 
					1b85de02e0 | ||
| 
						 | 
					2281d1835f | ||
| 
						 | 
					fb4433a129 | ||
| 
						 | 
					d954dcf9e1 | 
@@ -1,9 +1,6 @@
 | 
				
			|||||||
dnl Process this file with autoconf to produce a configure script
 | 
					dnl Process this file with autoconf to produce a configure script
 | 
				
			||||||
AC_INIT([openbsc],
 | 
					AC_INIT(openbsc, 0.3.99.9onwaves)
 | 
				
			||||||
	m4_esyscmd([./git-version-gen .tarball-version]),
 | 
					AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
 | 
				
			||||||
	[openbsc-devel@lists.openbsc.org])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
AM_INIT_AUTOMAKE([dist-bzip2])
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
dnl kernel style compile messages
 | 
					dnl kernel style compile messages
 | 
				
			||||||
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 | 
					m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 | 
				
			||||||
@@ -54,4 +51,5 @@ AC_OUTPUT(
 | 
				
			|||||||
    tests/db/Makefile
 | 
					    tests/db/Makefile
 | 
				
			||||||
    tests/channel/Makefile
 | 
					    tests/channel/Makefile
 | 
				
			||||||
    tests/sccp/Makefile
 | 
					    tests/sccp/Makefile
 | 
				
			||||||
 | 
					    tests/bsc-nat/Makefile
 | 
				
			||||||
    Makefile)
 | 
					    Makefile)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								openbsc/contrib/README
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								openbsc/contrib/README
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					This contains a set of scripts used for the development of the
 | 
				
			||||||
 | 
					MSC functionality.
 | 
				
			||||||
							
								
								
									
										30
									
								
								openbsc/contrib/send_handshake.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										30
									
								
								openbsc/contrib/send_handshake.py
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# packages
 | 
				
			||||||
 | 
					ACK ="\x00\x01\xfe\x06"
 | 
				
			||||||
 | 
					RESET_ACK = "\x00\x13\xfd\x09\x00\x03\x07\x0b\x04\x43\x01\x00\xfe\x04\x43\x5c\x00\xfe\x03\x00\x01\x31"
 | 
				
			||||||
 | 
					PAGE = "\x00\x20\xfd\x09\x00\x03\x07\x0b\x04\x43\x01\x00\xfe\x04\x43\x5c\x00\xfe\x10\x00\x0e\x52\x08\x08\x29\x42\x08\x05\x03\x12\x23\x42\x1a\x01\x06"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# simple handshake...
 | 
				
			||||||
 | 
					sys.stdout.write(ACK)
 | 
				
			||||||
 | 
					sys.stdout.flush()
 | 
				
			||||||
 | 
					sys.stdin.read(4)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# wait for some data and send reset ack
 | 
				
			||||||
 | 
					sys.stdin.read(21)
 | 
				
			||||||
 | 
					sys.stdout.write(RESET_ACK)
 | 
				
			||||||
 | 
					sys.stdout.flush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sys.stdout.write(RESET_ACK)
 | 
				
			||||||
 | 
					sys.stdout.flush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# page a subscriber
 | 
				
			||||||
 | 
					sys.stdout.write(PAGE)
 | 
				
			||||||
 | 
					sys.stdout.flush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					while True:
 | 
				
			||||||
 | 
					    sys.stdin.read(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -6,7 +6,7 @@ noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \
 | 
				
			|||||||
		 bsc_rll.h mncc.h transaction.h ussd.h gsm_04_80.h \
 | 
							 bsc_rll.h mncc.h transaction.h ussd.h gsm_04_80.h \
 | 
				
			||||||
		 silent_call.h mgcp.h meas_rep.h rest_octets.h \
 | 
							 silent_call.h mgcp.h meas_rep.h rest_octets.h \
 | 
				
			||||||
		 system_information.h handover.h mgcp_internal.h \
 | 
							 system_information.h handover.h mgcp_internal.h \
 | 
				
			||||||
		 vty.h
 | 
							 vty.h bssap.h bsc_msc.h bsc_nat.h bsc_msc_rf.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h
 | 
					openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h
 | 
				
			||||||
openbscdir = $(includedir)/openbsc
 | 
					openbscdir = $(includedir)/openbsc
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -68,13 +68,16 @@ unsigned int get_paging_group(u_int64_t imsi, unsigned int bs_cc_chans,
 | 
				
			|||||||
unsigned int n_pag_blocks(int bs_ccch_sdcch_comb, unsigned int bs_ag_blks_res);
 | 
					unsigned int n_pag_blocks(int bs_ccch_sdcch_comb, unsigned int bs_ag_blks_res);
 | 
				
			||||||
u_int64_t str_to_imsi(const char *imsi_str);
 | 
					u_int64_t str_to_imsi(const char *imsi_str);
 | 
				
			||||||
u_int8_t lchan2chan_nr(const struct gsm_lchan *lchan);
 | 
					u_int8_t lchan2chan_nr(const struct gsm_lchan *lchan);
 | 
				
			||||||
int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id);
 | 
					int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id, u_int8_t release_reason);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int rsl_lchan_set_state(struct gsm_lchan *lchan, int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int rsl_lchan_set_state(struct gsm_lchan *lchan, int);
 | 
					int rsl_lchan_set_state(struct gsm_lchan *lchan, int);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* to be provided by external code */
 | 
					/* to be provided by external code */
 | 
				
			||||||
int abis_rsl_sendmsg(struct msgb *msg);
 | 
					int abis_rsl_sendmsg(struct msgb *msg);
 | 
				
			||||||
int rsl_deact_sacch(struct gsm_lchan *lchan);
 | 
					int rsl_deact_sacch(struct gsm_lchan *lchan);
 | 
				
			||||||
 | 
					int rsl_lchan_rll_release(struct gsm_lchan *lchan, u_int8_t link_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* BCCH related code */
 | 
					/* BCCH related code */
 | 
				
			||||||
int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf);
 | 
					int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										48
									
								
								openbsc/include/openbsc/bsc_msc.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								openbsc/include/openbsc/bsc_msc.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					/* Routines to talk to the MSC using the IPA Protocol */
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
 | 
				
			||||||
 | 
					 * (C) 2010 by On-Waves
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef BSC_MSC_H
 | 
				
			||||||
 | 
					#define BSC_MSC_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/write_queue.h>
 | 
				
			||||||
 | 
					#include <osmocore/timer.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_msc_connection {
 | 
				
			||||||
 | 
						struct write_queue write_queue;
 | 
				
			||||||
 | 
						int is_connected;
 | 
				
			||||||
 | 
						int is_authenticated;
 | 
				
			||||||
 | 
						const char *ip;
 | 
				
			||||||
 | 
						int port;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void (*connection_loss) (struct bsc_msc_connection *);
 | 
				
			||||||
 | 
						void (*connected) (struct bsc_msc_connection *);
 | 
				
			||||||
 | 
						struct timer_list reconnect_timer;
 | 
				
			||||||
 | 
						struct timer_list timeout_timer;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_msc_connection *bsc_msc_create(const char *ip, int port);
 | 
				
			||||||
 | 
					int bsc_msc_connect(struct bsc_msc_connection *);
 | 
				
			||||||
 | 
					void bsc_msc_schedule_connect(struct bsc_msc_connection *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bsc_msc_lost(struct bsc_msc_connection *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										20
									
								
								openbsc/include/openbsc/bsc_msc_rf.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								openbsc/include/openbsc/bsc_msc_rf.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					#ifndef BSC_MSC_RF
 | 
				
			||||||
 | 
					#define BSC_MSC_RF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/write_queue.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct gsm_network;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_msc_rf {
 | 
				
			||||||
 | 
						struct bsc_fd listen;
 | 
				
			||||||
 | 
						struct gsm_network *gsm_network;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_msc_rf_conn {
 | 
				
			||||||
 | 
						struct write_queue queue;
 | 
				
			||||||
 | 
						struct gsm_network *gsm_network;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_msc_rf *bsc_msc_rf_create(const char *path, struct gsm_network *net);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										287
									
								
								openbsc/include/openbsc/bsc_nat.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										287
									
								
								openbsc/include/openbsc/bsc_nat.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,287 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
 | 
				
			||||||
 | 
					 * (C) 2010 by On-Waves
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef BSC_NAT_H
 | 
				
			||||||
 | 
					#define BSC_NAT_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "mgcp.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sys/types.h>
 | 
				
			||||||
 | 
					#include <sccp/sccp_types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/select.h>
 | 
				
			||||||
 | 
					#include <osmocore/msgb.h>
 | 
				
			||||||
 | 
					#include <osmocore/timer.h>
 | 
				
			||||||
 | 
					#include <osmocore/write_queue.h>
 | 
				
			||||||
 | 
					#include <osmocore/statistics.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <regex.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define DIR_BSC 1
 | 
				
			||||||
 | 
					#define DIR_MSC 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define NAT_IPAC_PROTO_MGCP	0xfc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_nat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * For the NAT we will need to analyze and later patch
 | 
				
			||||||
 | 
					 * the received message. This would require us to parse
 | 
				
			||||||
 | 
					 * the IPA and SCCP header twice. Instead of doing this
 | 
				
			||||||
 | 
					 * we will have one analyze structure and have the patching
 | 
				
			||||||
 | 
					 * and filter operate on the same structure.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct bsc_nat_parsed {
 | 
				
			||||||
 | 
						/* ip access prototype */
 | 
				
			||||||
 | 
						int ipa_proto;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* source local reference */
 | 
				
			||||||
 | 
						struct sccp_source_reference *src_local_ref;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* destination local reference */
 | 
				
			||||||
 | 
						struct sccp_source_reference *dest_local_ref;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* called ssn number */
 | 
				
			||||||
 | 
						int called_ssn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* calling ssn number */
 | 
				
			||||||
 | 
						int calling_ssn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* sccp message type */
 | 
				
			||||||
 | 
						int sccp_type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* bssap type, e.g. 0 for BSS Management */
 | 
				
			||||||
 | 
						int bssap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* the gsm0808 message type */
 | 
				
			||||||
 | 
						int gsm_type;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Per BSC data structure
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct bsc_connection {
 | 
				
			||||||
 | 
						struct llist_head list_entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* do we know anything about this BSC? */
 | 
				
			||||||
 | 
						int authenticated;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* the fd we use to communicate */
 | 
				
			||||||
 | 
						struct write_queue write_queue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* the BSS associated */
 | 
				
			||||||
 | 
						struct bsc_config *cfg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* a timeout node */
 | 
				
			||||||
 | 
						struct timer_list id_timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* pong timeout */
 | 
				
			||||||
 | 
						struct timer_list ping_timeout;
 | 
				
			||||||
 | 
						struct timer_list pong_timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* a back pointer */
 | 
				
			||||||
 | 
						struct bsc_nat *nat;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Per SCCP source local reference patch table. It needs to
 | 
				
			||||||
 | 
					 * be updated on new SCCP connections, connection confirm and reject,
 | 
				
			||||||
 | 
					 * and on the loss of the BSC connection.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct sccp_connections {
 | 
				
			||||||
 | 
						struct llist_head list_entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct bsc_connection *bsc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct sccp_source_reference real_ref;
 | 
				
			||||||
 | 
						struct sccp_source_reference patched_ref;
 | 
				
			||||||
 | 
						struct sccp_source_reference remote_ref;
 | 
				
			||||||
 | 
						int has_remote_ref;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* GSM audio handling. That is 32 * multiplex + ts */
 | 
				
			||||||
 | 
						int crcx;
 | 
				
			||||||
 | 
						int msc_timeslot;
 | 
				
			||||||
 | 
						int bsc_timeslot;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Stats per BSC
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct bsc_config_stats {
 | 
				
			||||||
 | 
						struct {
 | 
				
			||||||
 | 
							struct counter *conn;
 | 
				
			||||||
 | 
							struct counter *calls;
 | 
				
			||||||
 | 
						} sccp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct {
 | 
				
			||||||
 | 
							struct counter *reconn;
 | 
				
			||||||
 | 
						} net;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * One BSC entry in the config
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct bsc_config {
 | 
				
			||||||
 | 
						struct llist_head entry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						char *token;
 | 
				
			||||||
 | 
						unsigned int lac;
 | 
				
			||||||
 | 
						int nr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* imsi white and blacklist */
 | 
				
			||||||
 | 
						char *imsi_allow;
 | 
				
			||||||
 | 
						regex_t imsi_allow_re;
 | 
				
			||||||
 | 
						char *imsi_deny;
 | 
				
			||||||
 | 
						regex_t imsi_deny_re;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						int forbid_paging;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* backpointer */
 | 
				
			||||||
 | 
						struct bsc_nat *nat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct bsc_config_stats stats;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * BSCs point of view of endpoints
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct bsc_endpoint {
 | 
				
			||||||
 | 
						/* the pending transaction id */
 | 
				
			||||||
 | 
						char *transaction_id;
 | 
				
			||||||
 | 
						/* the bsc we are talking to */
 | 
				
			||||||
 | 
						struct bsc_connection *bsc;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Statistic for the nat.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct bsc_nat_statistics {
 | 
				
			||||||
 | 
						struct {
 | 
				
			||||||
 | 
							struct counter *conn;
 | 
				
			||||||
 | 
							struct counter *calls;
 | 
				
			||||||
 | 
						} sccp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct {
 | 
				
			||||||
 | 
							struct counter *reconn;
 | 
				
			||||||
 | 
					                struct counter *auth_fail;
 | 
				
			||||||
 | 
						} bsc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct {
 | 
				
			||||||
 | 
							struct counter *reconn;
 | 
				
			||||||
 | 
						} msc;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * the structure of the "nat" network
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct bsc_nat {
 | 
				
			||||||
 | 
						/* active SCCP connections that need patching */
 | 
				
			||||||
 | 
						struct llist_head sccp_connections;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* active BSC connections that need patching */
 | 
				
			||||||
 | 
						struct llist_head bsc_connections;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* known BSC's */
 | 
				
			||||||
 | 
						struct llist_head bsc_configs;
 | 
				
			||||||
 | 
						int num_bsc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* MGCP config */
 | 
				
			||||||
 | 
						struct mgcp_config *mgcp_cfg;
 | 
				
			||||||
 | 
						struct write_queue mgcp_queue;
 | 
				
			||||||
 | 
						u_int8_t mgcp_msg[4096];
 | 
				
			||||||
 | 
						int mgcp_length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* msc things */
 | 
				
			||||||
 | 
						char *msc_ip;
 | 
				
			||||||
 | 
						int msc_port;
 | 
				
			||||||
 | 
						int first_contact;
 | 
				
			||||||
 | 
						struct bsc_msc_connection *msc_con;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* timeouts */
 | 
				
			||||||
 | 
						int auth_timeout;
 | 
				
			||||||
 | 
						int ping_timeout;
 | 
				
			||||||
 | 
						int pong_timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct bsc_endpoint *bsc_endpoints;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* filter */
 | 
				
			||||||
 | 
						char *imsi_allow;
 | 
				
			||||||
 | 
						regex_t imsi_allow_re;
 | 
				
			||||||
 | 
						char *imsi_deny;
 | 
				
			||||||
 | 
						regex_t imsi_deny_re;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* statistics */
 | 
				
			||||||
 | 
						struct bsc_nat_statistics stats;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* create and init the structures */
 | 
				
			||||||
 | 
					struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token, unsigned int lac);
 | 
				
			||||||
 | 
					struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num);
 | 
				
			||||||
 | 
					struct bsc_nat *bsc_nat_alloc(void);
 | 
				
			||||||
 | 
					struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat);
 | 
				
			||||||
 | 
					void bsc_nat_set_msc_ip(struct bsc_nat *bsc, const char *ip);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sccp_connection_destroy(struct sccp_connections *);
 | 
				
			||||||
 | 
					void bsc_close_connection(struct bsc_connection *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * parse the given message into the above structure
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct bsc_nat_parsed *bsc_nat_parse(struct msgb *msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * filter based on IP Access header in both directions
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int bsc_nat_filter_ipa(int direction, struct msgb *msg, struct bsc_nat_parsed *parsed);
 | 
				
			||||||
 | 
					int bsc_nat_vty_init(struct bsc_nat *nat);
 | 
				
			||||||
 | 
					struct bsc_connection *bsc_nat_find_bsc(struct bsc_nat *nat, struct msgb *msg, int *_lac);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * SCCP patching and handling
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int create_sccp_src_ref(struct bsc_connection *bsc, struct msgb *msg, struct bsc_nat_parsed *parsed);
 | 
				
			||||||
 | 
					int update_sccp_src_ref(struct sccp_connections *sccp, struct bsc_nat_parsed *parsed);
 | 
				
			||||||
 | 
					void remove_sccp_src_ref(struct bsc_connection *bsc, struct msgb *msg, struct bsc_nat_parsed *parsed);
 | 
				
			||||||
 | 
					struct sccp_connections *patch_sccp_src_ref_to_bsc(struct msgb *, struct bsc_nat_parsed *, struct bsc_nat *);
 | 
				
			||||||
 | 
					struct sccp_connections *patch_sccp_src_ref_to_msc(struct msgb *, struct bsc_nat_parsed *, struct bsc_connection *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * MGCP/Audio handling
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int bsc_write_mgcp(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length);
 | 
				
			||||||
 | 
					int bsc_mgcp_assign(struct sccp_connections *, struct msgb *msg);
 | 
				
			||||||
 | 
					void bsc_mgcp_init(struct sccp_connections *);
 | 
				
			||||||
 | 
					void bsc_mgcp_dlcx(struct sccp_connections *);
 | 
				
			||||||
 | 
					void bsc_mgcp_free_endpoints(struct bsc_nat *nat);
 | 
				
			||||||
 | 
					int bsc_mgcp_nat_init(struct bsc_nat *nat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct sccp_connections *bsc_mgcp_find_con(struct bsc_nat *, int endpoint_number);
 | 
				
			||||||
 | 
					struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port);
 | 
				
			||||||
 | 
					void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc);
 | 
				
			||||||
 | 
					int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60]);
 | 
				
			||||||
 | 
					int bsc_mgcp_extract_ci(const char *resp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_write(struct bsc_connection *bsc, struct msgb *msg, int id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										333
									
								
								openbsc/include/openbsc/bssap.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										333
									
								
								openbsc/include/openbsc/bssap.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,333 @@
 | 
				
			|||||||
 | 
					/* From GSM08.08 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef BSSAP_H
 | 
				
			||||||
 | 
					#define BSSAP_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/msgb.h>
 | 
				
			||||||
 | 
					#include <openbsc/gsm_data.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * this is from GSM 03.03 CGI but is copied in GSM 08.08
 | 
				
			||||||
 | 
					 * in § 3.2.2.27 for Cell Identifier List
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					enum CELL_IDENT {
 | 
				
			||||||
 | 
						CELL_IDENT_WHOLE_GLOBAL		= 0,
 | 
				
			||||||
 | 
						CELL_IDENT_LAC_AND_CI		= 1,
 | 
				
			||||||
 | 
						CELL_IDENT_CI			= 2,
 | 
				
			||||||
 | 
						CELL_IDENT_NO_CELL		= 3,
 | 
				
			||||||
 | 
						CELL_IDENT_LAI_AND_LAC		= 4,
 | 
				
			||||||
 | 
						CELL_IDENT_LAC			= 5,
 | 
				
			||||||
 | 
						CELL_IDENT_BSS			= 6,
 | 
				
			||||||
 | 
						CELL_IDENT_UTRAN_PLMN_LAC_RNC	= 8,
 | 
				
			||||||
 | 
						CELL_IDENT_UTRAN_RNC		= 9,
 | 
				
			||||||
 | 
						CELL_IDENT_UTRAN_LAC_RNC	= 10,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* GSM 08.06 § 6.3 */
 | 
				
			||||||
 | 
					enum BSSAP_MSG_TYPE {
 | 
				
			||||||
 | 
						BSSAP_MSG_BSS_MANAGEMENT    = 0x0,
 | 
				
			||||||
 | 
						BSSAP_MSG_DTAP		    = 0x1,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bssmap_header {
 | 
				
			||||||
 | 
						u_int8_t type;
 | 
				
			||||||
 | 
						u_int8_t length;
 | 
				
			||||||
 | 
					} __attribute__((packed));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct dtap_header {
 | 
				
			||||||
 | 
						u_int8_t type;
 | 
				
			||||||
 | 
						u_int8_t link_id;
 | 
				
			||||||
 | 
						u_int8_t length;
 | 
				
			||||||
 | 
					} __attribute__((packed));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum BSS_MAP_MSG_TYPE {
 | 
				
			||||||
 | 
						BSS_MAP_MSG_RESERVED_0		= 0,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* ASSIGNMENT MESSAGES */
 | 
				
			||||||
 | 
						BSS_MAP_MSG_ASSIGMENT_RQST	= 1,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_ASSIGMENT_COMPLETE	= 2,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_ASSIGMENT_FAILURE	= 3,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*  HANDOVER MESSAGES */
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_RQST		= 16,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_REQUIRED		= 17,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE= 18,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_CMD		= 19,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_COMPLETE		= 20,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_SUCCEEDED		= 21,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_FAILURE		= 22,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_PERFORMED		= 23,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_CANDIDATE_ENQUIRE	= 24,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_CANDIDATE_RESPONSE	= 25,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_REQUIRED_REJECT	= 26,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_HANDOVER_DETECT		= 27,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* RELEASE MESSAGES */
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CLEAR_CMD		= 32,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CLEAR_COMPLETE		= 33,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CLEAR_RQST		= 34,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_RESERVED_1			= 35,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_RESERVED_2			= 36,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_SAPI_N_REJECT		= 37,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CONFUSION			= 38,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* OTHER CONNECTION RELATED MESSAGES */
 | 
				
			||||||
 | 
						BSS_MAP_MSG_SUSPEND			= 40,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_RESUME			= 41,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CONNECTION_ORIENTED_INFORMATION = 42,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_PERFORM_LOCATION_RQST	= 43,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_LSA_INFORMATION		= 44,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_PERFORM_LOCATION_RESPONSE	= 45,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_PERFORM_LOCATION_ABORT	= 46,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_COMMON_ID			= 47,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* GENERAL MESSAGES */
 | 
				
			||||||
 | 
						BSS_MAP_MSG_RESET			= 48,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_RESET_ACKNOWLEDGE		= 49,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_OVERLOAD			= 50,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_RESERVED_3			= 51,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_RESET_CIRCUIT		= 52,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_RESET_CIRCUIT_ACKNOWLEDGE	= 53,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_MSC_INVOKE_TRACE		= 54,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_BSS_INVOKE_TRACE		= 55,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CONNECTIONLESS_INFORMATION	= 58,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* TERRESTRIAL RESOURCE MESSAGES */
 | 
				
			||||||
 | 
						BSS_MAP_MSG_BLOCK			= 64,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_BLOCKING_ACKNOWLEDGE	= 65,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_UNBLOCK			= 66,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_UNBLOCKING_ACKNOWLEDGE	= 67,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CIRCUIT_GROUP_BLOCK		= 68,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CIRCUIT_GROUP_BLOCKING_ACKNOWLEDGE	= 69,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCK	= 70,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCKING_ACKNOWLEDGE = 71,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_UNEQUIPPED_CIRCUIT		= 72,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CHANGE_CIRCUIT		= 78,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CHANGE_CIRCUIT_ACKNOWLEDGE	= 79,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* RADIO RESOURCE MESSAGES */
 | 
				
			||||||
 | 
						BSS_MAP_MSG_RESOURCE_RQST		= 80,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_RESOURCE_INDICATION		= 81,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_PAGING			= 82,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CIPHER_MODE_CMD		= 83,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CLASSMARK_UPDATE		= 84,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CIPHER_MODE_COMPLETE	= 85,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_QUEUING_INDICATION		= 86,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_COMPLETE_LAYER_3		= 87,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CLASSMARK_RQST		= 88,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_CIPHER_MODE_REJECT		= 89,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_LOAD_INDICATION		= 90,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* VGCS/VBS */
 | 
				
			||||||
 | 
						BSS_MAP_MSG_VGCS_VBS_SETUP		= 4,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_VGCS_VBS_SETUP_ACK		= 5,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_VGCS_VBS_SETUP_REFUSE	= 6,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RQST	= 7,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RESULT	= 28,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_FAILURE	= 29,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_VGCS_VBS_QUEUING_INDICATION	= 30,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_UPLINK_RQST		= 31,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_UPLINK_RQST_ACKNOWLEDGE	= 39,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_UPLINK_RQST_CONFIRMATION	= 73,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_UPLINK_RELEASE_INDICATION	= 74,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_UPLINK_REJECT_CMD	= 75,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_UPLINK_RELEASE_CMD	= 76,
 | 
				
			||||||
 | 
						BSS_MAP_MSG_UPLINK_SEIZED_CMD	= 77,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum GSM0808_IE_CODING {
 | 
				
			||||||
 | 
						GSM0808_IE_CIRCUIT_IDENTITY_CODE	= 1,
 | 
				
			||||||
 | 
						GSM0808_IE_RESERVED_0			= 2,
 | 
				
			||||||
 | 
						GSM0808_IE_RESOURCE_AVAILABLE		= 3,
 | 
				
			||||||
 | 
						GSM0808_IE_CAUSE			= 4,
 | 
				
			||||||
 | 
						GSM0808_IE_CELL_IDENTIFIER		= 5,
 | 
				
			||||||
 | 
						GSM0808_IE_PRIORITY			= 6,
 | 
				
			||||||
 | 
						GSM0808_IE_LAYER_3_HEADER_INFORMATION	= 7,
 | 
				
			||||||
 | 
						GSM0808_IE_IMSI				= 8,
 | 
				
			||||||
 | 
						GSM0808_IE_TMSI				= 9,
 | 
				
			||||||
 | 
						GSM0808_IE_ENCRYPTION_INFORMATION	= 10,
 | 
				
			||||||
 | 
						GSM0808_IE_CHANNEL_TYPE			= 11,
 | 
				
			||||||
 | 
						GSM0808_IE_PERIODICITY			= 12,
 | 
				
			||||||
 | 
						GSM0808_IE_EXTENDED_RESOURCE_INDICATOR	= 13,
 | 
				
			||||||
 | 
						GSM0808_IE_NUMBER_OF_MSS		= 14,
 | 
				
			||||||
 | 
						GSM0808_IE_RESERVED_1			= 15,
 | 
				
			||||||
 | 
						GSM0808_IE_RESERVED_2			= 16,
 | 
				
			||||||
 | 
						GSM0808_IE_RESERVED_3			= 17,
 | 
				
			||||||
 | 
						GSM0808_IE_CLASSMARK_INFORMATION_T2	= 18,
 | 
				
			||||||
 | 
						GSM0808_IE_CLASSMARK_INFORMATION_T3	= 19,
 | 
				
			||||||
 | 
						GSM0808_IE_INTERFERENCE_BAND_TO_USE	= 20,
 | 
				
			||||||
 | 
						GSM0808_IE_RR_CAUSE			= 21,
 | 
				
			||||||
 | 
						GSM0808_IE_RESERVED_4			= 22,
 | 
				
			||||||
 | 
						GSM0808_IE_LAYER_3_INFORMATION		= 23,
 | 
				
			||||||
 | 
						GSM0808_IE_DLCI				= 24,
 | 
				
			||||||
 | 
						GSM0808_IE_DOWNLINK_DTX_FLAG		= 25,
 | 
				
			||||||
 | 
						GSM0808_IE_CELL_IDENTIFIER_LIST		= 26,
 | 
				
			||||||
 | 
						GSM0808_IE_RESPONSE_RQST		= 27,
 | 
				
			||||||
 | 
						GSM0808_IE_RESOURCE_INDICATION_METHOD	= 28,
 | 
				
			||||||
 | 
						GSM0808_IE_CLASSMARK_INFORMATION_TYPE_1	= 29,
 | 
				
			||||||
 | 
						GSM0808_IE_CIRCUIT_IDENTITY_CODE_LIST	= 30,
 | 
				
			||||||
 | 
						GSM0808_IE_DIAGNOSTIC			= 31,
 | 
				
			||||||
 | 
						GSM0808_IE_LAYER_3_MESSAGE_CONTENTS	= 32,
 | 
				
			||||||
 | 
						GSM0808_IE_CHOSEN_CHANNEL		= 33,
 | 
				
			||||||
 | 
						GSM0808_IE_TOTAL_RESOURCE_ACCESSIBLE	= 34,
 | 
				
			||||||
 | 
						GSM0808_IE_CIPHER_RESPONSE_MODE		= 35,
 | 
				
			||||||
 | 
						GSM0808_IE_CHANNEL_NEEDED		= 36,
 | 
				
			||||||
 | 
						GSM0808_IE_TRACE_TYPE			= 37,
 | 
				
			||||||
 | 
						GSM0808_IE_TRIGGERID			= 38,
 | 
				
			||||||
 | 
						GSM0808_IE_TRACE_REFERENCE		= 39,
 | 
				
			||||||
 | 
						GSM0808_IE_TRANSACTIONID		= 40,
 | 
				
			||||||
 | 
						GSM0808_IE_MOBILE_IDENTITY		= 41,
 | 
				
			||||||
 | 
						GSM0808_IE_OMCID			= 42,
 | 
				
			||||||
 | 
						GSM0808_IE_FORWARD_INDICATOR		= 43,
 | 
				
			||||||
 | 
						GSM0808_IE_CHOSEN_ENCR_ALG		= 44,
 | 
				
			||||||
 | 
						GSM0808_IE_CIRCUIT_POOL			= 45,
 | 
				
			||||||
 | 
						GSM0808_IE_CIRCUIT_POOL_LIST		= 46,
 | 
				
			||||||
 | 
						GSM0808_IE_TIME_INDICATION		= 47,
 | 
				
			||||||
 | 
						GSM0808_IE_RESOURCE_SITUATION		= 48,
 | 
				
			||||||
 | 
						GSM0808_IE_CURRENT_CHANNEL_TYPE_1	= 49,
 | 
				
			||||||
 | 
						GSM0808_IE_QUEUEING_INDICATOR		= 50,
 | 
				
			||||||
 | 
						GSM0808_IE_SPEECH_VERSION		= 64,
 | 
				
			||||||
 | 
						GSM0808_IE_ASSIGNMENT_REQUIREMENT	= 51,
 | 
				
			||||||
 | 
						GSM0808_IE_TALKER_FLAG			= 53,
 | 
				
			||||||
 | 
						GSM0808_IE_CONNECTION_RELEASE_RQSTED	= 54,
 | 
				
			||||||
 | 
						GSM0808_IE_GROUP_CALL_REFERENCE		= 55,
 | 
				
			||||||
 | 
						GSM0808_IE_EMLPP_PRIORITY		= 56,
 | 
				
			||||||
 | 
						GSM0808_IE_CONFIG_EVO_INDI		= 57,
 | 
				
			||||||
 | 
						GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION	= 58,
 | 
				
			||||||
 | 
						GSM0808_IE_LSA_IDENTIFIER		= 59,
 | 
				
			||||||
 | 
						GSM0808_IE_LSA_IDENTIFIER_LIST		= 60,
 | 
				
			||||||
 | 
						GSM0808_IE_LSA_INFORMATION		= 61,
 | 
				
			||||||
 | 
						GSM0808_IE_LCS_QOS			= 62,
 | 
				
			||||||
 | 
						GSM0808_IE_LSA_ACCESS_CTRL_SUPPR	= 63,
 | 
				
			||||||
 | 
						GSM0808_IE_LCS_PRIORITY			= 67,
 | 
				
			||||||
 | 
						GSM0808_IE_LOCATION_TYPE		= 68,
 | 
				
			||||||
 | 
						GSM0808_IE_LOCATION_ESTIMATE		= 69,
 | 
				
			||||||
 | 
						GSM0808_IE_POSITIONING_DATA		= 70,
 | 
				
			||||||
 | 
						GSM0808_IE_LCS_CAUSE			= 71,
 | 
				
			||||||
 | 
						GSM0808_IE_LCS_CLIENT_TYPE		= 72,
 | 
				
			||||||
 | 
						GSM0808_IE_APDU				= 73,
 | 
				
			||||||
 | 
						GSM0808_IE_NETWORK_ELEMENT_IDENTITY	= 74,
 | 
				
			||||||
 | 
						GSM0808_IE_GPS_ASSISTANCE_DATA		= 75,
 | 
				
			||||||
 | 
						GSM0808_IE_DECIPHERING_KEYS		= 76,
 | 
				
			||||||
 | 
						GSM0808_IE_RETURN_ERROR_RQST		= 77,
 | 
				
			||||||
 | 
						GSM0808_IE_RETURN_ERROR_CAUSE		= 78,
 | 
				
			||||||
 | 
						GSM0808_IE_SEGMENTATION			= 79,
 | 
				
			||||||
 | 
						GSM0808_IE_SERVICE_HANDOVER		= 80,
 | 
				
			||||||
 | 
						GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_UMTS	= 81,
 | 
				
			||||||
 | 
						GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_CDMA2000= 82,
 | 
				
			||||||
 | 
						GSM0808_IE_RESERVED_5			= 65,
 | 
				
			||||||
 | 
						GSM0808_IE_RESERVED_6			= 66,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum gsm0808_cause {
 | 
				
			||||||
 | 
						GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE			= 0,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_RADIO_INTERFACE_FAILURE				= 1,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_UPLINK_QUALITY					= 2,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_UPLINK_STRENGTH					= 3,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_DOWNLINK_QUALITY					= 4,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_DOWNLINK_STRENGTH					= 5,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_DISTANCE						= 6,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_O_AND_M_INTERVENTION				= 7,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_RESPONSE_TO_MSC_INVOCATION			= 8,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_CALL_CONTROL					= 9,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION			= 10,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_HANDOVER_SUCCESSFUL				= 11,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_BETTER_CELL					= 12,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_DIRECTED_RETRY					= 13,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_JOINED_GROUP_CALL_CHANNEL				= 14,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_TRAFFIC						= 15,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_EQUIPMENT_FAILURE					= 32,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE			= 33,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_RQSTED_TERRESTRIAL_RESOURCE_UNAVAILABLE	= 34,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_CCCH_OVERLOAD					= 35,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_PROCESSOR_OVERLOAD				= 36,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_BSS_NOT_EQUIPPED					= 37,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_MS_NOT_EQUIPPED					= 38,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_INVALID_CELL					= 39,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_TRAFFIC_LOAD					= 40,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_PREEMPTION					= 41,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_RQSTED_TRANSCODING_RATE_ADAPTION_UNAVAILABLE	= 48,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_CIRCUIT_POOL_MISMATCH				= 49,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_SWITCH_CIRCUIT_POOL				= 50,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_RQSTED_SPEECH_VERSION_UNAVAILABLE		= 51,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_LSA_NOT_ALLOWED					= 52,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED			= 64,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_TERRESTRIAL_CIRCUIT_ALREADY_ALLOCATED		= 80,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_INVALID_MESSAGE_CONTENTS				= 81,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING		= 82,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_INCORRECT_VALUE					= 83,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_UNKNOWN_MESSAGE_TYPE				= 84,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_UNKNOWN_INFORMATION_ELEMENT			= 85,
 | 
				
			||||||
 | 
						GSM0808_CAUSE_PROTOCOL_ERROR_BETWEEN_BSS_AND_MSC		= 96,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* GSM 08.08 3.2.2.11 Channel Type */
 | 
				
			||||||
 | 
					enum gsm0808_chan_indicator {
 | 
				
			||||||
 | 
						GSM0808_CHAN_SPEECH = 1,
 | 
				
			||||||
 | 
						GSM0808_CHAN_DATA   = 2,
 | 
				
			||||||
 | 
						GSM0808_CHAN_SIGN   = 3,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum gsm0808_chan_rate_type_data {
 | 
				
			||||||
 | 
						GSM0808_DATA_FULL_BM	= 0x8,
 | 
				
			||||||
 | 
						GSM0808_DATA_HALF_LM	= 0x9,
 | 
				
			||||||
 | 
						GSM0808_DATA_FULL_RPREF	= 0xa,
 | 
				
			||||||
 | 
						GSM0808_DATA_HALF_PREF	= 0xb,
 | 
				
			||||||
 | 
						GSM0808_DATA_FULL_PREF_NO_CHANGE	= 0x1a,
 | 
				
			||||||
 | 
						GSM0808_DATA_HALF_PREF_NO_CHANGE	= 0x1b,
 | 
				
			||||||
 | 
						GSM0808_DATA_MULTI_MASK	= 0x20,
 | 
				
			||||||
 | 
						GSM0808_DATA_MULTI_MASK_NO_CHANGE	= 0x30,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum gsm0808_chan_rate_type_speech {
 | 
				
			||||||
 | 
						GSM0808_SPEECH_FULL_BM	= 0x8,
 | 
				
			||||||
 | 
						GSM0808_SPEECH_HALF_LM	= 0x9,
 | 
				
			||||||
 | 
						GSM0808_SPEECH_FULL_PREF= 0xa,
 | 
				
			||||||
 | 
						GSM0808_SPEECH_HALF_PREF= 0xb,
 | 
				
			||||||
 | 
						GSM0808_SPEECH_FULL_PREF_NO_CHANGE	= 0x1a,
 | 
				
			||||||
 | 
						GSM0808_SPEECH_HALF_PREF_NO_CHANGE	= 0x1b,
 | 
				
			||||||
 | 
						GSM0808_SPEECH_PERM	= 0xf,
 | 
				
			||||||
 | 
						GSM0808_SPEECH_PERM_NO_CHANGE = 0x1f,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum gsm0808_permitted_speech {
 | 
				
			||||||
 | 
						GSM0808_PERM_FR1	= 0x01,
 | 
				
			||||||
 | 
						GSM0808_PERM_FR2	= 0x11,
 | 
				
			||||||
 | 
						GSM0808_PERM_FR3	= 0x21,
 | 
				
			||||||
 | 
						GSM0808_PERM_HR1	= GSM0808_PERM_FR1 | 0x4,
 | 
				
			||||||
 | 
						GSM0808_PERM_HR2	= GSM0808_PERM_FR2 | 0x4,
 | 
				
			||||||
 | 
						GSM0808_PERM_HR3	= GSM0808_PERM_FR3 | 0x4,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bssmap_rcvmsg_dt1(struct sccp_connection *conn, struct msgb *msg, unsigned int length);
 | 
				
			||||||
 | 
					int bssmap_rcvmsg_udt(struct gsm_network *net, struct msgb *msg, unsigned int length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct msgb *bssmap_create_layer3(struct msgb *msg);
 | 
				
			||||||
 | 
					struct msgb *bssmap_create_reset(void);
 | 
				
			||||||
 | 
					struct msgb *bssmap_create_clear_complete(void);
 | 
				
			||||||
 | 
					struct msgb *bssmap_create_cipher_complete(struct msgb *layer3);
 | 
				
			||||||
 | 
					struct msgb *bssmap_create_cipher_reject(u_int8_t cause);
 | 
				
			||||||
 | 
					struct msgb *bssmap_create_sapi_reject(u_int8_t link_id);
 | 
				
			||||||
 | 
					struct msgb *bssmap_create_assignment_completed(struct gsm_lchan *lchan, u_int8_t rr_cause);
 | 
				
			||||||
 | 
					struct msgb *bssmap_create_assignment_failure(u_int8_t cause, u_int8_t *rr_cause);
 | 
				
			||||||
 | 
					struct msgb *bssmap_create_classmark_update(const u_int8_t *classmark, u_int8_t length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void gsm0808_send_assignment_failure(struct gsm_lchan *l, u_int8_t cause, u_int8_t *rr_value);
 | 
				
			||||||
 | 
					void gsm0808_send_assignment_compl(struct gsm_lchan *l, u_int8_t rr_value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int dtap_rcvmsg(struct gsm_lchan *lchan, struct msgb *msg, unsigned int length);
 | 
				
			||||||
 | 
					struct msgb *dtap_create_msg(struct msgb *msg_l3, u_int8_t link_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bsc_queue_connection_write(struct sccp_connection *conn, struct msgb *msg);
 | 
				
			||||||
 | 
					void bsc_free_queued(struct sccp_connection *conn);
 | 
				
			||||||
 | 
					void bsc_send_queued(struct sccp_connection *conn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bts_send_queued(struct bss_sccp_connection_data*);
 | 
				
			||||||
 | 
					void bts_free_queued(struct bss_sccp_connection_data*);
 | 
				
			||||||
 | 
					void bts_unblock_queue(struct bss_sccp_connection_data*);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
@@ -23,6 +23,28 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "gsm_subscriber.h"
 | 
					#include "gsm_subscriber.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Refcounting for the lchan. If the refcount drops to zero
 | 
				
			||||||
 | 
					 * the channel will send a RSL release request.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define use_subscr_con(con) \
 | 
				
			||||||
 | 
						do {	(con)->use_count++; \
 | 
				
			||||||
 | 
							DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
 | 
				
			||||||
 | 
								(con)->lchan->ts->trx->bts->nr, (con)->lchan->ts->trx->nr, (con)->lchan->ts->nr, \
 | 
				
			||||||
 | 
								(con)->lchan->nr, (con)->use_count); \
 | 
				
			||||||
 | 
						} while(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define put_subscr_con(con, reason) \
 | 
				
			||||||
 | 
						do { (con)->use_count--; \
 | 
				
			||||||
 | 
							DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
 | 
				
			||||||
 | 
								(con)->lchan->ts->trx->bts->nr, (con)->lchan->ts->trx->nr, (con)->lchan->ts->nr, \
 | 
				
			||||||
 | 
								(con)->lchan->nr, (con)->use_count); \
 | 
				
			||||||
 | 
						    if ((con)->use_count <= 0) \
 | 
				
			||||||
 | 
							_lchan_release((con)->lchan, reason); \
 | 
				
			||||||
 | 
						} while(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Special allocator for C0 of BTS */
 | 
					/* Special allocator for C0 of BTS */
 | 
				
			||||||
struct gsm_bts_trx_ts *ts_c0_alloc(struct gsm_bts *bts,
 | 
					struct gsm_bts_trx_ts *ts_c0_alloc(struct gsm_bts *bts,
 | 
				
			||||||
				   enum gsm_phys_chan_config pchan);
 | 
									   enum gsm_phys_chan_config pchan);
 | 
				
			||||||
@@ -41,14 +63,14 @@ struct gsm_lchan *lchan_find(struct gsm_bts *bts, struct gsm_subscriber *subscr)
 | 
				
			|||||||
struct gsm_lchan *lchan_for_subscr(struct gsm_subscriber *subscr);
 | 
					struct gsm_lchan *lchan_for_subscr(struct gsm_subscriber *subscr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Allocate a logical channel (SDCCH, TCH, ...) */
 | 
					/* Allocate a logical channel (SDCCH, TCH, ...) */
 | 
				
			||||||
struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type);
 | 
					struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type, int allow_bigger);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Free a logical channel (SDCCH, TCH, ...) */
 | 
					/* Free a logical channel (SDCCH, TCH, ...) */
 | 
				
			||||||
void lchan_free(struct gsm_lchan *lchan);
 | 
					void lchan_free(struct gsm_lchan *lchan);
 | 
				
			||||||
void lchan_reset(struct gsm_lchan *lchan);
 | 
					void lchan_reset(struct gsm_lchan *lchan);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Consider releasing the channel */
 | 
					/* internal.. do not use */
 | 
				
			||||||
int lchan_auto_release(struct gsm_lchan *lchan);
 | 
					int _lchan_release(struct gsm_lchan *lchan, u_int8_t release_reason);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct load_counter {
 | 
					struct load_counter {
 | 
				
			||||||
	unsigned int total;
 | 
						unsigned int total;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,6 +29,7 @@ enum {
 | 
				
			|||||||
	DHO,
 | 
						DHO,
 | 
				
			||||||
	DDB,
 | 
						DDB,
 | 
				
			||||||
	DREF,
 | 
						DREF,
 | 
				
			||||||
 | 
						DNAT,
 | 
				
			||||||
	Debug_LastEntry,
 | 
						Debug_LastEntry,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -66,6 +66,8 @@ struct e1inp_ts {
 | 
				
			|||||||
		struct {
 | 
							struct {
 | 
				
			||||||
			/* list of all signalling links on this TS */
 | 
								/* list of all signalling links on this TS */
 | 
				
			||||||
			struct llist_head sign_links;
 | 
								struct llist_head sign_links;
 | 
				
			||||||
 | 
								/* delay for the queue */
 | 
				
			||||||
 | 
								int delay;
 | 
				
			||||||
			/* timer when to dequeue next frame */
 | 
								/* timer when to dequeue next frame */
 | 
				
			||||||
			struct timer_list tx_timer;
 | 
								struct timer_list tx_timer;
 | 
				
			||||||
		} sign;
 | 
							} sign;
 | 
				
			||||||
@@ -93,6 +95,7 @@ struct e1inp_driver {
 | 
				
			|||||||
	struct llist_head list;
 | 
						struct llist_head list;
 | 
				
			||||||
	const char *name;
 | 
						const char *name;
 | 
				
			||||||
	int (*want_write)(struct e1inp_ts *ts);
 | 
						int (*want_write)(struct e1inp_ts *ts);
 | 
				
			||||||
 | 
						int default_delay;
 | 
				
			||||||
};	
 | 
					};	
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct e1inp_line {
 | 
					struct e1inp_line {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,8 +16,9 @@ struct gsm_trans;
 | 
				
			|||||||
void gsm0408_allow_everyone(int allow);
 | 
					void gsm0408_allow_everyone(int allow);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id);
 | 
					int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id);
 | 
				
			||||||
enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci);
 | 
					enum gsm_chan_t get_ctype_by_chreq(struct gsm_network *bts, u_int8_t ra);
 | 
				
			||||||
enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci);
 | 
					enum gsm_chreq_reason_t get_reason_by_chreq(u_int8_t ra, int neci);
 | 
				
			||||||
 | 
					void gsm_net_update_ctype(struct gsm_network *net);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int gsm48_tx_mm_info(struct gsm_lchan *lchan);
 | 
					int gsm48_tx_mm_info(struct gsm_lchan *lchan);
 | 
				
			||||||
int gsm48_tx_mm_auth_req(struct gsm_lchan *lchan, u_int8_t *rand, int key_seq);
 | 
					int gsm48_tx_mm_auth_req(struct gsm_lchan *lchan, u_int8_t *rand, int key_seq);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <sys/types.h>
 | 
					#include <sys/types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_msc_connection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum gsm_phys_chan_config {
 | 
					enum gsm_phys_chan_config {
 | 
				
			||||||
	GSM_PCHAN_NONE,
 | 
						GSM_PCHAN_NONE,
 | 
				
			||||||
	GSM_PCHAN_CCCH,
 | 
						GSM_PCHAN_CCCH,
 | 
				
			||||||
@@ -85,30 +87,7 @@ typedef int gsm_cbfn(unsigned int hooknum,
 | 
				
			|||||||
		     struct msgb *msg,
 | 
							     struct msgb *msg,
 | 
				
			||||||
		     void *data, void *param);
 | 
							     void *data, void *param);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					struct sccp_connection;
 | 
				
			||||||
 * Use the channel. As side effect the lchannel recycle timer
 | 
					 | 
				
			||||||
 * will be started.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define LCHAN_RELEASE_TIMEOUT 20, 0
 | 
					 | 
				
			||||||
#define use_subscr_con(con) \
 | 
					 | 
				
			||||||
	do {	(con)->use_count++; \
 | 
					 | 
				
			||||||
		DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
 | 
					 | 
				
			||||||
			(con)->lchan->ts->trx->bts->nr, (con)->lchan->ts->trx->nr, (con)->lchan->ts->nr, \
 | 
					 | 
				
			||||||
			(con)->lchan->nr, (con)->use_count); \
 | 
					 | 
				
			||||||
		bsc_schedule_timer(&(con)->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define put_subscr_con(con) \
 | 
					 | 
				
			||||||
	do { (con)->use_count--; \
 | 
					 | 
				
			||||||
		DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
 | 
					 | 
				
			||||||
			(con)->lchan->ts->trx->bts->nr, (con)->lchan->ts->trx->nr, (con)->lchan->ts->nr, \
 | 
					 | 
				
			||||||
			(con)->lchan->nr, (con)->use_count); \
 | 
					 | 
				
			||||||
	} while(0);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* communications link with a BTS */
 | 
					 | 
				
			||||||
struct gsm_bts_link {
 | 
					 | 
				
			||||||
	struct gsm_bts *bts;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Real authentication information containing Ki */
 | 
					/* Real authentication information containing Ki */
 | 
				
			||||||
enum gsm_auth_algo {
 | 
					enum gsm_auth_algo {
 | 
				
			||||||
@@ -137,6 +116,44 @@ struct gsm_subscriber;
 | 
				
			|||||||
struct gsm_mncc;
 | 
					struct gsm_mncc;
 | 
				
			||||||
struct rtp_socket;
 | 
					struct rtp_socket;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* BSC/MSC data holding them together */
 | 
				
			||||||
 | 
					struct bss_sccp_connection_data {
 | 
				
			||||||
 | 
						struct gsm_lchan *lchan;
 | 
				
			||||||
 | 
						struct gsm_lchan *secondary_lchan;
 | 
				
			||||||
 | 
						struct sccp_connection *sccp;
 | 
				
			||||||
 | 
						int ciphering_handled : 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* Timers... */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* for assginment command */
 | 
				
			||||||
 | 
					        struct timer_list T10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* for SCCP ... */
 | 
				
			||||||
 | 
						struct timer_list sccp_cc_timeout;
 | 
				
			||||||
 | 
						struct timer_list sccp_it;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* audio handling */
 | 
				
			||||||
 | 
						int rtp_port;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Queue SCCP and GSM0408 messages */
 | 
				
			||||||
 | 
						int block_gsm;
 | 
				
			||||||
 | 
						struct llist_head gsm_queue;
 | 
				
			||||||
 | 
						unsigned int gsm_queue_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct llist_head sccp_queue;
 | 
				
			||||||
 | 
						unsigned int sccp_queue_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Active connections */
 | 
				
			||||||
 | 
						struct llist_head active_connections;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define GSM0808_T10_VALUE	6, 0
 | 
				
			||||||
 | 
					#define sccp_get_lchan(data_ctx) ((struct bss_sccp_connection_data *)data_ctx)->lchan
 | 
				
			||||||
 | 
					#define lchan_get_sccp(lchan) lchan->msc_data->sccp
 | 
				
			||||||
 | 
					struct bss_sccp_connection_data *bss_sccp_create_data();
 | 
				
			||||||
 | 
					void bss_sccp_free_data(struct bss_sccp_connection_data *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Network Management State */
 | 
					/* Network Management State */
 | 
				
			||||||
struct gsm_nm_state {
 | 
					struct gsm_nm_state {
 | 
				
			||||||
	u_int8_t operational;
 | 
						u_int8_t operational;
 | 
				
			||||||
@@ -185,6 +202,7 @@ enum gsm_lchan_state {
 | 
				
			|||||||
	LCHAN_S_ACT_REQ,	/* channel activatin requested */
 | 
						LCHAN_S_ACT_REQ,	/* channel activatin requested */
 | 
				
			||||||
	LCHAN_S_ACTIVE,		/* channel is active and operational */
 | 
						LCHAN_S_ACTIVE,		/* channel is active and operational */
 | 
				
			||||||
	LCHAN_S_REL_REQ,	/* channel release has been requested */
 | 
						LCHAN_S_REL_REQ,	/* channel release has been requested */
 | 
				
			||||||
 | 
						LCHAN_S_REL_ERR,	/* channel is in an error state */
 | 
				
			||||||
	LCHAN_S_INACTIVE,	/* channel is set inactive */
 | 
						LCHAN_S_INACTIVE,	/* channel is set inactive */
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -193,9 +211,6 @@ struct gsm_subscriber_connection {
 | 
				
			|||||||
	/* To whom we are allocated at the moment */
 | 
						/* To whom we are allocated at the moment */
 | 
				
			||||||
	struct gsm_subscriber *subscr;
 | 
						struct gsm_subscriber *subscr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Timer started to release the channel */
 | 
					 | 
				
			||||||
	struct timer_list release_timer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Operations that have a state and might be pending
 | 
						 * Operations that have a state and might be pending
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
@@ -236,6 +251,8 @@ struct gsm_lchan {
 | 
				
			|||||||
	} encr;
 | 
						} encr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct timer_list T3101;
 | 
						struct timer_list T3101;
 | 
				
			||||||
 | 
						struct timer_list T3111;
 | 
				
			||||||
 | 
						struct timer_list error_timer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* AMR bits */
 | 
						/* AMR bits */
 | 
				
			||||||
	struct gsm48_multi_rate_conf mr_conf;
 | 
						struct gsm48_multi_rate_conf mr_conf;
 | 
				
			||||||
@@ -243,6 +260,12 @@ struct gsm_lchan {
 | 
				
			|||||||
	/* Established data link layer services */
 | 
						/* Established data link layer services */
 | 
				
			||||||
	u_int8_t sapis[8];
 | 
						u_int8_t sapis[8];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * MSC handling...
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						struct bss_sccp_connection_data *msc_data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* cache of last measurement reports on this lchan */
 | 
						/* cache of last measurement reports on this lchan */
 | 
				
			||||||
	struct gsm_meas_rep meas_rep[6];
 | 
						struct gsm_meas_rep meas_rep[6];
 | 
				
			||||||
	int meas_rep_idx;
 | 
						int meas_rep_idx;
 | 
				
			||||||
@@ -256,13 +279,15 @@ struct gsm_lchan {
 | 
				
			|||||||
		u_int16_t bound_port;
 | 
							u_int16_t bound_port;
 | 
				
			||||||
		u_int16_t connect_port;
 | 
							u_int16_t connect_port;
 | 
				
			||||||
		u_int16_t conn_id;
 | 
							u_int16_t conn_id;
 | 
				
			||||||
		u_int8_t rtp_payload;
 | 
					 | 
				
			||||||
		u_int8_t rtp_payload2;
 | 
							u_int8_t rtp_payload2;
 | 
				
			||||||
		u_int8_t speech_mode;
 | 
							u_int8_t speech_mode;
 | 
				
			||||||
		struct rtp_socket *rtp_socket;
 | 
							struct rtp_socket *rtp_socket;
 | 
				
			||||||
	} abis_ip;
 | 
						} abis_ip;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct gsm_subscriber_connection conn;
 | 
						struct gsm_subscriber_connection conn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* release reason */
 | 
				
			||||||
 | 
						u_int8_t release_reason;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct gsm_e1_subslot {
 | 
					struct gsm_e1_subslot {
 | 
				
			||||||
@@ -378,6 +403,10 @@ struct gsm_bts_paging_state {
 | 
				
			|||||||
	struct gsm_bts *bts;
 | 
						struct gsm_bts *bts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct timer_list work_timer;
 | 
						struct timer_list work_timer;
 | 
				
			||||||
 | 
						struct timer_list credit_timer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* free chans needed */
 | 
				
			||||||
 | 
						int free_chans_need;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* load */
 | 
						/* load */
 | 
				
			||||||
	u_int16_t available_slots;
 | 
						u_int16_t available_slots;
 | 
				
			||||||
@@ -494,6 +523,10 @@ struct gsm_bts {
 | 
				
			|||||||
		struct gsm_bts_gprs_nsvc nsvc[2];
 | 
							struct gsm_bts_gprs_nsvc nsvc[2];
 | 
				
			||||||
		u_int8_t rac;
 | 
							u_int8_t rac;
 | 
				
			||||||
	} gprs;
 | 
						} gprs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* RACH NM values */
 | 
				
			||||||
 | 
						int rach_b_thresh;
 | 
				
			||||||
 | 
						int rach_ldavg_slots;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/* transceivers */
 | 
						/* transceivers */
 | 
				
			||||||
	int num_trx;
 | 
						int num_trx;
 | 
				
			||||||
@@ -560,6 +593,14 @@ enum gsm_auth_policy {
 | 
				
			|||||||
#define GSM_T3101_DEFAULT 10
 | 
					#define GSM_T3101_DEFAULT 10
 | 
				
			||||||
#define GSM_T3113_DEFAULT 60
 | 
					#define GSM_T3113_DEFAULT 60
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * internal data for audio management
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct gsm_audio_support {
 | 
				
			||||||
 | 
						u_int8_t hr  : 1,
 | 
				
			||||||
 | 
							 ver : 7;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct gsm_network {
 | 
					struct gsm_network {
 | 
				
			||||||
	/* global parameters */
 | 
						/* global parameters */
 | 
				
			||||||
	u_int16_t country_code;
 | 
						u_int16_t country_code;
 | 
				
			||||||
@@ -590,6 +631,11 @@ struct gsm_network {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	struct gsmnet_stats stats;
 | 
						struct gsmnet_stats stats;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct gsm_audio_support **audio_support;
 | 
				
			||||||
 | 
						int audio_length;
 | 
				
			||||||
 | 
						int rtp_payload;
 | 
				
			||||||
 | 
						int rtp_base_port;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* layer 4 */
 | 
						/* layer 4 */
 | 
				
			||||||
	int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
 | 
						int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
 | 
				
			||||||
	struct llist_head upqueue;
 | 
						struct llist_head upqueue;
 | 
				
			||||||
@@ -615,6 +661,23 @@ struct gsm_network {
 | 
				
			|||||||
	struct {
 | 
						struct {
 | 
				
			||||||
		enum rrlp_mode mode;
 | 
							enum rrlp_mode mode;
 | 
				
			||||||
	} rrlp;
 | 
						} rrlp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						enum gsm_chan_t ctype_by_chreq[16];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Use a TCH for handling requests of type paging any */
 | 
				
			||||||
 | 
						int pag_any_tch;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* a hack for On Waves. It must be signed */
 | 
				
			||||||
 | 
						int32_t core_country_code;
 | 
				
			||||||
 | 
						int32_t core_network_code;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* a simple token for this network... */
 | 
				
			||||||
 | 
						char *bsc_token;
 | 
				
			||||||
 | 
						char *msc_ip;
 | 
				
			||||||
 | 
						int msc_port;
 | 
				
			||||||
 | 
						struct bsc_msc_connection *msc_con;
 | 
				
			||||||
 | 
						int ping_timeout;
 | 
				
			||||||
 | 
						int pong_timeout;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SMS_HDR_SIZE	128
 | 
					#define SMS_HDR_SIZE	128
 | 
				
			||||||
@@ -716,14 +779,6 @@ const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
 | 
					void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* A parsed GPRS routing area */
 | 
					 | 
				
			||||||
struct gprs_ra_id {
 | 
					 | 
				
			||||||
	u_int16_t	mnc;
 | 
					 | 
				
			||||||
	u_int16_t	mcc;
 | 
					 | 
				
			||||||
	u_int16_t	lac;
 | 
					 | 
				
			||||||
	u_int8_t	rac;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int gsm48_ra_id_by_bts(u_int8_t *buf, struct gsm_bts *bts);
 | 
					int gsm48_ra_id_by_bts(u_int8_t *buf, struct gsm_bts *bts);
 | 
				
			||||||
void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
 | 
					void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
 | 
				
			||||||
struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
 | 
					struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -81,6 +81,8 @@ struct gsm_subscriber *subscr_get_by_extension(struct gsm_network *net,
 | 
				
			|||||||
					       const char *ext);
 | 
										       const char *ext);
 | 
				
			||||||
struct gsm_subscriber *subscr_get_by_id(struct gsm_network *net,
 | 
					struct gsm_subscriber *subscr_get_by_id(struct gsm_network *net,
 | 
				
			||||||
					unsigned long long id);
 | 
										unsigned long long id);
 | 
				
			||||||
 | 
					struct gsm_subscriber *subscr_get_or_create(struct gsm_network *net,
 | 
				
			||||||
 | 
										    const char *imsi);
 | 
				
			||||||
int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts, int reason);
 | 
					int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts, int reason);
 | 
				
			||||||
void subscr_put_channel(struct gsm_lchan *lchan);
 | 
					void subscr_put_channel(struct gsm_lchan *lchan);
 | 
				
			||||||
void subscr_get_channel(struct gsm_subscriber *subscr,
 | 
					void subscr_get_channel(struct gsm_subscriber *subscr,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,6 @@
 | 
				
			|||||||
#include <arpa/inet.h>
 | 
					#include <arpa/inet.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define RTP_PORT_DEFAULT 4000
 | 
					#define RTP_PORT_DEFAULT 4000
 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Calculate the RTP audio port for the given multiplex
 | 
					 * Calculate the RTP audio port for the given multiplex
 | 
				
			||||||
 * and the direction. This allows a semi static endpoint
 | 
					 * and the direction. This allows a semi static endpoint
 | 
				
			||||||
@@ -80,13 +79,14 @@ typedef int (*mgcp_policy)(struct mgcp_config *cfg, int endpoint, int state, con
 | 
				
			|||||||
typedef int (*mgcp_reset)(struct mgcp_config *cfg);
 | 
					typedef int (*mgcp_reset)(struct mgcp_config *cfg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct mgcp_config {
 | 
					struct mgcp_config {
 | 
				
			||||||
 | 
						/* common configuration */
 | 
				
			||||||
	int source_port;
 | 
						int source_port;
 | 
				
			||||||
	char *local_ip;
 | 
						char *local_ip;
 | 
				
			||||||
	char *source_addr;
 | 
						char *source_addr;
 | 
				
			||||||
	unsigned int number_endpoints;
 | 
					 | 
				
			||||||
	char *bts_ip;
 | 
						char *bts_ip;
 | 
				
			||||||
	char *call_agent_addr;
 | 
						char *call_agent_addr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* default endpoint data */
 | 
				
			||||||
	struct in_addr bts_in;
 | 
						struct in_addr bts_in;
 | 
				
			||||||
	char *audio_name;
 | 
						char *audio_name;
 | 
				
			||||||
	int audio_payload;
 | 
						int audio_payload;
 | 
				
			||||||
@@ -94,19 +94,24 @@ struct mgcp_config {
 | 
				
			|||||||
	int early_bind;
 | 
						int early_bind;
 | 
				
			||||||
	int rtp_base_port;
 | 
						int rtp_base_port;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* only used in forward mode */
 | 
				
			||||||
	char *forward_ip;
 | 
						char *forward_ip;
 | 
				
			||||||
	int forward_port;
 | 
						int forward_port;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						unsigned int last_call_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* endpoint configuration */
 | 
				
			||||||
 | 
						unsigned int number_endpoints;
 | 
				
			||||||
 | 
						struct mgcp_endpoint *endpoints;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* spec handling */
 | 
						/* spec handling */
 | 
				
			||||||
	int force_realloc;
 | 
						int force_realloc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* callback functionality */
 | 
				
			||||||
	mgcp_change change_cb;
 | 
						mgcp_change change_cb;
 | 
				
			||||||
	mgcp_policy policy_cb;
 | 
						mgcp_policy policy_cb;
 | 
				
			||||||
	mgcp_reset reset_cb;
 | 
						mgcp_reset reset_cb;
 | 
				
			||||||
	void *data;
 | 
						void *data;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	struct mgcp_endpoint *endpoints;
 | 
					 | 
				
			||||||
	unsigned int last_call_id;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* config management */
 | 
					/* config management */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,5 +73,6 @@ struct mgcp_msg_ptr {
 | 
				
			|||||||
int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg,
 | 
					int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg,
 | 
				
			||||||
			struct mgcp_msg_ptr *ptr, int size,
 | 
								struct mgcp_msg_ptr *ptr, int size,
 | 
				
			||||||
			const char **transaction_id, struct mgcp_endpoint **endp);
 | 
								const char **transaction_id, struct mgcp_endpoint **endp);
 | 
				
			||||||
 | 
					int mgcp_send_dummy(struct mgcp_endpoint *endp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,4 +43,7 @@ void paging_request_stop(struct gsm_bts *bts, struct gsm_subscriber *subscr,
 | 
				
			|||||||
/* update paging load */
 | 
					/* update paging load */
 | 
				
			||||||
void paging_update_buffer_space(struct gsm_bts *bts, u_int16_t);
 | 
					void paging_update_buffer_space(struct gsm_bts *bts, u_int16_t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* pending paging requests */
 | 
				
			||||||
 | 
					unsigned int paging_pending_requests_nr(struct gsm_bts *bts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,12 +28,6 @@
 | 
				
			|||||||
#include <osmocore/linuxlist.h>
 | 
					#include <osmocore/linuxlist.h>
 | 
				
			||||||
#include <osmocore/select.h>
 | 
					#include <osmocore/select.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define RTP_PT_GSM_FULL 3
 | 
					 | 
				
			||||||
#define RTP_PT_GSM_HALF 96
 | 
					 | 
				
			||||||
#define RTP_PT_GSM_EFR 97
 | 
					 | 
				
			||||||
#define RTP_PT_AMR_FULL 98
 | 
					 | 
				
			||||||
#define RTP_PT_AMR_HALF 99
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
enum rtp_rx_action {
 | 
					enum rtp_rx_action {
 | 
				
			||||||
	RTP_NONE,
 | 
						RTP_NONE,
 | 
				
			||||||
	RTP_PROXY,
 | 
						RTP_PROXY,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -411,4 +411,10 @@ struct sccp_data_it {
 | 
				
			|||||||
	u_int8_t			credit;
 | 
						u_int8_t			credit;
 | 
				
			||||||
} __attribute__((packed));
 | 
					} __attribute__((packed));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct sccp_proto_err {
 | 
				
			||||||
 | 
						u_int8_t			type;
 | 
				
			||||||
 | 
						struct sccp_source_reference	destination_local_reference;
 | 
				
			||||||
 | 
						u_int8_t			error_cause;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,7 +28,7 @@
 | 
				
			|||||||
/* Create a new buffer.  Memory will be allocated in chunks of the given
 | 
					/* Create a new buffer.  Memory will be allocated in chunks of the given
 | 
				
			||||||
   size.  If the argument is 0, the library will supply a reasonable
 | 
					   size.  If the argument is 0, the library will supply a reasonable
 | 
				
			||||||
   default size suitable for buffering socket I/O. */
 | 
					   default size suitable for buffering socket I/O. */
 | 
				
			||||||
struct buffer *buffer_new(size_t);
 | 
					struct buffer *buffer_new(void *ctx, size_t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Free all data in the buffer. */
 | 
					/* Free all data in the buffer. */
 | 
				
			||||||
void buffer_reset(struct buffer *);
 | 
					void buffer_reset(struct buffer *);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -107,6 +107,8 @@ enum node_type {
 | 
				
			|||||||
	TS_NODE,
 | 
						TS_NODE,
 | 
				
			||||||
	SUBSCR_NODE,
 | 
						SUBSCR_NODE,
 | 
				
			||||||
	MGCP_NODE,
 | 
						MGCP_NODE,
 | 
				
			||||||
 | 
						NAT_NODE,
 | 
				
			||||||
 | 
						BSC_NODE,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Node which has some commands and prompt string and configuration
 | 
					/* Node which has some commands and prompt string and configuration
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,8 @@ AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS)
 | 
				
			|||||||
AM_LDFLAGS = $(LIBOSMOCORE_LIBS)
 | 
					AM_LDFLAGS = $(LIBOSMOCORE_LIBS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sbin_PROGRAMS = bsc_hack bs11_config ipaccess-find ipaccess-config \
 | 
					sbin_PROGRAMS = bsc_hack bs11_config ipaccess-find ipaccess-config \
 | 
				
			||||||
                isdnsync bsc_mgcp ipaccess-proxy
 | 
					                isdnsync bsc_mgcp ipaccess-proxy \
 | 
				
			||||||
 | 
					                bsc_msc_ip bsc_nat
 | 
				
			||||||
noinst_LIBRARIES = libbsc.a libmsc.a libvty.a
 | 
					noinst_LIBRARIES = libbsc.a libmsc.a libvty.a
 | 
				
			||||||
noinst_HEADERS = vty/cardshell.h
 | 
					noinst_HEADERS = vty/cardshell.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -17,12 +18,12 @@ libbsc_a_SOURCES = abis_rsl.c abis_nm.c gsm_data.c gsm_04_08_utils.c \
 | 
				
			|||||||
		input/misdn.c input/ipaccess.c \
 | 
							input/misdn.c input/ipaccess.c \
 | 
				
			||||||
		talloc_ctx.c system_information.c rest_octets.c \
 | 
							talloc_ctx.c system_information.c rest_octets.c \
 | 
				
			||||||
		rtp_proxy.c bts_siemens_bs11.c bts_ipaccess_nanobts.c \
 | 
							rtp_proxy.c bts_siemens_bs11.c bts_ipaccess_nanobts.c \
 | 
				
			||||||
		bts_unknown.c bsc_version.c bsc_api.c vty_interface_cmds.c
 | 
							bts_unknown.c meas_rep.c telnet_interface.c bsc_version.c bsc_api.c vty_interface_cmds.c 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
libmsc_a_SOURCES = gsm_subscriber.c db.c telnet_interface.c \
 | 
					libmsc_a_SOURCES = gsm_subscriber.c db.c \
 | 
				
			||||||
		mncc.c gsm_04_08.c gsm_04_11.c transaction.c \
 | 
							mncc.c gsm_04_08.c gsm_04_11.c transaction.c \
 | 
				
			||||||
		token_auth.c rrlp.c gsm_04_80.c ussd.c silent_call.c \
 | 
							token_auth.c rrlp.c gsm_04_80.c ussd.c silent_call.c \
 | 
				
			||||||
		handover_logic.c handover_decision.c meas_rep.c
 | 
							handover_logic.c handover_decision.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
libvty_a_SOURCES = vty/buffer.c vty/command.c vty/vector.c vty/vty.c
 | 
					libvty_a_SOURCES = vty/buffer.c vty/command.c vty/vector.c vty/vty.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -33,6 +34,10 @@ bsc_hack_LDADD = libmsc.a libbsc.a libmsc.a libvty.a -ldl -ldbi $(LIBCRYPT)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bs11_config_SOURCES = bs11_config.c abis_nm.c gsm_data.c debug.c \
 | 
					bs11_config_SOURCES = bs11_config.c abis_nm.c gsm_data.c debug.c \
 | 
				
			||||||
		      rs232.c bts_siemens_bs11.c
 | 
							      rs232.c bts_siemens_bs11.c
 | 
				
			||||||
 | 
					bsc_msc_ip_SOURCES = bssap.c bsc_msc_ip.c bsc_init.c vty_interface.c vty_interface_bsc.c \
 | 
				
			||||||
 | 
							bsc_msc.c bsc_msc_rf.c
 | 
				
			||||||
 | 
					bsc_msc_ip_LDADD = libbsc.a libvty.a libsccp.a
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ipaccess_find_SOURCES = ipaccess/ipaccess-find.c
 | 
					ipaccess_find_SOURCES = ipaccess/ipaccess-find.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -46,3 +51,9 @@ bsc_mgcp_SOURCES = mgcp/mgcp_main.c mgcp/mgcp_protocol.c mgcp/mgcp_network.c mgc
 | 
				
			|||||||
bsc_mgcp_LDADD = libvty.a
 | 
					bsc_mgcp_LDADD = libvty.a
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ipaccess_proxy_SOURCES = ipaccess/ipaccess-proxy.c debug.c
 | 
					ipaccess_proxy_SOURCES = ipaccess/ipaccess-proxy.c debug.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bsc_nat_SOURCES = nat/bsc_nat.c nat/bsc_filter.c nat/bsc_sccp.c \
 | 
				
			||||||
 | 
							  nat/bsc_nat_utils.c nat/bsc_nat_vty.c nat/bsc_mgcp_utils.c \
 | 
				
			||||||
 | 
							  mgcp/mgcp_protocol.c mgcp/mgcp_network.c mgcp/mgcp_vty.c \
 | 
				
			||||||
 | 
							  bsc_msc.c bssap.c
 | 
				
			||||||
 | 
					bsc_nat_LDADD = libvty.a libbsc.a libsccp.a
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -568,12 +568,33 @@ int rsl_deact_sacch(struct gsm_lchan *lchan)
 | 
				
			|||||||
	return abis_rsl_sendmsg(msg);
 | 
						return abis_rsl_sendmsg(msg);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void error_timeout_cb(void *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct gsm_lchan *lchan = data;
 | 
				
			||||||
 | 
						if (lchan->state != LCHAN_S_REL_ERR) {
 | 
				
			||||||
 | 
							LOGP(DRSL, LOGL_ERROR, "%s error timeout but not in error state: %d\n",
 | 
				
			||||||
 | 
							     gsm_lchan_name(lchan), lchan->state);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* go back to the none state */
 | 
				
			||||||
 | 
						LOGP(DRSL, LOGL_NOTICE, "%s is back in operation.\n", gsm_lchan_name(lchan));
 | 
				
			||||||
 | 
						rsl_lchan_set_state(lchan, LCHAN_S_NONE);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Chapter 8.4.14 / 4.7: Tell BTS to release the radio channel */
 | 
					/* Chapter 8.4.14 / 4.7: Tell BTS to release the radio channel */
 | 
				
			||||||
int rsl_rf_chan_release(struct gsm_lchan *lchan)
 | 
					static int rsl_rf_chan_release(struct gsm_lchan *lchan, int error)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct abis_rsl_dchan_hdr *dh;
 | 
						struct abis_rsl_dchan_hdr *dh;
 | 
				
			||||||
	struct msgb *msg = rsl_msgb_alloc();
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (lchan->state == LCHAN_S_REL_ERR) {
 | 
				
			||||||
 | 
							LOGP(DRSL, LOGL_NOTICE, "%s is in error state not sending release.\n",
 | 
				
			||||||
 | 
							     gsm_lchan_name(lchan));
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg = rsl_msgb_alloc();
 | 
				
			||||||
	dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
 | 
						dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
 | 
				
			||||||
	init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL);
 | 
						init_dchan_hdr(dh, RSL_MT_RF_CHAN_REL);
 | 
				
			||||||
	dh->chan_nr = lchan2chan_nr(lchan);
 | 
						dh->chan_nr = lchan2chan_nr(lchan);
 | 
				
			||||||
@@ -581,7 +602,20 @@ int rsl_rf_chan_release(struct gsm_lchan *lchan)
 | 
				
			|||||||
	msg->lchan = lchan;
 | 
						msg->lchan = lchan;
 | 
				
			||||||
	msg->trx = lchan->ts->trx;
 | 
						msg->trx = lchan->ts->trx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DEBUGP(DRSL, "%s RF Channel Release CMD\n", gsm_lchan_name(lchan));
 | 
						DEBUGP(DRSL, "%s RF Channel Release CMD due error %d\n", gsm_lchan_name(lchan), error);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (error) {
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * the nanoBTS sends RLL release indications after the channel release. This can
 | 
				
			||||||
 | 
							 * be a problem when we have reassigned the channel to someone else and then can
 | 
				
			||||||
 | 
							 * not figure out who used this channel.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							rsl_lchan_set_state(lchan, LCHAN_S_REL_ERR);
 | 
				
			||||||
 | 
							lchan->error_timer.data = lchan;
 | 
				
			||||||
 | 
							lchan->error_timer.cb = error_timeout_cb;
 | 
				
			||||||
 | 
							bsc_schedule_timer(&lchan->error_timer,
 | 
				
			||||||
 | 
									   msg->trx->bts->network->T3111 + 2, 0);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* BTS will respond by RF CHAN REL ACK */
 | 
						/* BTS will respond by RF CHAN REL ACK */
 | 
				
			||||||
	return abis_rsl_sendmsg(msg);
 | 
						return abis_rsl_sendmsg(msg);
 | 
				
			||||||
@@ -718,14 +752,15 @@ int rsl_establish_request(struct gsm_lchan *lchan, u_int8_t link_id)
 | 
				
			|||||||
   RELEASE CONFIRM, which we in turn use to trigger RSL CHANNEL RELEASE,
 | 
					   RELEASE CONFIRM, which we in turn use to trigger RSL CHANNEL RELEASE,
 | 
				
			||||||
   which in turn is acknowledged by RSL CHANNEL RELEASE ACK, which calls
 | 
					   which in turn is acknowledged by RSL CHANNEL RELEASE ACK, which calls
 | 
				
			||||||
   lchan_free() */
 | 
					   lchan_free() */
 | 
				
			||||||
int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id)
 | 
					int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id, u_int8_t reason)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct msgb *msg;
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	msg = rsl_rll_simple(RSL_MT_REL_REQ, lchan2chan_nr(lchan),
 | 
						msg = rsl_rll_simple(RSL_MT_REL_REQ, lchan2chan_nr(lchan),
 | 
				
			||||||
			     link_id, 0);
 | 
								     link_id, 0);
 | 
				
			||||||
	msgb_tv_put(msg, RSL_IE_RELEASE_MODE, 0);	/* normal release */
 | 
					        /* 0 is normal release, 1 is local end */
 | 
				
			||||||
 | 
						msgb_tv_put(msg, RSL_IE_RELEASE_MODE, reason);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* FIXME: start some timer in case we don't receive a REL ACK ? */
 | 
						/* FIXME: start some timer in case we don't receive a REL ACK ? */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -811,7 +846,7 @@ static int rsl_rx_conn_fail(struct msgb *msg)
 | 
				
			|||||||
	LOGPC(DRSL, LOGL_NOTICE, "\n");
 | 
						LOGPC(DRSL, LOGL_NOTICE, "\n");
 | 
				
			||||||
	/* FIXME: only free it after channel release ACK */
 | 
						/* FIXME: only free it after channel release ACK */
 | 
				
			||||||
	counter_inc(msg->lchan->ts->trx->bts->network->stats.chan.rf_fail);
 | 
						counter_inc(msg->lchan->ts->trx->bts->network->stats.chan.rf_fail);
 | 
				
			||||||
	return rsl_rf_chan_release(msg->lchan);
 | 
						return rsl_rf_chan_release(msg->lchan, 1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void print_meas_rep_uni(struct gsm_meas_rep_unidir *mru,
 | 
					static void print_meas_rep_uni(struct gsm_meas_rep_unidir *mru,
 | 
				
			||||||
@@ -983,11 +1018,14 @@ static int abis_rsl_rx_dchan(struct msgb *msg)
 | 
				
			|||||||
		break;
 | 
							break;
 | 
				
			||||||
	case RSL_MT_RF_CHAN_REL_ACK:
 | 
						case RSL_MT_RF_CHAN_REL_ACK:
 | 
				
			||||||
		DEBUGP(DRSL, "%s RF CHANNEL RELEASE ACK\n", ts_name);
 | 
							DEBUGP(DRSL, "%s RF CHANNEL RELEASE ACK\n", ts_name);
 | 
				
			||||||
		if (msg->lchan->state != LCHAN_S_REL_REQ)
 | 
							if (msg->lchan->state != LCHAN_S_REL_REQ && msg->lchan->state != LCHAN_S_REL_ERR)
 | 
				
			||||||
			LOGP(DRSL, LOGL_NOTICE, "%s CHAN REL ACK but state %s\n",
 | 
								LOGP(DRSL, LOGL_NOTICE, "%s CHAN REL ACK but state %s\n",
 | 
				
			||||||
				gsm_lchan_name(msg->lchan),
 | 
									gsm_lchan_name(msg->lchan),
 | 
				
			||||||
				gsm_lchans_name(msg->lchan->state));
 | 
									gsm_lchans_name(msg->lchan->state));
 | 
				
			||||||
		rsl_lchan_set_state(msg->lchan, LCHAN_S_NONE);
 | 
							bsc_del_timer(&msg->lchan->T3111);
 | 
				
			||||||
 | 
							/* we have an error timer pending to release that */
 | 
				
			||||||
 | 
							if (msg->lchan->state != LCHAN_S_REL_ERR)
 | 
				
			||||||
 | 
								rsl_lchan_set_state(msg->lchan, LCHAN_S_NONE);
 | 
				
			||||||
		lchan_free(msg->lchan);
 | 
							lchan_free(msg->lchan);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case RSL_MT_MODE_MODIFY_ACK:
 | 
						case RSL_MT_MODE_MODIFY_ACK:
 | 
				
			||||||
@@ -1079,7 +1117,15 @@ static void t3101_expired(void *data)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	struct gsm_lchan *lchan = data;
 | 
						struct gsm_lchan *lchan = data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rsl_rf_chan_release(lchan);
 | 
						rsl_rf_chan_release(lchan, 1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* If T3111 expires, we will send the RF Channel Request */
 | 
				
			||||||
 | 
					static void t3111_expired(void *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct gsm_lchan *lchan = data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rsl_rf_chan_release(lchan, 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* MS has requested a channel on the RACH */
 | 
					/* MS has requested a channel on the RACH */
 | 
				
			||||||
@@ -1094,6 +1140,7 @@ static int rsl_rx_chan_rqd(struct msgb *msg)
 | 
				
			|||||||
	struct gsm_lchan *lchan;
 | 
						struct gsm_lchan *lchan;
 | 
				
			||||||
	u_int8_t rqd_ta;
 | 
						u_int8_t rqd_ta;
 | 
				
			||||||
	int ret;
 | 
						int ret;
 | 
				
			||||||
 | 
						int is_lu;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	u_int16_t arfcn;
 | 
						u_int16_t arfcn;
 | 
				
			||||||
	u_int8_t ts_number, subch;
 | 
						u_int8_t ts_number, subch;
 | 
				
			||||||
@@ -1111,13 +1158,19 @@ static int rsl_rx_chan_rqd(struct msgb *msg)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* determine channel type (SDCCH/TCH_F/TCH_H) based on
 | 
						/* determine channel type (SDCCH/TCH_F/TCH_H) based on
 | 
				
			||||||
	 * request reference RA */
 | 
						 * request reference RA */
 | 
				
			||||||
	lctype = get_ctype_by_chreq(bts, rqd_ref->ra, bts->network->neci);
 | 
						lctype = get_ctype_by_chreq(bts->network, rqd_ref->ra);
 | 
				
			||||||
	chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra, bts->network->neci);
 | 
						chreq_reason = get_reason_by_chreq(rqd_ref->ra, bts->network->neci);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	counter_inc(bts->network->stats.chreq.total);
 | 
						counter_inc(bts->network->stats.chreq.total);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * We want LOCATION UPDATES to succeed and will assign a TCH
 | 
				
			||||||
 | 
						 * if we have no SDCCH available.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						is_lu = !!(chreq_reason == GSM_CHREQ_REASON_LOCATION_UPD);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* check availability / allocate channel */
 | 
						/* check availability / allocate channel */
 | 
				
			||||||
	lchan = lchan_alloc(bts, lctype);
 | 
						lchan = lchan_alloc(bts, lctype, is_lu);
 | 
				
			||||||
	if (!lchan) {
 | 
						if (!lchan) {
 | 
				
			||||||
		LOGP(DRSL, LOGL_NOTICE, "BTS %d CHAN RQD: no resources for %s 0x%x\n",
 | 
							LOGP(DRSL, LOGL_NOTICE, "BTS %d CHAN RQD: no resources for %s 0x%x\n",
 | 
				
			||||||
		     msg->lchan->ts->trx->bts->nr, gsm_lchant_name(lctype), rqd_ref->ra);
 | 
							     msg->lchan->ts->trx->bts->nr, gsm_lchant_name(lctype), rqd_ref->ra);
 | 
				
			||||||
@@ -1252,12 +1305,38 @@ static int rsl_rx_rll_err_ind(struct msgb *msg)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (rlm_cause[1] == RLL_CAUSE_T200_EXPIRED) {
 | 
						if (rlm_cause[1] == RLL_CAUSE_T200_EXPIRED) {
 | 
				
			||||||
		counter_inc(msg->lchan->ts->trx->bts->network->stats.chan.rll_err);
 | 
							counter_inc(msg->lchan->ts->trx->bts->network->stats.chan.rll_err);
 | 
				
			||||||
		return rsl_rf_chan_release(msg->lchan);
 | 
							return rsl_rf_chan_release(msg->lchan, 1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void rsl_handle_release(struct gsm_lchan *lchan)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int sapi;
 | 
				
			||||||
 | 
						struct gsm_bts *bts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* maybe we have only brought down one RLL */
 | 
				
			||||||
 | 
						if (lchan->state != LCHAN_S_REL_REQ)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (sapi = 0; sapi < ARRAY_SIZE(lchan->sapis); ++sapi) {
 | 
				
			||||||
 | 
							if (lchan->sapis[sapi] == LCHAN_SAPI_UNUSED)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							LOGP(DRSL, LOGL_NOTICE, "%s waiting for SAPI=%d to be released.\n",
 | 
				
			||||||
 | 
							     gsm_lchan_name(lchan), sapi);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* wait a bit to send the RF Channel Release */
 | 
				
			||||||
 | 
						lchan->T3111.cb = t3111_expired;
 | 
				
			||||||
 | 
						lchan->T3111.data = lchan;
 | 
				
			||||||
 | 
						bts = lchan->ts->trx->bts;
 | 
				
			||||||
 | 
						bsc_schedule_timer(&lchan->T3111, bts->network->T3111, 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*	ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST
 | 
					/*	ESTABLISH INDICATION, LOCATION AREA UPDATE REQUEST
 | 
				
			||||||
	0x02, 0x06,
 | 
						0x02, 0x06,
 | 
				
			||||||
	0x01, 0x20,
 | 
						0x01, 0x20,
 | 
				
			||||||
@@ -1309,20 +1388,16 @@ static int abis_rsl_rx_rll(struct msgb *msg)
 | 
				
			|||||||
		msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
 | 
							msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
 | 
				
			||||||
		rll_indication(msg->lchan, rllh->link_id,
 | 
							rll_indication(msg->lchan, rllh->link_id,
 | 
				
			||||||
				  BSC_RLLR_IND_REL_IND);
 | 
									  BSC_RLLR_IND_REL_IND);
 | 
				
			||||||
		/* we can now releae the channel on the BTS/Abis side */
 | 
							rsl_handle_release(msg->lchan);
 | 
				
			||||||
		/* FIXME: officially we need to start T3111 and wait for
 | 
							rsl_lchan_rll_release(msg->lchan, rllh->link_id);
 | 
				
			||||||
		 * some grace period */
 | 
					 | 
				
			||||||
		rsl_rf_chan_release(msg->lchan);
 | 
					 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case RSL_MT_REL_CONF:
 | 
						case RSL_MT_REL_CONF:
 | 
				
			||||||
		/* BTS informs us of having received UA from MS,
 | 
							/* BTS informs us of having received UA from MS,
 | 
				
			||||||
		 * in response to DISC that we've sent earlier */
 | 
							 * in response to DISC that we've sent earlier */
 | 
				
			||||||
		DEBUGPC(DRLL, "RELEASE CONFIRMATION\n");
 | 
							DEBUGPC(DRLL, "RELEASE CONFIRMATION\n");
 | 
				
			||||||
		msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
 | 
							msg->lchan->sapis[rllh->link_id & 0x7] = LCHAN_SAPI_UNUSED;
 | 
				
			||||||
		/* we can now releae the channel on the BTS/Abis side */
 | 
							rsl_handle_release(msg->lchan);
 | 
				
			||||||
		/* FIXME: officially we need to start T3111 and wait for
 | 
							rsl_lchan_rll_release(msg->lchan, rllh->link_id);
 | 
				
			||||||
		 * some grace period */
 | 
					 | 
				
			||||||
		rsl_rf_chan_release(msg->lchan);
 | 
					 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case RSL_MT_ERROR_IND:
 | 
						case RSL_MT_ERROR_IND:
 | 
				
			||||||
		rc = rsl_rx_rll_err_ind(msg);
 | 
							rc = rsl_rx_rll_err_ind(msg);
 | 
				
			||||||
@@ -1342,31 +1417,11 @@ static u_int8_t ipa_smod_s_for_lchan(struct gsm_lchan *lchan)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	switch (lchan->tch_mode) {
 | 
						switch (lchan->tch_mode) {
 | 
				
			||||||
	case GSM48_CMODE_SPEECH_V1:
 | 
						case GSM48_CMODE_SPEECH_V1:
 | 
				
			||||||
		switch (lchan->type) {
 | 
							return 0x00;
 | 
				
			||||||
		case GSM_LCHAN_TCH_F:
 | 
					 | 
				
			||||||
			return 0x00;
 | 
					 | 
				
			||||||
		case GSM_LCHAN_TCH_H:
 | 
					 | 
				
			||||||
			return 0x03;
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	case GSM48_CMODE_SPEECH_EFR:
 | 
						case GSM48_CMODE_SPEECH_EFR:
 | 
				
			||||||
		switch (lchan->type) {
 | 
							return 0x01;
 | 
				
			||||||
		case GSM_LCHAN_TCH_F:
 | 
					 | 
				
			||||||
			return 0x01;
 | 
					 | 
				
			||||||
		/* there's no half-rate EFR */
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	case GSM48_CMODE_SPEECH_AMR:
 | 
						case GSM48_CMODE_SPEECH_AMR:
 | 
				
			||||||
		switch (lchan->type) {
 | 
							return 0x02;
 | 
				
			||||||
		case GSM_LCHAN_TCH_F:
 | 
					 | 
				
			||||||
			return 0x02;
 | 
					 | 
				
			||||||
		case GSM_LCHAN_TCH_H:
 | 
					 | 
				
			||||||
			return 0x05;
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1375,44 +1430,6 @@ static u_int8_t ipa_smod_s_for_lchan(struct gsm_lchan *lchan)
 | 
				
			|||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static u_int8_t ipa_rtp_pt_for_lchan(struct gsm_lchan *lchan)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	switch (lchan->tch_mode) {
 | 
					 | 
				
			||||||
	case GSM48_CMODE_SPEECH_V1:
 | 
					 | 
				
			||||||
		switch (lchan->type) {
 | 
					 | 
				
			||||||
		case GSM_LCHAN_TCH_F:
 | 
					 | 
				
			||||||
			return RTP_PT_GSM_FULL;
 | 
					 | 
				
			||||||
		case GSM_LCHAN_TCH_H:
 | 
					 | 
				
			||||||
			return RTP_PT_GSM_HALF;
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	case GSM48_CMODE_SPEECH_EFR:
 | 
					 | 
				
			||||||
		switch (lchan->type) {
 | 
					 | 
				
			||||||
		case GSM_LCHAN_TCH_F:
 | 
					 | 
				
			||||||
			return RTP_PT_GSM_EFR;
 | 
					 | 
				
			||||||
		/* there's no half-rate EFR */
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	case GSM48_CMODE_SPEECH_AMR:
 | 
					 | 
				
			||||||
		switch (lchan->type) {
 | 
					 | 
				
			||||||
		case GSM_LCHAN_TCH_F:
 | 
					 | 
				
			||||||
			return RTP_PT_AMR_FULL;
 | 
					 | 
				
			||||||
		case GSM_LCHAN_TCH_H:
 | 
					 | 
				
			||||||
			return RTP_PT_AMR_HALF;
 | 
					 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	LOGP(DRSL, LOGL_ERROR, "Cannot determine ip.access rtp payload type for "
 | 
					 | 
				
			||||||
		"tch_mode == 0x%02x\n & lchan_type == %d",
 | 
					 | 
				
			||||||
		lchan->tch_mode, lchan->type);
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* ip.access specific RSL extensions */
 | 
					/* ip.access specific RSL extensions */
 | 
				
			||||||
static void ipac_parse_rtp(struct gsm_lchan *lchan, struct tlv_parsed *tv)
 | 
					static void ipac_parse_rtp(struct gsm_lchan *lchan, struct tlv_parsed *tv)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -1479,13 +1496,10 @@ int rsl_ipacc_crcx(struct gsm_lchan *lchan)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* 0x1- == receive-only, 0x-1 == EFR codec */
 | 
						/* 0x1- == receive-only, 0x-1 == EFR codec */
 | 
				
			||||||
	lchan->abis_ip.speech_mode = 0x10 | ipa_smod_s_for_lchan(lchan);
 | 
						lchan->abis_ip.speech_mode = 0x10 | ipa_smod_s_for_lchan(lchan);
 | 
				
			||||||
	lchan->abis_ip.rtp_payload = ipa_rtp_pt_for_lchan(lchan);
 | 
					 | 
				
			||||||
	msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
 | 
						msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
 | 
				
			||||||
	msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD, lchan->abis_ip.rtp_payload);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DEBUGP(DRSL, "%s IPAC_BIND speech_mode=0x%02x RTP_PAYLOAD=%d\n",
 | 
						DEBUGP(DRSL, "%s IPAC_BIND speech_mode=0x%02x\n",
 | 
				
			||||||
		gsm_lchan_name(lchan), lchan->abis_ip.speech_mode,
 | 
							gsm_lchan_name(lchan), lchan->abis_ip.speech_mode);
 | 
				
			||||||
		lchan->abis_ip.rtp_payload);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	msg->trx = lchan->ts->trx;
 | 
						msg->trx = lchan->ts->trx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1512,13 +1526,11 @@ int rsl_ipacc_mdcx(struct gsm_lchan *lchan, u_int32_t ip, u_int16_t port,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* 0x0- == both directions, 0x-1 == EFR codec */
 | 
						/* 0x0- == both directions, 0x-1 == EFR codec */
 | 
				
			||||||
	lchan->abis_ip.speech_mode = 0x00 | ipa_smod_s_for_lchan(lchan);
 | 
						lchan->abis_ip.speech_mode = 0x00 | ipa_smod_s_for_lchan(lchan);
 | 
				
			||||||
	lchan->abis_ip.rtp_payload = ipa_rtp_pt_for_lchan(lchan);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ia.s_addr = htonl(ip);
 | 
						ia.s_addr = htonl(ip);
 | 
				
			||||||
	DEBUGP(DRSL, "%s IPAC_MDCX IP=%s PORT=%d RTP_PAYLOAD=%d RTP_PAYLOAD2=%d "
 | 
						DEBUGP(DRSL, "%s IPAC_MDCX IP=%s PORT=%d RTP_PAYLOAD2=%d CONN_ID=%d "
 | 
				
			||||||
		"CONN_ID=%d speech_mode=0x%02x\n", gsm_lchan_name(lchan),
 | 
							"speech_mode=0x%02x\n", gsm_lchan_name(lchan), inet_ntoa(ia), port,
 | 
				
			||||||
		inet_ntoa(ia), port, lchan->abis_ip.rtp_payload, rtp_payload2,
 | 
							rtp_payload2, lchan->abis_ip.conn_id, lchan->abis_ip.speech_mode);
 | 
				
			||||||
		lchan->abis_ip.conn_id, lchan->abis_ip.speech_mode);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	msgb_tv16_put(msg, RSL_IE_IPAC_CONN_ID, lchan->abis_ip.conn_id);
 | 
						msgb_tv16_put(msg, RSL_IE_IPAC_CONN_ID, lchan->abis_ip.conn_id);
 | 
				
			||||||
	msgb_v_put(msg, RSL_IE_IPAC_REMOTE_IP);
 | 
						msgb_v_put(msg, RSL_IE_IPAC_REMOTE_IP);
 | 
				
			||||||
@@ -1526,7 +1538,6 @@ int rsl_ipacc_mdcx(struct gsm_lchan *lchan, u_int32_t ip, u_int16_t port,
 | 
				
			|||||||
	*att_ip = ia.s_addr;
 | 
						*att_ip = ia.s_addr;
 | 
				
			||||||
	msgb_tv16_put(msg, RSL_IE_IPAC_REMOTE_PORT, port);
 | 
						msgb_tv16_put(msg, RSL_IE_IPAC_REMOTE_PORT, port);
 | 
				
			||||||
	msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
 | 
						msgb_tv_put(msg, RSL_IE_IPAC_SPEECH_MODE, lchan->abis_ip.speech_mode);
 | 
				
			||||||
	msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD, lchan->abis_ip.rtp_payload);
 | 
					 | 
				
			||||||
	if (rtp_payload2)
 | 
						if (rtp_payload2)
 | 
				
			||||||
		msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD2, rtp_payload2);
 | 
							msgb_tv_put(msg, RSL_IE_IPAC_RTP_PAYLOAD2, rtp_payload2);
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -870,3 +870,8 @@ int main(int argc, char **argv)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	exit(0);
 | 
						exit(0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* dummy to be able to compile */
 | 
				
			||||||
 | 
					void gsm_net_update_ctype(struct gsm_network *net)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										25
									
								
								openbsc/src/bsc-nat.cfg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								openbsc/src/bsc-nat.cfg
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					!
 | 
				
			||||||
 | 
					! BSC NAT configuration hand edited
 | 
				
			||||||
 | 
					!   !
 | 
				
			||||||
 | 
					password foo
 | 
				
			||||||
 | 
					!
 | 
				
			||||||
 | 
					line vty
 | 
				
			||||||
 | 
					 no login
 | 
				
			||||||
 | 
					!
 | 
				
			||||||
 | 
					nat
 | 
				
			||||||
 | 
					 msc ip 10.0.0.23
 | 
				
			||||||
 | 
					 bsc 0
 | 
				
			||||||
 | 
					   token zecke
 | 
				
			||||||
 | 
					   location_area_code 3
 | 
				
			||||||
 | 
					 bsc 1
 | 
				
			||||||
 | 
					   token roch
 | 
				
			||||||
 | 
					   location_area_code 4
 | 
				
			||||||
 | 
					mgcp
 | 
				
			||||||
 | 
					  local ip 10.0.0.23
 | 
				
			||||||
 | 
					!  bts ip 0.0.0.0
 | 
				
			||||||
 | 
					  bind ip 127.0.0.1
 | 
				
			||||||
 | 
					  bind port 2427
 | 
				
			||||||
 | 
					  bind early 1
 | 
				
			||||||
 | 
					  rtp base 4000
 | 
				
			||||||
 | 
					  number endpoints 31
 | 
				
			||||||
 | 
					  call agent ip 127.0.0.1
 | 
				
			||||||
@@ -418,9 +418,9 @@ int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
 | 
				
			|||||||
	switch (obj_class) {
 | 
						switch (obj_class) {
 | 
				
			||||||
	case NM_OC_SITE_MANAGER:
 | 
						case NM_OC_SITE_MANAGER:
 | 
				
			||||||
		bts = container_of(obj, struct gsm_bts, site_mgr);
 | 
							bts = container_of(obj, struct gsm_bts, site_mgr);
 | 
				
			||||||
		if ((new_state->operational == 2 &&
 | 
							if ((new_state->operational == NM_OPSTATE_ENABLED &&
 | 
				
			||||||
		     new_state->availability == NM_AVSTATE_OK) ||
 | 
							     new_state->availability == NM_AVSTATE_OK) ||
 | 
				
			||||||
		    (new_state->operational == 1 &&
 | 
							    (new_state->operational == NM_OPSTATE_DISABLED &&
 | 
				
			||||||
		     new_state->availability == NM_AVSTATE_OFF_LINE))
 | 
							     new_state->availability == NM_AVSTATE_OFF_LINE))
 | 
				
			||||||
			abis_nm_opstart(bts, obj_class, 0xff, 0xff, 0xff);
 | 
								abis_nm_opstart(bts, obj_class, 0xff, 0xff, 0xff);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
@@ -440,7 +440,7 @@ int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
 | 
				
			|||||||
	case NM_OC_CHANNEL:
 | 
						case NM_OC_CHANNEL:
 | 
				
			||||||
		ts = obj;
 | 
							ts = obj;
 | 
				
			||||||
		trx = ts->trx;
 | 
							trx = ts->trx;
 | 
				
			||||||
		if (new_state->operational == 1 &&
 | 
							if (new_state->operational == NM_OPSTATE_DISABLED &&
 | 
				
			||||||
		    new_state->availability == NM_AVSTATE_DEPENDENCY) {
 | 
							    new_state->availability == NM_AVSTATE_DEPENDENCY) {
 | 
				
			||||||
			patch_nm_tables(trx->bts);
 | 
								patch_nm_tables(trx->bts);
 | 
				
			||||||
			enum abis_nm_chan_comb ccomb =
 | 
								enum abis_nm_chan_comb ccomb =
 | 
				
			||||||
@@ -455,7 +455,7 @@ int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
 | 
				
			|||||||
		break;
 | 
							break;
 | 
				
			||||||
	case NM_OC_RADIO_CARRIER:
 | 
						case NM_OC_RADIO_CARRIER:
 | 
				
			||||||
		trx = obj;
 | 
							trx = obj;
 | 
				
			||||||
		if (new_state->operational == 1 &&
 | 
							if (new_state->operational == NM_OPSTATE_DISABLED &&
 | 
				
			||||||
		    new_state->availability == NM_AVSTATE_OK)
 | 
							    new_state->availability == NM_AVSTATE_OK)
 | 
				
			||||||
			abis_nm_opstart(trx->bts, obj_class, trx->bts->bts_nr,
 | 
								abis_nm_opstart(trx->bts, obj_class, trx->bts->bts_nr,
 | 
				
			||||||
					trx->nr, 0xff);
 | 
										trx->nr, 0xff);
 | 
				
			||||||
@@ -464,7 +464,7 @@ int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
 | 
				
			|||||||
		bts = container_of(obj, struct gsm_bts, gprs.nse);
 | 
							bts = container_of(obj, struct gsm_bts, gprs.nse);
 | 
				
			||||||
		if (bts->gprs.mode == BTS_GPRS_NONE)
 | 
							if (bts->gprs.mode == BTS_GPRS_NONE)
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		if (new_state->availability == 5) {
 | 
							if (new_state->availability == NM_AVSTATE_DEPENDENCY) {
 | 
				
			||||||
			abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr,
 | 
								abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr,
 | 
				
			||||||
						  0xff, 0xff, nanobts_attr_nse,
 | 
											  0xff, 0xff, nanobts_attr_nse,
 | 
				
			||||||
						  sizeof(nanobts_attr_nse));
 | 
											  sizeof(nanobts_attr_nse));
 | 
				
			||||||
@@ -478,7 +478,7 @@ int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
 | 
				
			|||||||
		bts = container_of(obj, struct gsm_bts, gprs.cell);
 | 
							bts = container_of(obj, struct gsm_bts, gprs.cell);
 | 
				
			||||||
		if (bts->gprs.mode == BTS_GPRS_NONE)
 | 
							if (bts->gprs.mode == BTS_GPRS_NONE)
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		if (new_state->availability == 5) {
 | 
							if (new_state->availability == NM_AVSTATE_DEPENDENCY) {
 | 
				
			||||||
			abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr,
 | 
								abis_nm_ipaccess_set_attr(bts, obj_class, bts->bts_nr,
 | 
				
			||||||
						  0, 0xff, nanobts_attr_cell,
 | 
											  0, 0xff, nanobts_attr_cell,
 | 
				
			||||||
						  sizeof(nanobts_attr_cell));
 | 
											  sizeof(nanobts_attr_cell));
 | 
				
			||||||
@@ -853,6 +853,22 @@ static void patch_nm_tables(struct gsm_bts *bts)
 | 
				
			|||||||
	bs11_attr_radio[2] |= arfcn_high;
 | 
						bs11_attr_radio[2] |= arfcn_high;
 | 
				
			||||||
	bs11_attr_radio[3] = arfcn_low;
 | 
						bs11_attr_radio[3] = arfcn_low;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* patch the RACH attributes */
 | 
				
			||||||
 | 
						if (bts->rach_b_thresh != -1) {
 | 
				
			||||||
 | 
							nanobts_attr_bts[33] = bts->rach_b_thresh & 0xff;
 | 
				
			||||||
 | 
							bs11_attr_bts[33] = bts->rach_b_thresh & 0xff;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bts->rach_ldavg_slots != -1) {
 | 
				
			||||||
 | 
							u_int8_t avg_high = bts->rach_ldavg_slots & 0xff;
 | 
				
			||||||
 | 
							u_int8_t avg_low = (bts->rach_ldavg_slots >> 8) & 0x0f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							nanobts_attr_bts[35] = avg_high;
 | 
				
			||||||
 | 
							nanobts_attr_bts[36] = avg_low;
 | 
				
			||||||
 | 
							bs11_attr_bts[35] = avg_high;
 | 
				
			||||||
 | 
							bs11_attr_bts[36] = avg_low;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* patch BSIC */
 | 
						/* patch BSIC */
 | 
				
			||||||
	bs11_attr_bts[1] = bts->bsic;
 | 
						bs11_attr_bts[1] = bts->bsic;
 | 
				
			||||||
	nanobts_attr_bts[sizeof(nanobts_attr_bts)-11] = bts->bsic;
 | 
						nanobts_attr_bts[sizeof(nanobts_attr_bts)-11] = bts->bsic;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										241
									
								
								openbsc/src/bsc_msc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										241
									
								
								openbsc/src/bsc_msc.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,241 @@
 | 
				
			|||||||
 | 
					/* Routines to talk to the MSC using the IPA Protocol */
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
 | 
				
			||||||
 | 
					 * (C) 2010 by On-Waves
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <openbsc/bsc_msc.h>
 | 
				
			||||||
 | 
					#include <openbsc/debug.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/write_queue.h>
 | 
				
			||||||
 | 
					#include <osmocore/talloc.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <arpa/inet.h>
 | 
				
			||||||
 | 
					#include <sys/socket.h>
 | 
				
			||||||
 | 
					#include <errno.h>
 | 
				
			||||||
 | 
					#include <fcntl.h>
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void connection_loss(struct bsc_msc_connection *con)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_fd *fd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd = &con->write_queue.bfd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						close(fd->fd);
 | 
				
			||||||
 | 
						fd->fd = -1;
 | 
				
			||||||
 | 
						fd->cb = write_queue_bfd_cb;
 | 
				
			||||||
 | 
						fd->when = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						con->is_connected = 0;
 | 
				
			||||||
 | 
						con->connection_loss(con);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void msc_con_timeout(void *_con)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_msc_connection *con = _con;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DMSC, LOGL_ERROR, "MSC Connection timeout.\n");
 | 
				
			||||||
 | 
						bsc_msc_lost(con);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int bsc_msc_except(struct bsc_fd *bfd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct write_queue *wrt;
 | 
				
			||||||
 | 
						struct bsc_msc_connection *con;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DMSC, LOGL_ERROR, "Exception on the BFD. Closing down.\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						wrt = container_of(bfd, struct write_queue, bfd);
 | 
				
			||||||
 | 
						con = container_of(wrt, struct bsc_msc_connection, write_queue);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						connection_loss(con);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* called in the case of a non blocking connect */
 | 
				
			||||||
 | 
					static int msc_connection_connect(struct bsc_fd *fd, unsigned int what)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int rc;
 | 
				
			||||||
 | 
						int val;
 | 
				
			||||||
 | 
						struct bsc_msc_connection *con;
 | 
				
			||||||
 | 
						struct write_queue *queue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						socklen_t len = sizeof(val);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if ((what & BSC_FD_WRITE) == 0) {
 | 
				
			||||||
 | 
							LOGP(DMSC, LOGL_ERROR, "Callback but not readable.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						queue = container_of(fd, struct write_queue, bfd);
 | 
				
			||||||
 | 
						con = container_of(queue, struct bsc_msc_connection, write_queue);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* check the socket state */
 | 
				
			||||||
 | 
						rc = getsockopt(fd->fd, SOL_SOCKET, SO_ERROR, &val, &len);
 | 
				
			||||||
 | 
						if (rc != 0) {
 | 
				
			||||||
 | 
							LOGP(DMSC, LOGL_ERROR, "getsockopt for the MSC socket failed.\n");
 | 
				
			||||||
 | 
							goto error;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (val != 0) {
 | 
				
			||||||
 | 
							LOGP(DMSC, LOGL_ERROR, "Not connected to the MSC: %d\n", val);
 | 
				
			||||||
 | 
							goto error;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* go to full operation */
 | 
				
			||||||
 | 
						fd->cb = write_queue_bfd_cb;
 | 
				
			||||||
 | 
						fd->when = BSC_FD_READ | BSC_FD_EXCEPT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						con->is_connected = 1;
 | 
				
			||||||
 | 
						bsc_del_timer(&con->timeout_timer);
 | 
				
			||||||
 | 
						LOGP(DMSC, LOGL_NOTICE, "(Re)Connected to the MSC.\n");
 | 
				
			||||||
 | 
						if (con->connected)
 | 
				
			||||||
 | 
							con->connected(con);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					error:
 | 
				
			||||||
 | 
						bsc_unregister_fd(fd);
 | 
				
			||||||
 | 
						connection_loss(con);
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static void setnonblocking(struct bsc_fd *fd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int flags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						flags = fcntl(fd->fd, F_GETFL);
 | 
				
			||||||
 | 
						if (flags < 0) {
 | 
				
			||||||
 | 
							perror("fcntl get failed");
 | 
				
			||||||
 | 
							close(fd->fd);
 | 
				
			||||||
 | 
							fd->fd = -1;
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						flags |= O_NONBLOCK;
 | 
				
			||||||
 | 
						flags = fcntl(fd->fd, F_SETFL, flags);
 | 
				
			||||||
 | 
						if (flags < 0) {
 | 
				
			||||||
 | 
							perror("fcntl get failed");
 | 
				
			||||||
 | 
							close(fd->fd);
 | 
				
			||||||
 | 
							fd->fd = -1;
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_msc_connect(struct bsc_msc_connection *con)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_fd *fd;
 | 
				
			||||||
 | 
						struct sockaddr_in sin;
 | 
				
			||||||
 | 
						int on = 1, ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DMSC, LOGL_NOTICE, "Attempting to connect MSC at %s:%d\n", con->ip, con->port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						con->is_connected = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd = &con->write_queue.bfd;
 | 
				
			||||||
 | 
						fd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 | 
				
			||||||
 | 
						fd->data = NULL;
 | 
				
			||||||
 | 
						fd->priv_nr = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (fd->fd < 0) {
 | 
				
			||||||
 | 
							perror("Creating TCP socket failed");
 | 
				
			||||||
 | 
							return fd->fd;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* make it non blocking */
 | 
				
			||||||
 | 
						setnonblocking(fd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memset(&sin, 0, sizeof(sin));
 | 
				
			||||||
 | 
						sin.sin_family = AF_INET;
 | 
				
			||||||
 | 
						sin.sin_port = htons(con->port);
 | 
				
			||||||
 | 
						inet_aton(con->ip, &sin.sin_addr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						setsockopt(fd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
 | 
				
			||||||
 | 
						ret = connect(fd->fd, (struct sockaddr *) &sin, sizeof(sin));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (ret == -1 && errno == EINPROGRESS) {
 | 
				
			||||||
 | 
							LOGP(DMSC, LOGL_ERROR, "MSC Connection in progress\n");
 | 
				
			||||||
 | 
							fd->when = BSC_FD_WRITE;
 | 
				
			||||||
 | 
							fd->cb = msc_connection_connect;
 | 
				
			||||||
 | 
							con->timeout_timer.cb = msc_con_timeout;
 | 
				
			||||||
 | 
							con->timeout_timer.data = con;
 | 
				
			||||||
 | 
							bsc_schedule_timer(&con->timeout_timer, 20, 0);
 | 
				
			||||||
 | 
						} else if (ret < 0) {
 | 
				
			||||||
 | 
							perror("Connection failed");
 | 
				
			||||||
 | 
							connection_loss(con);
 | 
				
			||||||
 | 
							return ret;
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							fd->when = BSC_FD_READ | BSC_FD_EXCEPT;
 | 
				
			||||||
 | 
							fd->cb = write_queue_bfd_cb;
 | 
				
			||||||
 | 
							con->is_connected = 1;
 | 
				
			||||||
 | 
							if (con->connected)
 | 
				
			||||||
 | 
								con->connected(con);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = bsc_register_fd(fd);
 | 
				
			||||||
 | 
						if (ret < 0) {
 | 
				
			||||||
 | 
							perror("Registering the fd failed");
 | 
				
			||||||
 | 
							close(fd->fd);
 | 
				
			||||||
 | 
							return ret;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_msc_connection *bsc_msc_create(const char *ip, int port)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_msc_connection *con;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						con = talloc_zero(NULL, struct bsc_msc_connection);
 | 
				
			||||||
 | 
						if (!con) {
 | 
				
			||||||
 | 
							LOGP(DMSC, LOGL_FATAL, "Failed to create the MSC connection.\n");
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						con->ip = ip;
 | 
				
			||||||
 | 
						con->port = port;
 | 
				
			||||||
 | 
						write_queue_init(&con->write_queue, 100);
 | 
				
			||||||
 | 
						con->write_queue.except_cb = bsc_msc_except;
 | 
				
			||||||
 | 
						return con;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bsc_msc_lost(struct bsc_msc_connection *con)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						write_queue_clear(&con->write_queue);
 | 
				
			||||||
 | 
						bsc_unregister_fd(&con->write_queue.bfd);
 | 
				
			||||||
 | 
						connection_loss(con);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void reconnect_msc(void *_msc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_msc_connection *con = _msc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DMSC, LOGL_NOTICE, "Attempting to reconnect to the MSC.\n");
 | 
				
			||||||
 | 
						bsc_msc_connect(con);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bsc_msc_schedule_connect(struct bsc_msc_connection *con)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						LOGP(DMSC, LOGL_NOTICE, "Attempting to reconnect to the MSC.\n");
 | 
				
			||||||
 | 
						con->reconnect_timer.cb = reconnect_msc;
 | 
				
			||||||
 | 
						con->reconnect_timer.data = con;
 | 
				
			||||||
 | 
						bsc_schedule_timer(&con->reconnect_timer, 5, 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1266
									
								
								openbsc/src/bsc_msc_ip.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1266
									
								
								openbsc/src/bsc_msc_ip.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										249
									
								
								openbsc/src/bsc_msc_rf.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										249
									
								
								openbsc/src/bsc_msc_rf.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,249 @@
 | 
				
			|||||||
 | 
					/* RF Ctl handling socket */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
 | 
				
			||||||
 | 
					 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
 | 
				
			||||||
 | 
					 * (C) 2010 by On-Waves
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <openbsc/bsc_msc_rf.h>
 | 
				
			||||||
 | 
					#include <openbsc/debug.h>
 | 
				
			||||||
 | 
					#include <openbsc/gsm_data.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/talloc.h>
 | 
				
			||||||
 | 
					#include <osmocore/protocol/gsm_12_21.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sys/socket.h>
 | 
				
			||||||
 | 
					#include <sys/un.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <errno.h>
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define RF_CMD_QUERY '?'
 | 
				
			||||||
 | 
					#define RF_CMD_OFF   '0'
 | 
				
			||||||
 | 
					#define RF_CMD_ON    '1'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lock_each_trx(struct gsm_network *net, int lock)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct gsm_bts *bts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(bts, &net->bts_list, list) {
 | 
				
			||||||
 | 
							struct gsm_bts_trx *trx;
 | 
				
			||||||
 | 
							llist_for_each_entry(trx, &bts->trx_list, list) {
 | 
				
			||||||
 | 
								gsm_trx_lock_rf(trx, lock);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Send a '1' when one TRX is online, otherwise send 0
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static void handle_query(struct bsc_msc_rf_conn *conn)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
						struct gsm_bts *bts;
 | 
				
			||||||
 | 
						char send = '0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(bts, &conn->gsm_network->bts_list, list) {
 | 
				
			||||||
 | 
							struct gsm_bts_trx *trx;
 | 
				
			||||||
 | 
							llist_for_each_entry(trx, &bts->trx_list, list) {
 | 
				
			||||||
 | 
								if (trx->nm_state.availability == NM_AVSTATE_OK &&
 | 
				
			||||||
 | 
								    trx->nm_state.operational != NM_STATE_LOCKED) {
 | 
				
			||||||
 | 
										send = '1';
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg = msgb_alloc(10, "RF Query");
 | 
				
			||||||
 | 
						if (!msg) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to allocate response msg.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg->l2h = msgb_put(msg, 1);
 | 
				
			||||||
 | 
						msg->l2h[0] = send;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (write_queue_enqueue(&conn->queue, msg) != 0) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to enqueue the answer.\n");
 | 
				
			||||||
 | 
							msgb_free(msg);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int rf_read_cmd(struct bsc_fd *fd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_msc_rf_conn *conn = fd->data;
 | 
				
			||||||
 | 
						char buf[1];
 | 
				
			||||||
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rc = read(fd->fd, buf, sizeof(buf));
 | 
				
			||||||
 | 
						if (rc != sizeof(buf)) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Short read %d/%s\n", errno, strerror(errno));
 | 
				
			||||||
 | 
							bsc_unregister_fd(fd);
 | 
				
			||||||
 | 
							close(fd->fd);
 | 
				
			||||||
 | 
							write_queue_clear(&conn->queue);
 | 
				
			||||||
 | 
							talloc_free(conn);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch (buf[0]) {
 | 
				
			||||||
 | 
						case RF_CMD_QUERY:
 | 
				
			||||||
 | 
							handle_query(conn);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case RF_CMD_OFF:
 | 
				
			||||||
 | 
							lock_each_trx(conn->gsm_network, 1);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case RF_CMD_ON:
 | 
				
			||||||
 | 
							lock_each_trx(conn->gsm_network, 0);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Unknown command %d\n", buf[0]);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int rf_write_cmd(struct bsc_fd *fd, struct msgb *msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rc = write(fd->fd, msg->data, msg->len);
 | 
				
			||||||
 | 
						if (rc != msg->len) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Short write %d/%s\n", errno, strerror(errno));
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int rf_ctl_accept(struct bsc_fd *bfd, unsigned int what)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_msc_rf_conn *conn;
 | 
				
			||||||
 | 
						struct bsc_msc_rf *rf = bfd->data;
 | 
				
			||||||
 | 
						struct sockaddr_un addr;
 | 
				
			||||||
 | 
						socklen_t len = sizeof(addr);
 | 
				
			||||||
 | 
						int fd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd = accept(bfd->fd, (struct sockaddr *) &addr, &len);
 | 
				
			||||||
 | 
						if (fd < 0) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to accept. errno: %d/%s\n",
 | 
				
			||||||
 | 
							     errno, strerror(errno));
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						conn = talloc_zero(rf, struct bsc_msc_rf_conn);
 | 
				
			||||||
 | 
						if (!conn) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to allocate mem.\n");
 | 
				
			||||||
 | 
							close(fd);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						write_queue_init(&conn->queue, 10);
 | 
				
			||||||
 | 
						conn->queue.bfd.data = conn;
 | 
				
			||||||
 | 
						conn->queue.bfd.fd = fd;
 | 
				
			||||||
 | 
						conn->queue.bfd.when = BSC_FD_READ | BSC_FD_WRITE;
 | 
				
			||||||
 | 
						conn->queue.read_cb = rf_read_cmd;
 | 
				
			||||||
 | 
						conn->queue.write_cb = rf_write_cmd;
 | 
				
			||||||
 | 
						conn->gsm_network = rf->gsm_network;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc_register_fd(&conn->queue.bfd) != 0) {
 | 
				
			||||||
 | 
							close(fd);
 | 
				
			||||||
 | 
							talloc_free(conn);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_msc_rf *bsc_msc_rf_create(const char *path, struct gsm_network *net)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						unsigned int namelen;
 | 
				
			||||||
 | 
						struct sockaddr_un local;
 | 
				
			||||||
 | 
						struct bsc_fd *bfd;
 | 
				
			||||||
 | 
						struct bsc_msc_rf *rf;
 | 
				
			||||||
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rf = talloc_zero(NULL, struct bsc_msc_rf);
 | 
				
			||||||
 | 
						if (!rf) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to create bsc_msc_rf.\n");
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bfd = &rf->listen;
 | 
				
			||||||
 | 
						bfd->fd = socket(AF_UNIX, SOCK_STREAM, 0);
 | 
				
			||||||
 | 
						if (bfd->fd < 0) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Can not create socket. %d/%s\n",
 | 
				
			||||||
 | 
							     errno, strerror(errno));
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						local.sun_family = AF_UNIX;
 | 
				
			||||||
 | 
						strncpy(local.sun_path, path, sizeof(local.sun_path));
 | 
				
			||||||
 | 
						local.sun_path[sizeof(local.sun_path) - 1] = '\0';
 | 
				
			||||||
 | 
						unlink(local.sun_path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* we use the same magic that X11 uses in Xtranssock.c for
 | 
				
			||||||
 | 
						 * calculating the proper length of the sockaddr */
 | 
				
			||||||
 | 
					#if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
 | 
				
			||||||
 | 
						local.sun_len = strlen(local.sun_path);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#if defined(BSD44SOCKETS) || defined(SUN_LEN)
 | 
				
			||||||
 | 
						namelen = SUN_LEN(&local);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
						namelen = strlen(local.sun_path) +
 | 
				
			||||||
 | 
							  offsetof(struct sockaddr_un, sun_path);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rc = bind(bfd->fd, (struct sockaddr *) &local, namelen);
 | 
				
			||||||
 | 
						if (rc != 0) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to bind '%s' errno: %d/%s\n",
 | 
				
			||||||
 | 
							     local.sun_path, errno, strerror(errno));
 | 
				
			||||||
 | 
							close(bfd->fd);
 | 
				
			||||||
 | 
							talloc_free(rf);
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (listen(bfd->fd, 0) != 0) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to listen: %d/%s\n", errno, strerror(errno));
 | 
				
			||||||
 | 
							close(bfd->fd);
 | 
				
			||||||
 | 
							talloc_free(rf);
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bfd->when = BSC_FD_READ;
 | 
				
			||||||
 | 
						bfd->cb = rf_ctl_accept;
 | 
				
			||||||
 | 
						bfd->data = rf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc_register_fd(bfd) != 0) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to register bfd.\n");
 | 
				
			||||||
 | 
							close(bfd->fd);
 | 
				
			||||||
 | 
							talloc_free(rf);
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rf->gsm_network = net;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return rf;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -55,7 +55,7 @@ static void complete_rllr(struct bsc_rll_req *rllr, enum bsc_rllr_ind type)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	conn = &rllr->lchan->conn;
 | 
						conn = &rllr->lchan->conn;
 | 
				
			||||||
	llist_del(&rllr->list);
 | 
						llist_del(&rllr->list);
 | 
				
			||||||
	put_subscr_con(conn);
 | 
						put_subscr_con(conn, 0);
 | 
				
			||||||
	rllr->cb(rllr->lchan, rllr->link_id, rllr->data, type);
 | 
						rllr->cb(rllr->lchan, rllr->link_id, rllr->data, type);
 | 
				
			||||||
	talloc_free(rllr);
 | 
						talloc_free(rllr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1341
									
								
								openbsc/src/bssap.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1341
									
								
								openbsc/src/bssap.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -33,8 +33,6 @@
 | 
				
			|||||||
#include <openbsc/debug.h>
 | 
					#include <openbsc/debug.h>
 | 
				
			||||||
#include <openbsc/signal.h>
 | 
					#include <openbsc/signal.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void auto_release_channel(void *_lchan);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int ts_is_usable(struct gsm_bts_trx_ts *ts)
 | 
					static int ts_is_usable(struct gsm_bts_trx_ts *ts)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/* FIXME: How does this behave for BS-11 ? */
 | 
						/* FIXME: How does this behave for BS-11 ? */
 | 
				
			||||||
@@ -225,7 +223,8 @@ _lc_find_bts(struct gsm_bts *bts, enum gsm_phys_chan_config pchan)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Allocate a logical channel */
 | 
					/* Allocate a logical channel */
 | 
				
			||||||
struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type)
 | 
					struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type,
 | 
				
			||||||
 | 
								      int allow_bigger)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct gsm_lchan *lchan = NULL;
 | 
						struct gsm_lchan *lchan = NULL;
 | 
				
			||||||
	enum gsm_phys_chan_config first, second;
 | 
						enum gsm_phys_chan_config first, second;
 | 
				
			||||||
@@ -243,6 +242,19 @@ struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type)
 | 
				
			|||||||
		lchan = _lc_find_bts(bts, first);
 | 
							lchan = _lc_find_bts(bts, first);
 | 
				
			||||||
		if (lchan == NULL)
 | 
							if (lchan == NULL)
 | 
				
			||||||
			lchan = _lc_find_bts(bts, second);
 | 
								lchan = _lc_find_bts(bts, second);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* allow to assign bigger channels */
 | 
				
			||||||
 | 
							if (allow_bigger) {
 | 
				
			||||||
 | 
								if (lchan == NULL) {
 | 
				
			||||||
 | 
									lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_H);
 | 
				
			||||||
 | 
									type = GSM_LCHAN_TCH_H;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (lchan == NULL) {
 | 
				
			||||||
 | 
									lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
 | 
				
			||||||
 | 
									type = GSM_LCHAN_TCH_F;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case GSM_LCHAN_TCH_F:
 | 
						case GSM_LCHAN_TCH_F:
 | 
				
			||||||
		lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
 | 
							lchan = _lc_find_bts(bts, GSM_PCHAN_TCH_F);
 | 
				
			||||||
@@ -268,16 +280,13 @@ struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type)
 | 
				
			|||||||
		/* clear multi rate config */
 | 
							/* clear multi rate config */
 | 
				
			||||||
		memset(&lchan->mr_conf, 0, sizeof(lchan->mr_conf));
 | 
							memset(&lchan->mr_conf, 0, sizeof(lchan->mr_conf));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* clear any msc reference */
 | 
				
			||||||
 | 
							lchan->msc_data = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* clear per MSC/BSC data */
 | 
							/* clear per MSC/BSC data */
 | 
				
			||||||
		memset(&lchan->conn, 0, sizeof(lchan->conn));
 | 
							memset(&lchan->conn, 0, sizeof(lchan->conn));
 | 
				
			||||||
 | 
					 | 
				
			||||||
		/* Configure the time and start it so it will be closed */
 | 
					 | 
				
			||||||
		lchan->conn.lchan = lchan;
 | 
							lchan->conn.lchan = lchan;
 | 
				
			||||||
		lchan->conn.bts = lchan->ts->trx->bts;
 | 
							lchan->conn.bts = lchan->ts->trx->bts;
 | 
				
			||||||
		lchan->conn.release_timer.cb = auto_release_channel;
 | 
					 | 
				
			||||||
		lchan->conn.release_timer.data = lchan;
 | 
					 | 
				
			||||||
		bsc_schedule_timer(&lchan->conn.release_timer, LCHAN_RELEASE_TIMEOUT);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		struct challoc_signal_data sig;
 | 
							struct challoc_signal_data sig;
 | 
				
			||||||
		sig.bts = bts;
 | 
							sig.bts = bts;
 | 
				
			||||||
@@ -307,8 +316,6 @@ void lchan_free(struct gsm_lchan *lchan)
 | 
				
			|||||||
		lchan->conn.use_count = 0;
 | 
							lchan->conn.use_count = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* stop the timer */
 | 
					 | 
				
			||||||
	bsc_del_timer(&lchan->conn.release_timer);
 | 
					 | 
				
			||||||
	bsc_del_timer(&lchan->T3101);
 | 
						bsc_del_timer(&lchan->T3101);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* clear cached measuement reports */
 | 
						/* clear cached measuement reports */
 | 
				
			||||||
@@ -319,7 +326,6 @@ void lchan_free(struct gsm_lchan *lchan)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	for (i = 0; i < ARRAY_SIZE(lchan->neigh_meas); i++)
 | 
						for (i = 0; i < ARRAY_SIZE(lchan->neigh_meas); i++)
 | 
				
			||||||
		lchan->neigh_meas[i].arfcn = 0;
 | 
							lchan->neigh_meas[i].arfcn = 0;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	lchan->conn.silent_call = 0;
 | 
						lchan->conn.silent_call = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sig.lchan = lchan;
 | 
						sig.lchan = lchan;
 | 
				
			||||||
@@ -338,22 +344,43 @@ void lchan_free(struct gsm_lchan *lchan)
 | 
				
			|||||||
void lchan_reset(struct gsm_lchan *lchan)
 | 
					void lchan_reset(struct gsm_lchan *lchan)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	bsc_del_timer(&lchan->T3101);
 | 
						bsc_del_timer(&lchan->T3101);
 | 
				
			||||||
 | 
						bsc_del_timer(&lchan->T3111);
 | 
				
			||||||
 | 
						bsc_del_timer(&lchan->error_timer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	lchan->type = GSM_LCHAN_NONE;
 | 
						lchan->type = GSM_LCHAN_NONE;
 | 
				
			||||||
	lchan->state = LCHAN_S_NONE;
 | 
						lchan->state = LCHAN_S_NONE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int _lchan_release_next_sapi(struct gsm_lchan *lchan)
 | 
				
			||||||
/* Consider releasing the channel now */
 | 
					 | 
				
			||||||
int lchan_auto_release(struct gsm_lchan *lchan)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (lchan->conn.use_count > 0) {
 | 
						int sapi;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (sapi = 1; sapi < ARRAY_SIZE(lchan->sapis); ++sapi) {
 | 
				
			||||||
 | 
							u_int8_t link_id;
 | 
				
			||||||
 | 
							if (lchan->sapis[sapi] == LCHAN_SAPI_UNUSED)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							link_id = sapi;
 | 
				
			||||||
 | 
							if (lchan->type == GSM_LCHAN_TCH_F || lchan->type == GSM_LCHAN_TCH_H)
 | 
				
			||||||
 | 
								link_id |= 0x40;
 | 
				
			||||||
 | 
							rsl_release_request(lchan, link_id, lchan->release_reason);
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void _lchan_handle_release(struct gsm_lchan *lchan)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						/* Ask for SAPI != 0 to be freed first and stop if we need to wait */
 | 
				
			||||||
 | 
						if (_lchan_release_next_sapi(lchan) == 0)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Assume we have GSM04.08 running and send a release */
 | 
						/* Assume we have GSM04.08 running and send a release */
 | 
				
			||||||
	if (lchan->conn.subscr) {
 | 
						if (lchan->conn.subscr) {
 | 
				
			||||||
 | 
							++lchan->conn.use_count;
 | 
				
			||||||
		gsm48_send_rr_release(lchan);
 | 
							gsm48_send_rr_release(lchan);
 | 
				
			||||||
 | 
							--lchan->conn.use_count;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* spoofed? message */
 | 
						/* spoofed? message */
 | 
				
			||||||
@@ -361,19 +388,44 @@ int lchan_auto_release(struct gsm_lchan *lchan)
 | 
				
			|||||||
		LOGP(DRLL, LOGL_ERROR, "Channel count is negative: %d\n",
 | 
							LOGP(DRLL, LOGL_ERROR, "Channel count is negative: %d\n",
 | 
				
			||||||
			lchan->conn.use_count);
 | 
								lchan->conn.use_count);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DEBUGP(DRLL, "%s Recycling Channel\n", gsm_lchan_name(lchan));
 | 
						rsl_release_request(lchan, 0, lchan->release_reason);
 | 
				
			||||||
	rsl_lchan_set_state(lchan, LCHAN_S_REL_REQ);
 | 
						rsl_lchan_set_state(lchan, LCHAN_S_REL_REQ);
 | 
				
			||||||
	rsl_release_request(lchan, 0);
 | 
					 | 
				
			||||||
	return 1;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Auto release the channel when the use count is zero */
 | 
					/* called from abis rsl */
 | 
				
			||||||
static void auto_release_channel(void *_lchan)
 | 
					int rsl_lchan_rll_release(struct gsm_lchan *lchan, u_int8_t link_id)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct gsm_lchan *lchan = _lchan;
 | 
						if (lchan->state != LCHAN_S_REL_REQ)
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!lchan_auto_release(lchan))
 | 
						if ((link_id & 0x7) != 0)
 | 
				
			||||||
		bsc_schedule_timer(&lchan->conn.release_timer, LCHAN_RELEASE_TIMEOUT);
 | 
							_lchan_handle_release(lchan);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Start the channel release procedure now. We will start by shutting
 | 
				
			||||||
 | 
					 * down SAPI!=0, then we will deactivate the SACCH and finish by releasing
 | 
				
			||||||
 | 
					 * the last SAPI at which point the RSL code will send the channel release
 | 
				
			||||||
 | 
					 * for us. We should guard the whole shutdown by T3109 or similiar and then
 | 
				
			||||||
 | 
					 * update the fixme inside gsm_04_08_utils.c
 | 
				
			||||||
 | 
					 * When we request to release the RLL and we don't get an answer within T200
 | 
				
			||||||
 | 
					 * the BTS will send us an Error indication which we will handle by closing
 | 
				
			||||||
 | 
					 * the channel and be done.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int _lchan_release(struct gsm_lchan *lchan, u_int8_t release_reason)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (lchan->conn.use_count > 0) {
 | 
				
			||||||
 | 
							DEBUGP(DRLL, "BUG: _lchan_release called without zero use_count.\n");
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						DEBUGP(DRLL, "%s Recycling Channel\n", gsm_lchan_name(lchan));
 | 
				
			||||||
 | 
						rsl_lchan_set_state(lchan, LCHAN_S_REL_REQ);
 | 
				
			||||||
 | 
						lchan->release_reason = release_reason;
 | 
				
			||||||
 | 
						_lchan_handle_release(lchan);
 | 
				
			||||||
 | 
						return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct gsm_lchan* lchan_find(struct gsm_bts *bts, struct gsm_subscriber *subscr) {
 | 
					struct gsm_lchan* lchan_find(struct gsm_bts *bts, struct gsm_subscriber *subscr) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -146,6 +146,11 @@ static const struct log_info_cat default_categories[] = {
 | 
				
			|||||||
		.description = "Reference Counting",
 | 
							.description = "Reference Counting",
 | 
				
			||||||
		.enabled = 0, .loglevel = LOGL_NOTICE,
 | 
							.enabled = 0, .loglevel = LOGL_NOTICE,
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
						[DNAT] = {
 | 
				
			||||||
 | 
							.name = "DNAT",
 | 
				
			||||||
 | 
							.description = "BSC MUX/NAT",
 | 
				
			||||||
 | 
							.enabled = 1, .loglevel = LOGL_NOTICE,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum log_ctxt {
 | 
					enum log_ctxt {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -303,6 +303,10 @@ int e1inp_ts_config(struct e1inp_ts *ts, struct e1inp_line *line,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	switch (type) {
 | 
						switch (type) {
 | 
				
			||||||
	case E1INP_TS_TYPE_SIGN:
 | 
						case E1INP_TS_TYPE_SIGN:
 | 
				
			||||||
 | 
							if (line->driver)
 | 
				
			||||||
 | 
								ts->sign.delay = line->driver->default_delay;
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								ts->sign.delay = 100000;
 | 
				
			||||||
		INIT_LLIST_HEAD(&ts->sign.sign_links);
 | 
							INIT_LLIST_HEAD(&ts->sign.sign_links);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case E1INP_TS_TYPE_TRAU:
 | 
						case E1INP_TS_TYPE_TRAU:
 | 
				
			||||||
@@ -420,7 +424,17 @@ e1inp_sign_link_create(struct e1inp_ts *ts, enum e1inp_sign_type type,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void e1inp_sign_link_destroy(struct e1inp_sign_link *link)
 | 
					void e1inp_sign_link_destroy(struct e1inp_sign_link *link)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	llist_del(&link->list);
 | 
						llist_del(&link->list);
 | 
				
			||||||
 | 
						while (!llist_empty(&link->tx_list)) {
 | 
				
			||||||
 | 
							msg = msgb_dequeue(&link->tx_list);
 | 
				
			||||||
 | 
							msgb_free(msg);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (link->ts->type == E1INP_TS_TYPE_SIGN)
 | 
				
			||||||
 | 
							bsc_del_timer(&link->ts->sign.tx_timer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	talloc_free(link);
 | 
						talloc_free(link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -104,12 +104,12 @@ static void release_loc_updating_req(struct gsm_subscriber_connection *conn)
 | 
				
			|||||||
	bsc_del_timer(&conn->loc_operation->updating_timer);
 | 
						bsc_del_timer(&conn->loc_operation->updating_timer);
 | 
				
			||||||
	talloc_free(conn->loc_operation);
 | 
						talloc_free(conn->loc_operation);
 | 
				
			||||||
	conn->loc_operation = 0;
 | 
						conn->loc_operation = 0;
 | 
				
			||||||
	put_subscr_con(conn);
 | 
						put_subscr_con(conn, 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void allocate_loc_updating_req(struct gsm_subscriber_connection *conn)
 | 
					static void allocate_loc_updating_req(struct gsm_subscriber_connection *conn)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	use_subscr_con(conn)
 | 
						use_subscr_con(conn);
 | 
				
			||||||
	release_loc_updating_req(conn);
 | 
						release_loc_updating_req(conn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	conn->loc_operation = talloc_zero(tall_locop_ctx,
 | 
						conn->loc_operation = talloc_zero(tall_locop_ctx,
 | 
				
			||||||
@@ -122,7 +122,6 @@ static int gsm0408_authorize(struct gsm_subscriber_connection *conn, struct msgb
 | 
				
			|||||||
		int rc;
 | 
							int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		db_subscriber_alloc_tmsi(conn->subscr);
 | 
							db_subscriber_alloc_tmsi(conn->subscr);
 | 
				
			||||||
		release_loc_updating_req(conn);
 | 
					 | 
				
			||||||
		rc = gsm0408_loc_upd_acc(msg->lchan, conn->subscr->tmsi);
 | 
							rc = gsm0408_loc_upd_acc(msg->lchan, conn->subscr->tmsi);
 | 
				
			||||||
		if (msg->lchan->ts->trx->bts->network->send_mm_info) {
 | 
							if (msg->lchan->ts->trx->bts->network->send_mm_info) {
 | 
				
			||||||
			/* send MM INFO with network name */
 | 
								/* send MM INFO with network name */
 | 
				
			||||||
@@ -134,9 +133,7 @@ static int gsm0408_authorize(struct gsm_subscriber_connection *conn, struct msgb
 | 
				
			|||||||
		 * trigger further action like SMS delivery */
 | 
							 * trigger further action like SMS delivery */
 | 
				
			||||||
		subscr_update(conn->subscr, msg->trx->bts,
 | 
							subscr_update(conn->subscr, msg->trx->bts,
 | 
				
			||||||
			      GSM_SUBSCRIBER_UPDATE_ATTACHED);
 | 
								      GSM_SUBSCRIBER_UPDATE_ATTACHED);
 | 
				
			||||||
 | 
							release_loc_updating_req(conn);
 | 
				
			||||||
		/* try to close channel ASAP */
 | 
					 | 
				
			||||||
		lchan_auto_release(conn->lchan);
 | 
					 | 
				
			||||||
		return rc;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -298,9 +295,8 @@ static void loc_upd_rej_cb(void *data)
 | 
				
			|||||||
	struct gsm_lchan *lchan = conn->lchan;
 | 
						struct gsm_lchan *lchan = conn->lchan;
 | 
				
			||||||
	struct gsm_bts *bts = lchan->ts->trx->bts;
 | 
						struct gsm_bts *bts = lchan->ts->trx->bts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	release_loc_updating_req(conn);
 | 
					 | 
				
			||||||
	gsm0408_loc_upd_rej(lchan, bts->network->reject_cause);
 | 
						gsm0408_loc_upd_rej(lchan, bts->network->reject_cause);
 | 
				
			||||||
	lchan_auto_release(lchan);
 | 
						release_loc_updating_req(conn);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void schedule_reject(struct gsm_subscriber_connection *conn)
 | 
					static void schedule_reject(struct gsm_subscriber_connection *conn)
 | 
				
			||||||
@@ -722,8 +718,6 @@ static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg)
 | 
				
			|||||||
	 * imagine an IMSI DETACH happening during an active call! */
 | 
						 * imagine an IMSI DETACH happening during an active call! */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* subscriber is detached: should we release lchan? */
 | 
						/* subscriber is detached: should we release lchan? */
 | 
				
			||||||
	lchan_auto_release(msg->lchan);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2070,7 +2064,6 @@ static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg)
 | 
				
			|||||||
					  MNCC_REL_CNF, &rel);
 | 
										  MNCC_REL_CNF, &rel);
 | 
				
			||||||
			/* FIXME: in case of multiple calls, we can't simply
 | 
								/* FIXME: in case of multiple calls, we can't simply
 | 
				
			||||||
			 * hang up here ! */
 | 
								 * hang up here ! */
 | 
				
			||||||
			lchan_auto_release(msg->lchan);
 | 
					 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
			rc = mncc_recvmsg(trans->subscr->net, trans,
 | 
								rc = mncc_recvmsg(trans->subscr->net, trans,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -164,13 +164,46 @@ static const enum gsm_chreq_reason_t reason_by_chreq[] = {
 | 
				
			|||||||
	[CHREQ_T_RESERVED_IGNORE]	= GSM_CHREQ_REASON_OTHER,
 | 
						[CHREQ_T_RESERVED_IGNORE]	= GSM_CHREQ_REASON_OTHER,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci)
 | 
					/* verify that the two tables match */
 | 
				
			||||||
 | 
					static_assert(sizeof(ctype_by_chreq) ==
 | 
				
			||||||
 | 
						      sizeof(((struct gsm_network *) NULL)->ctype_by_chreq), assert_size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Update channel types for request based on policy. E.g. in the
 | 
				
			||||||
 | 
					 * case of a TCH/H network/bsc use TCH/H for the emergency calls,
 | 
				
			||||||
 | 
					 * for early assignment assign a SDCCH and some other options.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void gsm_net_update_ctype(struct gsm_network *network)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						/* copy over the data */
 | 
				
			||||||
 | 
						memcpy(network->ctype_by_chreq, ctype_by_chreq, sizeof(ctype_by_chreq));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Use TCH/H for emergency calls when this cell allows TCH/H. Maybe it
 | 
				
			||||||
 | 
						 * is better to iterate over the BTS/TRX and check if no TCH/F is available
 | 
				
			||||||
 | 
						 * and then set it to TCH/H.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (network->neci)
 | 
				
			||||||
 | 
							network->ctype_by_chreq[CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_H;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (network->pag_any_tch) {
 | 
				
			||||||
 | 
							if (network->neci) {
 | 
				
			||||||
 | 
								network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_TCH_H;
 | 
				
			||||||
 | 
								network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_TCH_H;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_TCH_F;
 | 
				
			||||||
 | 
								network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_TCH_F;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum gsm_chan_t get_ctype_by_chreq(struct gsm_network *network, u_int8_t ra)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
	int length;
 | 
						int length;
 | 
				
			||||||
	const struct chreq *chreq;
 | 
						const struct chreq *chreq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (neci) {
 | 
						if (network->neci) {
 | 
				
			||||||
		chreq = chreq_type_neci1;
 | 
							chreq = chreq_type_neci1;
 | 
				
			||||||
		length = ARRAY_SIZE(chreq_type_neci1);
 | 
							length = ARRAY_SIZE(chreq_type_neci1);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
@@ -182,13 +215,13 @@ enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci)
 | 
				
			|||||||
	for (i = 0; i < length; i++) {
 | 
						for (i = 0; i < length; i++) {
 | 
				
			||||||
		const struct chreq *chr = &chreq[i];
 | 
							const struct chreq *chr = &chreq[i];
 | 
				
			||||||
		if ((ra & chr->mask) == chr->val)
 | 
							if ((ra & chr->mask) == chr->val)
 | 
				
			||||||
			return ctype_by_chreq[chr->type];
 | 
								return network->ctype_by_chreq[chr->type];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	LOGP(DRR, LOGL_ERROR, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra);
 | 
						LOGP(DRR, LOGL_ERROR, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra);
 | 
				
			||||||
	return GSM_LCHAN_SDCCH;
 | 
						return GSM_LCHAN_SDCCH;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci)
 | 
					enum gsm_chreq_reason_t get_reason_by_chreq(u_int8_t ra, int neci)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
	int length;
 | 
						int length;
 | 
				
			||||||
@@ -288,7 +321,7 @@ int gsm48_handle_paging_resp(struct msgb *msg, struct gsm_subscriber *subscr)
 | 
				
			|||||||
	sig_data.bts	= msg->lchan->ts->trx->bts;
 | 
						sig_data.bts	= msg->lchan->ts->trx->bts;
 | 
				
			||||||
	sig_data.lchan	= msg->lchan;
 | 
						sig_data.lchan	= msg->lchan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bts->network->stats.paging.completed++;
 | 
						counter_inc(bts->network->stats.paging.completed);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dispatch_signal(SS_PAGING, S_PAGING_SUCCEEDED, &sig_data);
 | 
						dispatch_signal(SS_PAGING, S_PAGING_SUCCEEDED, &sig_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -675,7 +675,7 @@ static int gsm411_rx_rp_ud(struct msgb *msg, struct gsm_trans *trans,
 | 
				
			|||||||
				     GSM411_RP_CAUSE_INV_MAND_INF);
 | 
									     GSM411_RP_CAUSE_INV_MAND_INF);
 | 
				
			||||||
		return -EIO;
 | 
							return -EIO;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	msg->smsh = tpdu;
 | 
						msg->l4h = tpdu;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DEBUGP(DSMS, "DST(%u,%s)\n", dst_len, hexdump(dst, dst_len));
 | 
						DEBUGP(DSMS, "DST(%u,%s)\n", dst_len, hexdump(dst, dst_len));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -757,7 +757,7 @@ static int gsm411_rx_rp_ack(struct msgb *msg, struct gsm_trans *trans,
 | 
				
			|||||||
	/* release channel if done */
 | 
						/* release channel if done */
 | 
				
			||||||
#warning "BROKEN. The SAPI will be released automatically by the BSC"
 | 
					#warning "BROKEN. The SAPI will be released automatically by the BSC"
 | 
				
			||||||
	if (!sms)
 | 
						if (!sms)
 | 
				
			||||||
		rsl_release_request(msg->lchan, trans->sms.link_id);
 | 
							rsl_release_request(msg->lchan, trans->sms.link_id, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -833,7 +833,7 @@ static int gsm411_rx_rp_smma(struct msgb *msg, struct gsm_trans *trans,
 | 
				
			|||||||
	if (sms)
 | 
						if (sms)
 | 
				
			||||||
		gsm411_send_sms_lchan(trans->conn, sms);
 | 
							gsm411_send_sms_lchan(trans->conn, sms);
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		rsl_release_request(msg->lchan, trans->sms.link_id);
 | 
							rsl_release_request(msg->lchan, trans->sms.link_id, 0);
 | 
				
			||||||
#warning "BROKEN: The SAPI=3 will be released automatically by the BSC"
 | 
					#warning "BROKEN: The SAPI=3 will be released automatically by the BSC"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return rc;
 | 
						return rc;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -257,7 +257,6 @@ int gsm0480_send_ussd_response(const struct msgb *in_msg, const char *response_t
 | 
				
			|||||||
	if (((strlen(response_text) * 7) % 8) != 0)
 | 
						if (((strlen(response_text) * 7) % 8) != 0)
 | 
				
			||||||
		response_len += 1;
 | 
							response_len += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	msg->bts_link = in_msg->bts_link;
 | 
					 | 
				
			||||||
	msg->lchan = in_msg->lchan;
 | 
						msg->lchan = in_msg->lchan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* First put the payload text into the message */
 | 
						/* First put the payload text into the message */
 | 
				
			||||||
@@ -304,7 +303,6 @@ int gsm0480_send_ussd_reject(const struct msgb *in_msg,
 | 
				
			|||||||
	struct msgb *msg = gsm48_msgb_alloc();
 | 
						struct msgb *msg = gsm48_msgb_alloc();
 | 
				
			||||||
	struct gsm48_hdr *gh;
 | 
						struct gsm48_hdr *gh;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	msg->bts_link = in_msg->bts_link;
 | 
					 | 
				
			||||||
	msg->lchan = in_msg->lchan;
 | 
						msg->lchan = in_msg->lchan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* First insert the problem code */
 | 
						/* First insert the problem code */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -88,6 +88,7 @@ static const struct value_string lchan_s_names[] = {
 | 
				
			|||||||
	{ LCHAN_S_ACTIVE,	"ACTIVE" },
 | 
						{ LCHAN_S_ACTIVE,	"ACTIVE" },
 | 
				
			||||||
	{ LCHAN_S_INACTIVE,	"INACTIVE" },
 | 
						{ LCHAN_S_INACTIVE,	"INACTIVE" },
 | 
				
			||||||
	{ LCHAN_S_REL_REQ,	"RELEASE REQUESTED" },
 | 
						{ LCHAN_S_REL_REQ,	"RELEASE REQUESTED" },
 | 
				
			||||||
 | 
						{ LCHAN_S_REL_ERR,	"RELEASE DUE ERROR" },
 | 
				
			||||||
	{ 0,			NULL }
 | 
						{ 0,			NULL }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -221,6 +222,10 @@ struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	bts->c0->ts[0].pchan = GSM_PCHAN_CCCH_SDCCH4;
 | 
						bts->c0->ts[0].pchan = GSM_PCHAN_CCCH_SDCCH4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bts->paging.free_chans_need = -1;
 | 
				
			||||||
 | 
						bts->rach_b_thresh = -1;
 | 
				
			||||||
 | 
						bts->rach_ldavg_slots = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	llist_add_tail(&bts->list, &net->bts_list);
 | 
						llist_add_tail(&bts->list, &net->bts_list);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return bts;
 | 
						return bts;
 | 
				
			||||||
@@ -287,6 +292,17 @@ struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_c
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	net->mncc_recv = mncc_recv;
 | 
						net->mncc_recv = mncc_recv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						gsm_net_update_ctype(net);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						net->core_country_code = -1;
 | 
				
			||||||
 | 
						net->core_network_code = -1;
 | 
				
			||||||
 | 
						net->rtp_base_port = 4000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						net->msc_ip = talloc_strdup(net, "127.0.0.1");
 | 
				
			||||||
 | 
						net->msc_port = 5000;
 | 
				
			||||||
 | 
						net->ping_timeout = 20;
 | 
				
			||||||
 | 
						net->pong_timeout = 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return net;
 | 
						return net;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -440,33 +456,6 @@ const char *gsm_auth_policy_name(enum gsm_auth_policy policy)
 | 
				
			|||||||
	return get_value_string(auth_policy_names, policy);
 | 
						return get_value_string(auth_policy_names, policy);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* this should not be here but in gsm_04_08... but that creates
 | 
					 | 
				
			||||||
   in turn a dependency nightmare (abis_nm depending on 04_08, ...) */
 | 
					 | 
				
			||||||
static int gsm48_construct_ra(u_int8_t *buf, const struct gprs_ra_id *raid)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	u_int16_t mcc = raid->mcc;
 | 
					 | 
				
			||||||
	u_int16_t mnc = raid->mnc;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	buf[0] = ((mcc / 100) % 10) | (((mcc / 10) % 10) << 4);
 | 
					 | 
				
			||||||
	buf[1] = (mcc % 10);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* I wonder who came up with the stupidity of encoding the MNC
 | 
					 | 
				
			||||||
	 * differently depending on how many digits its decimal number has! */
 | 
					 | 
				
			||||||
	if (mnc < 100) {
 | 
					 | 
				
			||||||
		buf[1] |= 0xf0;
 | 
					 | 
				
			||||||
		buf[2] = ((mnc / 10) % 10) | ((mnc % 10) << 4);
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		buf[1] |= (mnc % 10) << 4;
 | 
					 | 
				
			||||||
		buf[2] = ((mnc / 100) % 10) | (((mcc / 10) % 10) << 4);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	*(u_int16_t *)(buf+3) = htons(raid->lac);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	buf[5] = raid->rac;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return 6;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts)
 | 
					void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	raid->mcc = bts->network->country_code;
 | 
						raid->mcc = bts->network->country_code;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,6 +31,7 @@
 | 
				
			|||||||
#include <openbsc/gsm_subscriber.h>
 | 
					#include <openbsc/gsm_subscriber.h>
 | 
				
			||||||
#include <openbsc/paging.h>
 | 
					#include <openbsc/paging.h>
 | 
				
			||||||
#include <openbsc/debug.h>
 | 
					#include <openbsc/debug.h>
 | 
				
			||||||
 | 
					#include <openbsc/chan_alloc.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LLIST_HEAD(active_subscribers);
 | 
					LLIST_HEAD(active_subscribers);
 | 
				
			||||||
void *tall_subscr_ctx;
 | 
					void *tall_subscr_ctx;
 | 
				
			||||||
@@ -88,6 +89,7 @@ static int subscr_paging_cb(unsigned int hooknum, unsigned int event,
 | 
				
			|||||||
	request->cbfn(hooknum, event, msg, data, request->param);
 | 
						request->cbfn(hooknum, event, msg, data, request->param);
 | 
				
			||||||
	subscr->in_callback = 0;
 | 
						subscr->in_callback = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						subscr_put(request->subscr);
 | 
				
			||||||
	talloc_free(request);
 | 
						talloc_free(request);
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -165,7 +167,7 @@ void subscr_get_channel(struct gsm_subscriber *subscr,
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memset(request, 0, sizeof(*request));
 | 
						memset(request, 0, sizeof(*request));
 | 
				
			||||||
	request->subscr = subscr;
 | 
						request->subscr = subscr_get(subscr);
 | 
				
			||||||
	request->channel_type = type;
 | 
						request->channel_type = type;
 | 
				
			||||||
	request->cbfn = cbfn;
 | 
						request->cbfn = cbfn;
 | 
				
			||||||
	request->param = param;
 | 
						request->param = param;
 | 
				
			||||||
@@ -206,9 +208,28 @@ void subscr_put_channel(struct gsm_lchan *lchan)
 | 
				
			|||||||
	 * will listen to the paging requests before we timeout
 | 
						 * will listen to the paging requests before we timeout
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	put_subscr_con(conn);
 | 
						put_subscr_con(conn, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (lchan->conn.subscr && !llist_empty(&lchan->conn.subscr->requests))
 | 
						if (lchan->conn.subscr && !llist_empty(&lchan->conn.subscr->requests))
 | 
				
			||||||
		subscr_send_paging_request(lchan->conn.subscr);
 | 
							subscr_send_paging_request(lchan->conn.subscr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct gsm_subscriber *subscr_get_or_create(struct gsm_network *net,
 | 
				
			||||||
 | 
										    const char *imsi)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct gsm_subscriber *subscr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(subscr, subscr_bsc_active_subscriber(), entry) {
 | 
				
			||||||
 | 
							if (strcmp(subscr->imsi, imsi) == 0 && subscr->net == net)
 | 
				
			||||||
 | 
								return subscr_get(subscr);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						subscr = subscr_alloc();
 | 
				
			||||||
 | 
						if (!subscr)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						strcpy(subscr->imsi, imsi);
 | 
				
			||||||
 | 
						subscr->net = net;
 | 
				
			||||||
 | 
						return subscr;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -99,7 +99,7 @@ int bsc_handover_start(struct gsm_lchan *old_lchan, struct gsm_bts *bts)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	counter_inc(bts->network->stats.handover.attempted);
 | 
						counter_inc(bts->network->stats.handover.attempted);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	new_lchan = lchan_alloc(bts, old_lchan->type);
 | 
						new_lchan = lchan_alloc(bts, old_lchan->type, 0);
 | 
				
			||||||
	if (!new_lchan) {
 | 
						if (!new_lchan) {
 | 
				
			||||||
		LOGP(DHO, LOGL_NOTICE, "No free channel\n");
 | 
							LOGP(DHO, LOGL_NOTICE, "No free channel\n");
 | 
				
			||||||
		counter_inc(bts->network->stats.handover.no_channel);
 | 
							counter_inc(bts->network->stats.handover.no_channel);
 | 
				
			||||||
@@ -231,7 +231,6 @@ static int ho_gsm48_ho_compl(struct gsm_lchan *new_lchan)
 | 
				
			|||||||
	trans_lchan_change(&ho->old_lchan->conn, &new_lchan->conn);
 | 
						trans_lchan_change(&ho->old_lchan->conn, &new_lchan->conn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rsl_lchan_set_state(ho->old_lchan, LCHAN_S_INACTIVE);
 | 
						rsl_lchan_set_state(ho->old_lchan, LCHAN_S_INACTIVE);
 | 
				
			||||||
	lchan_auto_release(ho->old_lchan);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* do something to re-route the actual speech frames ! */
 | 
						/* do something to re-route the actual speech frames ! */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -259,7 +258,7 @@ static int ho_gsm48_ho_fail(struct gsm_lchan *old_lchan)
 | 
				
			|||||||
	bsc_del_timer(&ho->T3103);
 | 
						bsc_del_timer(&ho->T3103);
 | 
				
			||||||
	llist_del(&ho->list);
 | 
						llist_del(&ho->list);
 | 
				
			||||||
	conn = &ho->new_lchan->conn;
 | 
						conn = &ho->new_lchan->conn;
 | 
				
			||||||
	put_subscr_con(conn);
 | 
						put_subscr_con(conn, 0);
 | 
				
			||||||
	talloc_free(ho);
 | 
						talloc_free(ho);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -265,6 +265,7 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg,
 | 
				
			|||||||
			trx->rsl_link = e1inp_sign_link_create(e1i_ts,
 | 
								trx->rsl_link = e1inp_sign_link_create(e1i_ts,
 | 
				
			||||||
							E1INP_SIGN_RSL, trx,
 | 
												E1INP_SIGN_RSL, trx,
 | 
				
			||||||
							trx->rsl_tei, 0);
 | 
												trx->rsl_tei, 0);
 | 
				
			||||||
 | 
								trx->rsl_link->ts->sign.delay = 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			/* get rid of our old temporary bfd */
 | 
								/* get rid of our old temporary bfd */
 | 
				
			||||||
			memcpy(newbfd, bfd, sizeof(*newbfd));
 | 
								memcpy(newbfd, bfd, sizeof(*newbfd));
 | 
				
			||||||
@@ -572,7 +573,7 @@ static int handle_ts1_write(struct bsc_fd *bfd)
 | 
				
			|||||||
	e1i_ts->sign.tx_timer.data = e1i_ts;
 | 
						e1i_ts->sign.tx_timer.data = e1i_ts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Reducing this might break the nanoBTS 900 init. */
 | 
						/* Reducing this might break the nanoBTS 900 init. */
 | 
				
			||||||
	bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, 100000);
 | 
						bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -606,6 +607,7 @@ static int ipaccess_fd_cb(struct bsc_fd *bfd, unsigned int what)
 | 
				
			|||||||
struct e1inp_driver ipaccess_driver = {
 | 
					struct e1inp_driver ipaccess_driver = {
 | 
				
			||||||
	.name = "ip.access",
 | 
						.name = "ip.access",
 | 
				
			||||||
	.want_write = ts_want_write,
 | 
						.want_write = ts_want_write,
 | 
				
			||||||
 | 
						.default_delay = 100000,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* callback of the OML listening filedescriptor */
 | 
					/* callback of the OML listening filedescriptor */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -235,7 +235,7 @@ static int handle_ts1_write(struct bsc_fd *bfd)
 | 
				
			|||||||
	/* set tx delay timer for next event */
 | 
						/* set tx delay timer for next event */
 | 
				
			||||||
	e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
 | 
						e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
 | 
				
			||||||
	e1i_ts->sign.tx_timer.data = e1i_ts;
 | 
						e1i_ts->sign.tx_timer.data = e1i_ts;
 | 
				
			||||||
	bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, 50000);
 | 
						bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -375,6 +375,7 @@ static int activate_bchan(struct e1inp_line *line, int ts, int act)
 | 
				
			|||||||
struct e1inp_driver misdn_driver = {
 | 
					struct e1inp_driver misdn_driver = {
 | 
				
			||||||
	.name = "mISDNuser",
 | 
						.name = "mISDNuser",
 | 
				
			||||||
	.want_write = ts_want_write,
 | 
						.want_write = ts_want_write,
 | 
				
			||||||
 | 
						.default_delay = 50000,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int mi_e1_setup(struct e1inp_line *line, int release_l2)
 | 
					static int mi_e1_setup(struct e1inp_line *line, int release_l2)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,6 +59,7 @@ static int sw_load_state = 0;
 | 
				
			|||||||
static int oml_state = 0;
 | 
					static int oml_state = 0;
 | 
				
			||||||
static int dump_files = 0;
 | 
					static int dump_files = 0;
 | 
				
			||||||
static char *firmware_analysis = NULL;
 | 
					static char *firmware_analysis = NULL;
 | 
				
			||||||
 | 
					static int trx_nr = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct sw_load {
 | 
					struct sw_load {
 | 
				
			||||||
	u_int8_t file_id[255];
 | 
						u_int8_t file_id[255];
 | 
				
			||||||
@@ -316,7 +317,8 @@ static void bootstrap_om(struct gsm_bts *bts)
 | 
				
			|||||||
		memcpy(buf+3, unit_id, len);
 | 
							memcpy(buf+3, unit_id, len);
 | 
				
			||||||
		buf[3+len] = 0;
 | 
							buf[3+len] = 0;
 | 
				
			||||||
		printf("setting Unit ID to '%s'\n", unit_id);
 | 
							printf("setting Unit ID to '%s'\n", unit_id);
 | 
				
			||||||
		abis_nm_ipaccess_set_nvattr(bts->c0, buf, 3+len+1);
 | 
							abis_nm_ipaccess_set_nvattr(gsm_bts_trx_by_nr(bts, trx_nr),
 | 
				
			||||||
 | 
										    buf, 3+len+1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (prim_oml_ip) {
 | 
						if (prim_oml_ip) {
 | 
				
			||||||
		struct in_addr ia;
 | 
							struct in_addr ia;
 | 
				
			||||||
@@ -354,7 +356,8 @@ static void bootstrap_om(struct gsm_bts *bts)
 | 
				
			|||||||
		*cur++ = nv_mask >> 8;
 | 
							*cur++ = nv_mask >> 8;
 | 
				
			||||||
		printf("setting NV Flags/Mask to 0x%04x/0x%04x\n",
 | 
							printf("setting NV Flags/Mask to 0x%04x/0x%04x\n",
 | 
				
			||||||
			nv_flags, nv_mask);
 | 
								nv_flags, nv_mask);
 | 
				
			||||||
		abis_nm_ipaccess_set_nvattr(bts->c0, buf, 3+len);
 | 
							abis_nm_ipaccess_set_nvattr(gsm_bts_trx_by_nr(bts, trx_nr),
 | 
				
			||||||
 | 
										    buf, 3+len);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (restart && !prim_oml_ip && !software) {
 | 
						if (restart && !prim_oml_ip && !software) {
 | 
				
			||||||
@@ -605,6 +608,7 @@ static void print_help(void)
 | 
				
			|||||||
	printf("  -d --software firmware\n");
 | 
						printf("  -d --software firmware\n");
 | 
				
			||||||
	printf("  -f --firmware firmware Provide firmware information\n");
 | 
						printf("  -f --firmware firmware Provide firmware information\n");
 | 
				
			||||||
	printf("  -w --write-firmware. This will dump the firmware parts to the filesystem. Use with -f.\n");
 | 
						printf("  -w --write-firmware. This will dump the firmware parts to the filesystem. Use with -f.\n");
 | 
				
			||||||
 | 
						printf("  -t --trx NR. The TRX to use for the Unit ID and NVRAM attributes.\n");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char **argv)
 | 
					int main(int argc, char **argv)
 | 
				
			||||||
@@ -639,9 +643,11 @@ int main(int argc, char **argv)
 | 
				
			|||||||
			{ "software", 1, 0, 'd' },
 | 
								{ "software", 1, 0, 'd' },
 | 
				
			||||||
			{ "firmware", 1, 0, 'f' },
 | 
								{ "firmware", 1, 0, 'f' },
 | 
				
			||||||
			{ "write-firmware", 0, 0, 'w' },
 | 
								{ "write-firmware", 0, 0, 'w' },
 | 
				
			||||||
 | 
								{ "trx", 1, 0, 't' },
 | 
				
			||||||
 | 
								{ 0, 0, 0, 0 },
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		c = getopt_long(argc, argv, "u:o:rn:l:hs:d:f:w", long_options,
 | 
							c = getopt_long(argc, argv, "u:o:rn:l:hs:d:f:wt:", long_options,
 | 
				
			||||||
				&option_index);
 | 
									&option_index);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (c == -1)
 | 
							if (c == -1)
 | 
				
			||||||
@@ -683,6 +689,9 @@ int main(int argc, char **argv)
 | 
				
			|||||||
		case 'w':
 | 
							case 'w':
 | 
				
			||||||
			dump_files = 1;
 | 
								dump_files = 1;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
							case 't':
 | 
				
			||||||
 | 
								trx_nr = atoi(optarg);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		case 'h':
 | 
							case 'h':
 | 
				
			||||||
			print_usage();
 | 
								print_usage();
 | 
				
			||||||
			print_help();
 | 
								print_help();
 | 
				
			||||||
@@ -724,6 +733,8 @@ int main(int argc, char **argv)
 | 
				
			|||||||
		exit(1);
 | 
							exit(1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						bts->oml_link->ts->sign.delay = 10;
 | 
				
			||||||
 | 
						bts->c0->rsl_link->ts->sign.delay = 10;
 | 
				
			||||||
	while (1) {
 | 
						while (1) {
 | 
				
			||||||
		rc = bsc_select_main(0);
 | 
							rc = bsc_select_main(0);
 | 
				
			||||||
		if (rc < 0)
 | 
							if (rc < 0)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -128,6 +128,15 @@ static int mgcp_rsip_cb(struct mgcp_config *cfg)
 | 
				
			|||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int mgcp_change_cb(struct mgcp_config *cfg, int endpoint, int state, int local_rtp)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (state != MGCP_ENDP_MDCX)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mgcp_send_dummy(&cfg->endpoints[endpoint]);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int read_call_agent(struct bsc_fd *fd, unsigned int what)
 | 
					static int read_call_agent(struct bsc_fd *fd, unsigned int what)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct sockaddr_in addr;
 | 
						struct sockaddr_in addr;
 | 
				
			||||||
@@ -200,6 +209,7 @@ int main(int argc, char** argv)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* set some callbacks */
 | 
						/* set some callbacks */
 | 
				
			||||||
	cfg->reset_cb = mgcp_rsip_cb;
 | 
						cfg->reset_cb = mgcp_rsip_cb;
 | 
				
			||||||
 | 
						cfg->change_cb = mgcp_change_cb;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* we need to bind a socket */
 | 
					        /* we need to bind a socket */
 | 
				
			||||||
        if (rc == 0) {
 | 
					        if (rc == 0) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,7 +31,6 @@
 | 
				
			|||||||
#include <arpa/inet.h>
 | 
					#include <arpa/inet.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <osmocore/msgb.h>
 | 
					#include <osmocore/msgb.h>
 | 
				
			||||||
#include <osmocore/talloc.h>
 | 
					 | 
				
			||||||
#include <osmocore/select.h>
 | 
					#include <osmocore/select.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <openbsc/debug.h>
 | 
					#include <openbsc/debug.h>
 | 
				
			||||||
@@ -73,6 +72,8 @@ enum {
 | 
				
			|||||||
	PROTO_RTCP,
 | 
						PROTO_RTCP,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define DUMMY_LOAD 0x23
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int udp_send(int fd, struct in_addr *addr, int port, char *buf, int len)
 | 
					static int udp_send(int fd, struct in_addr *addr, int port, char *buf, int len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -84,6 +85,14 @@ static int udp_send(int fd, struct in_addr *addr, int port, char *buf, int len)
 | 
				
			|||||||
	return sendto(fd, buf, len, 0, (struct sockaddr *)&out, sizeof(out));
 | 
						return sendto(fd, buf, len, 0, (struct sockaddr *)&out, sizeof(out));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int mgcp_send_dummy(struct mgcp_endpoint *endp)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static char buf[] = { DUMMY_LOAD };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return udp_send(endp->local_rtp.fd, &endp->remote,
 | 
				
			||||||
 | 
								endp->net_rtp, buf, 1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void patch_payload(int payload, char *data, int len)
 | 
					static void patch_payload(int payload, char *data, int len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct rtp_hdr *rtp_hdr;
 | 
						struct rtp_hdr *rtp_hdr;
 | 
				
			||||||
@@ -129,8 +138,10 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* do not forward aynthing... maybe there is a packet from the bts */
 | 
						/* do not forward aynthing... maybe there is a packet from the bts */
 | 
				
			||||||
	if (endp->ci == CI_UNUSED)
 | 
						if (endp->ci == CI_UNUSED) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_DEBUG, "Unknown message on endpoint: 0x%x\n", ENDPOINT_NUMBER(endp));
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Figure out where to forward it to. This code assumes that we
 | 
						 * Figure out where to forward it to. This code assumes that we
 | 
				
			||||||
@@ -161,9 +172,17 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
 | 
				
			|||||||
			LOGP(DMGCP, LOGL_NOTICE, "Found BTS for endpoint: 0x%x on port: %d/%d of %s\n",
 | 
								LOGP(DMGCP, LOGL_NOTICE, "Found BTS for endpoint: 0x%x on port: %d/%d of %s\n",
 | 
				
			||||||
				ENDPOINT_NUMBER(endp), ntohs(endp->bts_rtp), ntohs(endp->bts_rtcp),
 | 
									ENDPOINT_NUMBER(endp), ntohs(endp->bts_rtp), ntohs(endp->bts_rtcp),
 | 
				
			||||||
				inet_ntoa(addr.sin_addr));
 | 
									inet_ntoa(addr.sin_addr));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* throw away dummy message */
 | 
				
			||||||
 | 
						if (rc == 1 && buf[0] == DUMMY_LOAD) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_NOTICE, "Filtered dummy on 0x%x\n",
 | 
				
			||||||
 | 
								ENDPOINT_NUMBER(endp));
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* do this before the loop handling */
 | 
						/* do this before the loop handling */
 | 
				
			||||||
	if (dest == DEST_NETWORK)
 | 
						if (dest == DEST_NETWORK)
 | 
				
			||||||
		++endp->in_bts;
 | 
							++endp->in_bts;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -389,6 +389,7 @@ static struct msgb *handle_create_con(struct mgcp_config *cfg, struct msgb *msg)
 | 
				
			|||||||
		if (cfg->force_realloc) {
 | 
							if (cfg->force_realloc) {
 | 
				
			||||||
			LOGP(DMGCP, LOGL_NOTICE, "Endpoint 0x%x already allocated. Forcing realloc.\n",
 | 
								LOGP(DMGCP, LOGL_NOTICE, "Endpoint 0x%x already allocated. Forcing realloc.\n",
 | 
				
			||||||
			    ENDPOINT_NUMBER(endp));
 | 
								    ENDPOINT_NUMBER(endp));
 | 
				
			||||||
 | 
								mgcp_free_endp(endp);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			LOGP(DMGCP, LOGL_ERROR, "Endpoint is already used. 0x%x\n",
 | 
								LOGP(DMGCP, LOGL_ERROR, "Endpoint is already used. 0x%x\n",
 | 
				
			||||||
			     ENDPOINT_NUMBER(endp));
 | 
								     ENDPOINT_NUMBER(endp));
 | 
				
			||||||
@@ -485,6 +486,7 @@ static struct msgb *handle_modify_con(struct mgcp_config *cfg, struct msgb *msg)
 | 
				
			|||||||
	const char *trans_id;
 | 
						const char *trans_id;
 | 
				
			||||||
	struct mgcp_endpoint *endp;
 | 
						struct mgcp_endpoint *endp;
 | 
				
			||||||
	int error_code = 500;
 | 
						int error_code = 500;
 | 
				
			||||||
 | 
						int silent = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
 | 
						found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
 | 
				
			||||||
	if (found != 0)
 | 
						if (found != 0)
 | 
				
			||||||
@@ -517,6 +519,9 @@ static struct msgb *handle_modify_con(struct mgcp_config *cfg, struct msgb *msg)
 | 
				
			|||||||
		    goto error3;
 | 
							    goto error3;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
						case 'Z':
 | 
				
			||||||
 | 
							silent = strcmp("noanswer", (const char *)&msg->l3h[line_start + 3]) == 0;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
	case '\0':
 | 
						case '\0':
 | 
				
			||||||
		/* SDP file begins */
 | 
							/* SDP file begins */
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
@@ -562,6 +567,8 @@ static struct msgb *handle_modify_con(struct mgcp_config *cfg, struct msgb *msg)
 | 
				
			|||||||
		case MGCP_POLICY_REJECT:
 | 
							case MGCP_POLICY_REJECT:
 | 
				
			||||||
			LOGP(DMGCP, LOGL_NOTICE, "MDCX rejected by policy on 0x%x\n",
 | 
								LOGP(DMGCP, LOGL_NOTICE, "MDCX rejected by policy on 0x%x\n",
 | 
				
			||||||
			     ENDPOINT_NUMBER(endp));
 | 
								     ENDPOINT_NUMBER(endp));
 | 
				
			||||||
 | 
								if (silent)
 | 
				
			||||||
 | 
									goto out_silent;
 | 
				
			||||||
			return create_response(500, "MDCX", trans_id);
 | 
								return create_response(500, "MDCX", trans_id);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case MGCP_POLICY_DEFER:
 | 
							case MGCP_POLICY_DEFER:
 | 
				
			||||||
@@ -579,6 +586,9 @@ static struct msgb *handle_modify_con(struct mgcp_config *cfg, struct msgb *msg)
 | 
				
			|||||||
		ENDPOINT_NUMBER(endp), inet_ntoa(endp->remote), ntohs(endp->net_rtp));
 | 
							ENDPOINT_NUMBER(endp), inet_ntoa(endp->remote), ntohs(endp->net_rtp));
 | 
				
			||||||
	if (cfg->change_cb)
 | 
						if (cfg->change_cb)
 | 
				
			||||||
		cfg->change_cb(cfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_MDCX, endp->rtp_port);
 | 
							cfg->change_cb(cfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_MDCX, endp->rtp_port);
 | 
				
			||||||
 | 
						if (silent)
 | 
				
			||||||
 | 
							goto out_silent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return create_response_with_sdp(endp, "MDCX", trans_id);
 | 
						return create_response_with_sdp(endp, "MDCX", trans_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
error:
 | 
					error:
 | 
				
			||||||
@@ -589,6 +599,10 @@ error:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
error3:
 | 
					error3:
 | 
				
			||||||
	return create_response(error_code, "MDCX", trans_id);
 | 
						return create_response(error_code, "MDCX", trans_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					out_silent:
 | 
				
			||||||
 | 
						return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg)
 | 
					static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg)
 | 
				
			||||||
@@ -598,6 +612,7 @@ static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg)
 | 
				
			|||||||
	const char *trans_id;
 | 
						const char *trans_id;
 | 
				
			||||||
	struct mgcp_endpoint *endp;
 | 
						struct mgcp_endpoint *endp;
 | 
				
			||||||
	int error_code = 500;
 | 
						int error_code = 500;
 | 
				
			||||||
 | 
						int silent = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
 | 
						found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
 | 
				
			||||||
	if (found != 0)
 | 
						if (found != 0)
 | 
				
			||||||
@@ -619,6 +634,9 @@ static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg)
 | 
				
			|||||||
		if (verify_ci(endp, (const char *)&msg->l3h[line_start + 3]) != 0)
 | 
							if (verify_ci(endp, (const char *)&msg->l3h[line_start + 3]) != 0)
 | 
				
			||||||
			goto error3;
 | 
								goto error3;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
						case 'Z':
 | 
				
			||||||
 | 
							silent = strcmp("noanswer", (const char *)&msg->l3h[line_start + 3]) == 0;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		LOGP(DMGCP, LOGL_NOTICE, "Unhandled option: '%c'/%d on 0x%x\n",
 | 
							LOGP(DMGCP, LOGL_NOTICE, "Unhandled option: '%c'/%d on 0x%x\n",
 | 
				
			||||||
@@ -634,6 +652,8 @@ static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg)
 | 
				
			|||||||
		case MGCP_POLICY_REJECT:
 | 
							case MGCP_POLICY_REJECT:
 | 
				
			||||||
			LOGP(DMGCP, LOGL_NOTICE, "DLCX rejected by policy on 0x%x\n",
 | 
								LOGP(DMGCP, LOGL_NOTICE, "DLCX rejected by policy on 0x%x\n",
 | 
				
			||||||
			     ENDPOINT_NUMBER(endp));
 | 
								     ENDPOINT_NUMBER(endp));
 | 
				
			||||||
 | 
								if (silent)
 | 
				
			||||||
 | 
									goto out_silent;
 | 
				
			||||||
			return create_response(500, "DLCX", trans_id);
 | 
								return create_response(500, "DLCX", trans_id);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case MGCP_POLICY_DEFER:
 | 
							case MGCP_POLICY_DEFER:
 | 
				
			||||||
@@ -647,10 +667,14 @@ static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* free the connection */
 | 
						/* free the connection */
 | 
				
			||||||
 | 
						LOGP(DMGCP, LOGL_NOTICE, "Deleted endpoint on: 0x%x Server: %s:%u\n",
 | 
				
			||||||
 | 
							ENDPOINT_NUMBER(endp), inet_ntoa(endp->remote), ntohs(endp->net_rtp));
 | 
				
			||||||
	mgcp_free_endp(endp);
 | 
						mgcp_free_endp(endp);
 | 
				
			||||||
	if (cfg->change_cb)
 | 
						if (cfg->change_cb)
 | 
				
			||||||
		cfg->change_cb(cfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_DLCX, endp->rtp_port);
 | 
							cfg->change_cb(cfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_DLCX, endp->rtp_port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (silent)
 | 
				
			||||||
 | 
							goto out_silent;
 | 
				
			||||||
	return create_response(250, "DLCX", trans_id);
 | 
						return create_response(250, "DLCX", trans_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
error:
 | 
					error:
 | 
				
			||||||
@@ -661,6 +685,9 @@ error:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
error3:
 | 
					error3:
 | 
				
			||||||
	return create_response(error_code, "DLCX", trans_id);
 | 
						return create_response(error_code, "DLCX", trans_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					out_silent:
 | 
				
			||||||
 | 
						return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct msgb *handle_rsip(struct mgcp_config *cfg, struct msgb *msg)
 | 
					static struct msgb *handle_rsip(struct mgcp_config *cfg, struct msgb *msg)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										216
									
								
								openbsc/src/nat/bsc_filter.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										216
									
								
								openbsc/src/nat/bsc_filter.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,216 @@
 | 
				
			|||||||
 | 
					/* BSC Multiplexer/NAT */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
 | 
				
			||||||
 | 
					 * (C) 2010 by On-Waves
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <openbsc/bsc_nat.h>
 | 
				
			||||||
 | 
					#include <openbsc/bssap.h>
 | 
				
			||||||
 | 
					#include <openbsc/ipaccess.h>
 | 
				
			||||||
 | 
					#include <openbsc/debug.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/talloc.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sccp/sccp.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * The idea is to have a simple struct describing a IPA packet with
 | 
				
			||||||
 | 
					 * SCCP SSN and the GSM 08.08 payload and decide. We will both have
 | 
				
			||||||
 | 
					 * a white and a blacklist of packets we want to handle.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * TODO: Implement a "NOT" in the filter language.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ALLOW_ANY -1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define FILTER_TO_BSC	1
 | 
				
			||||||
 | 
					#define FILTER_TO_MSC	2
 | 
				
			||||||
 | 
					#define FILTER_TO_BOTH	3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_pkt_filter {
 | 
				
			||||||
 | 
						int ipa_proto;
 | 
				
			||||||
 | 
						int dest_ssn;
 | 
				
			||||||
 | 
						int bssap;
 | 
				
			||||||
 | 
						int gsm;
 | 
				
			||||||
 | 
						int filter_dir;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct bsc_pkt_filter black_list[] = {
 | 
				
			||||||
 | 
						/* filter reset messages to the MSC */
 | 
				
			||||||
 | 
						{ IPAC_PROTO_SCCP, SCCP_SSN_BSSAP, 0, BSS_MAP_MSG_RESET, FILTER_TO_MSC },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* filter reset ack messages to the BSC */
 | 
				
			||||||
 | 
						{ IPAC_PROTO_SCCP, SCCP_SSN_BSSAP, 0, BSS_MAP_MSG_RESET_ACKNOWLEDGE, FILTER_TO_BSC },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* filter ip access */
 | 
				
			||||||
 | 
						{ IPAC_PROTO_IPACCESS, ALLOW_ANY, ALLOW_ANY, ALLOW_ANY, FILTER_TO_MSC },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct bsc_pkt_filter white_list[] = {
 | 
				
			||||||
 | 
						/* allow IPAC_PROTO_SCCP messages to both sides */
 | 
				
			||||||
 | 
						{ IPAC_PROTO_SCCP, ALLOW_ANY, ALLOW_ANY, ALLOW_ANY, FILTER_TO_BOTH },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* allow MGCP messages to both sides */
 | 
				
			||||||
 | 
						{ NAT_IPAC_PROTO_MGCP, ALLOW_ANY, ALLOW_ANY, ALLOW_ANY, FILTER_TO_BOTH },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_nat_parsed* bsc_nat_parse(struct msgb *msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_parse_result result;
 | 
				
			||||||
 | 
						struct bsc_nat_parsed *parsed;
 | 
				
			||||||
 | 
						struct ipaccess_head *hh;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* quick fail */
 | 
				
			||||||
 | 
						if (msg->len < 4)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						parsed = talloc_zero(msg, struct bsc_nat_parsed);
 | 
				
			||||||
 | 
						if (!parsed)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* more init */
 | 
				
			||||||
 | 
						parsed->ipa_proto = parsed->called_ssn = parsed->calling_ssn = -1;
 | 
				
			||||||
 | 
						parsed->sccp_type = parsed->bssap = parsed->gsm_type = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* start parsing */
 | 
				
			||||||
 | 
						hh = (struct ipaccess_head *) msg->data;
 | 
				
			||||||
 | 
						parsed->ipa_proto = hh->proto;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg->l2h = &hh->data[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* do a size check on the input */
 | 
				
			||||||
 | 
						if (ntohs(hh->len) != msgb_l2len(msg)) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Wrong input length?\n");
 | 
				
			||||||
 | 
							talloc_free(parsed);
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* analyze sccp down here */
 | 
				
			||||||
 | 
						if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
 | 
				
			||||||
 | 
							memset(&result, 0, sizeof(result));
 | 
				
			||||||
 | 
							if (sccp_parse_header(msg, &result) != 0) {
 | 
				
			||||||
 | 
								talloc_free(parsed);
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (msg->l3h && msgb_l3len(msg) < 3) {
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_ERROR, "Not enough space or GSM payload\n");
 | 
				
			||||||
 | 
								talloc_free(parsed);
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							parsed->sccp_type = sccp_determine_msg_type(msg);
 | 
				
			||||||
 | 
							parsed->src_local_ref = result.source_local_reference;
 | 
				
			||||||
 | 
							parsed->dest_local_ref = result.destination_local_reference;
 | 
				
			||||||
 | 
							parsed->called_ssn = result.called.ssn;
 | 
				
			||||||
 | 
							parsed->calling_ssn = result.calling.ssn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* in case of connection confirm we have no payload */
 | 
				
			||||||
 | 
							if (msg->l3h) {
 | 
				
			||||||
 | 
								parsed->bssap = msg->l3h[0];
 | 
				
			||||||
 | 
								parsed->gsm_type = msg->l3h[2];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return parsed;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_nat_filter_ipa(int dir, struct msgb *msg, struct bsc_nat_parsed *parsed)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* go through the blacklist now */
 | 
				
			||||||
 | 
						for (i = 0; i < ARRAY_SIZE(black_list); ++i) {
 | 
				
			||||||
 | 
							/* ignore the rule? */
 | 
				
			||||||
 | 
							if (black_list[i].filter_dir != FILTER_TO_BOTH
 | 
				
			||||||
 | 
							    && black_list[i].filter_dir != dir)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* the proto is not blacklisted */
 | 
				
			||||||
 | 
							if (black_list[i].ipa_proto != ALLOW_ANY
 | 
				
			||||||
 | 
							    && black_list[i].ipa_proto != parsed->ipa_proto)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
 | 
				
			||||||
 | 
								/* the SSN is not blacklisted */
 | 
				
			||||||
 | 
								if (black_list[i].dest_ssn != ALLOW_ANY
 | 
				
			||||||
 | 
								    && black_list[i].dest_ssn != parsed->called_ssn)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/* bssap */
 | 
				
			||||||
 | 
								if (black_list[i].bssap != ALLOW_ANY
 | 
				
			||||||
 | 
								    && black_list[i].bssap != parsed->bssap)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/* gsm */
 | 
				
			||||||
 | 
								if (black_list[i].gsm != ALLOW_ANY
 | 
				
			||||||
 | 
								    && black_list[i].gsm != parsed->gsm_type)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/* blacklisted */
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_INFO, "Blacklisted with rule %d\n", i);
 | 
				
			||||||
 | 
								return 1;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								/* blacklisted, we have no content sniffing yet */
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_INFO, "Blacklisted with rule %d\n", i);
 | 
				
			||||||
 | 
								return 1;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* go through the whitelust now */
 | 
				
			||||||
 | 
						for (i = 0; i < ARRAY_SIZE(white_list); ++i) {
 | 
				
			||||||
 | 
							/* ignore the rule? */
 | 
				
			||||||
 | 
							if (white_list[i].filter_dir != FILTER_TO_BOTH
 | 
				
			||||||
 | 
							    && white_list[i].filter_dir != dir)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* the proto is not whitelisted */
 | 
				
			||||||
 | 
							if (white_list[i].ipa_proto != ALLOW_ANY
 | 
				
			||||||
 | 
							    && white_list[i].ipa_proto != parsed->ipa_proto)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
 | 
				
			||||||
 | 
								/* the SSN is not whitelisted */
 | 
				
			||||||
 | 
								if (white_list[i].dest_ssn != ALLOW_ANY
 | 
				
			||||||
 | 
								    && white_list[i].dest_ssn != parsed->called_ssn)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/* bssap */
 | 
				
			||||||
 | 
								if (white_list[i].bssap != ALLOW_ANY
 | 
				
			||||||
 | 
								    && white_list[i].bssap != parsed->bssap)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/* gsm */
 | 
				
			||||||
 | 
								if (white_list[i].gsm != ALLOW_ANY
 | 
				
			||||||
 | 
								    && white_list[i].gsm != parsed->gsm_type)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/* whitelisted */
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_INFO, "Whitelisted with rule %d\n", i);
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								/* whitelisted */
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										559
									
								
								openbsc/src/nat/bsc_mgcp_utils.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										559
									
								
								openbsc/src/nat/bsc_mgcp_utils.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,559 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
 | 
				
			||||||
 | 
					 * (C) 2010 by On-Waves
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <openbsc/bsc_nat.h>
 | 
				
			||||||
 | 
					#include <openbsc/gsm_data.h>
 | 
				
			||||||
 | 
					#include <openbsc/bssap.h>
 | 
				
			||||||
 | 
					#include <openbsc/debug.h>
 | 
				
			||||||
 | 
					#include <openbsc/mgcp.h>
 | 
				
			||||||
 | 
					#include <openbsc/mgcp_internal.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sccp/sccp.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/talloc.h>
 | 
				
			||||||
 | 
					#include <osmocore/gsm0808.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <netinet/in.h>
 | 
				
			||||||
 | 
					#include <arpa/inet.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <errno.h>
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_mgcp_assign(struct sccp_connections *con, struct msgb *msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connections *mcon;
 | 
				
			||||||
 | 
						struct tlv_parsed tp;
 | 
				
			||||||
 | 
						u_int16_t cic;
 | 
				
			||||||
 | 
						u_int8_t timeslot;
 | 
				
			||||||
 | 
						u_int8_t multiplex;
 | 
				
			||||||
 | 
						int combined;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!msg->l3h) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Assignment message should have l3h pointer.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (msgb_l3len(msg) < 3) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Assignment message has not enough space for GSM0808.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 3, msgb_l3len(msg) - 3, 0, 0);
 | 
				
			||||||
 | 
						if (!TLVP_PRESENT(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Circuit identity code not found in assignment message.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cic = ntohs(*(u_int16_t *)TLVP_VAL(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE));
 | 
				
			||||||
 | 
						timeslot = cic & 0x1f;
 | 
				
			||||||
 | 
						multiplex = (cic & ~0x1f) >> 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						combined = (32 * multiplex) + timeslot;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* find stale connections using that endpoint */
 | 
				
			||||||
 | 
						llist_for_each_entry(mcon, &con->bsc->nat->sccp_connections, list_entry) {
 | 
				
			||||||
 | 
							if (mcon->msc_timeslot == combined) {
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_ERROR,
 | 
				
			||||||
 | 
								     "Timeslot %d was assigned to 0x%x and now 0x%x\n",
 | 
				
			||||||
 | 
								     combined,
 | 
				
			||||||
 | 
								     sccp_src_ref_to_int(&mcon->patched_ref),
 | 
				
			||||||
 | 
								     sccp_src_ref_to_int(&con->patched_ref));
 | 
				
			||||||
 | 
								bsc_mgcp_dlcx(mcon);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						con->msc_timeslot = combined;
 | 
				
			||||||
 | 
						con->bsc_timeslot = con->msc_timeslot;
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void bsc_mgcp_free_endpoint(struct bsc_nat *nat, int i)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (nat->bsc_endpoints[i].transaction_id) {
 | 
				
			||||||
 | 
							talloc_free(nat->bsc_endpoints[i].transaction_id);
 | 
				
			||||||
 | 
							nat->bsc_endpoints[i].transaction_id = NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat->bsc_endpoints[i].bsc = NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bsc_mgcp_free_endpoints(struct bsc_nat *nat)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 1; i < nat->mgcp_cfg->number_endpoints; ++i){
 | 
				
			||||||
 | 
							bsc_mgcp_free_endpoint(nat, i);
 | 
				
			||||||
 | 
							mgcp_free_endp(&nat->mgcp_cfg->endpoints[i]);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* send a MDCX where we do not want a response */
 | 
				
			||||||
 | 
					static void bsc_mgcp_send_mdcx(struct bsc_connection *bsc, struct mgcp_endpoint *endp)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char buf[2096];
 | 
				
			||||||
 | 
						int len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						len = snprintf(buf, sizeof(buf),
 | 
				
			||||||
 | 
							       "MDCX 23 %x@mgw MGCP 1.0\r\n"
 | 
				
			||||||
 | 
							       "Z: noanswer\r\n"
 | 
				
			||||||
 | 
							       "\r\n"
 | 
				
			||||||
 | 
							       "c=IN IP4 %s\r\n"
 | 
				
			||||||
 | 
							       "m=audio %d RTP/AVP 255\r\n",
 | 
				
			||||||
 | 
							       ENDPOINT_NUMBER(endp),
 | 
				
			||||||
 | 
							       bsc->nat->mgcp_cfg->source_addr,
 | 
				
			||||||
 | 
							       endp->rtp_port);
 | 
				
			||||||
 | 
						if (len < 0) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "snprintf for DLCX failed.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void bsc_mgcp_send_dlcx(struct bsc_connection *bsc, int endpoint)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char buf[2096];
 | 
				
			||||||
 | 
						int len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						len = snprintf(buf, sizeof(buf),
 | 
				
			||||||
 | 
							       "DLCX 23 %x@mgw MGCP 1.0\r\n"
 | 
				
			||||||
 | 
							       "Z: noanswer\r\n", endpoint);
 | 
				
			||||||
 | 
						if (len < 0) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "snprintf for DLCX failed.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_write_mgcp(bsc, (u_int8_t *) buf, len);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bsc_mgcp_init(struct sccp_connections *con)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						con->msc_timeslot = -1;
 | 
				
			||||||
 | 
						con->bsc_timeslot = -1;
 | 
				
			||||||
 | 
						con->crcx = 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bsc_mgcp_dlcx(struct sccp_connections *con)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						/* send a DLCX down the stream */
 | 
				
			||||||
 | 
						if (con->bsc_timeslot != -1 && con->crcx) {
 | 
				
			||||||
 | 
							int endp = mgcp_timeslot_to_endpoint(0, con->msc_timeslot);
 | 
				
			||||||
 | 
							bsc_mgcp_send_dlcx(con->bsc, endp);
 | 
				
			||||||
 | 
							bsc_mgcp_free_endpoint(con->bsc->nat, endp);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_mgcp_init(con);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct sccp_connections *bsc_mgcp_find_con(struct bsc_nat *nat, int endpoint)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connections *con = NULL;
 | 
				
			||||||
 | 
						struct sccp_connections *sccp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(sccp, &nat->sccp_connections, list_entry) {
 | 
				
			||||||
 | 
							if (sccp->msc_timeslot == -1)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if (mgcp_timeslot_to_endpoint(0, sccp->msc_timeslot) != endpoint)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							con = sccp;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (con)
 | 
				
			||||||
 | 
							return con;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DMGCP, LOGL_ERROR, "Failed to find the connection.\n");
 | 
				
			||||||
 | 
						return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_mgcp_policy_cb(struct mgcp_config *cfg, int endpoint, int state, const char *transaction_id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_nat *nat;
 | 
				
			||||||
 | 
						struct bsc_endpoint *bsc_endp;
 | 
				
			||||||
 | 
						struct sccp_connections *sccp;
 | 
				
			||||||
 | 
						struct mgcp_endpoint *mgcp_endp;
 | 
				
			||||||
 | 
						struct msgb *bsc_msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat = cfg->data;
 | 
				
			||||||
 | 
						bsc_endp = &nat->bsc_endpoints[endpoint];
 | 
				
			||||||
 | 
						mgcp_endp = &nat->mgcp_cfg->endpoints[endpoint];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc_endp->transaction_id) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Endpoint 0x%x had pending transaction: '%s'\n",
 | 
				
			||||||
 | 
							     endpoint, bsc_endp->transaction_id);
 | 
				
			||||||
 | 
							talloc_free(bsc_endp->transaction_id);
 | 
				
			||||||
 | 
							bsc_endp->transaction_id = NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						bsc_endp->bsc = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sccp = bsc_mgcp_find_con(nat, endpoint);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!sccp) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Did not find BSC for change on endpoint: 0x%x state: %d\n", endpoint, state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							switch (state) {
 | 
				
			||||||
 | 
							case MGCP_ENDP_CRCX:
 | 
				
			||||||
 | 
								return MGCP_POLICY_REJECT;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case MGCP_ENDP_DLCX:
 | 
				
			||||||
 | 
								return MGCP_POLICY_CONT;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case MGCP_ENDP_MDCX:
 | 
				
			||||||
 | 
								return MGCP_POLICY_CONT;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								LOGP(DMGCP, LOGL_FATAL, "Unhandled state: %d\n", state);
 | 
				
			||||||
 | 
								return MGCP_POLICY_CONT;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* we need to generate a new and patched message */
 | 
				
			||||||
 | 
						bsc_msg = bsc_mgcp_rewrite((char *) nat->mgcp_msg, nat->mgcp_length,
 | 
				
			||||||
 | 
									   nat->mgcp_cfg->source_addr, mgcp_endp->rtp_port);
 | 
				
			||||||
 | 
						if (!bsc_msg) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to patch the msg.\n");
 | 
				
			||||||
 | 
							return MGCP_POLICY_CONT;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_endp->transaction_id = talloc_strdup(nat, transaction_id);
 | 
				
			||||||
 | 
						bsc_endp->bsc = sccp->bsc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* we need to update some bits */
 | 
				
			||||||
 | 
						if (state == MGCP_ENDP_CRCX) {
 | 
				
			||||||
 | 
							struct sockaddr_in sock;
 | 
				
			||||||
 | 
							socklen_t len = sizeof(sock);
 | 
				
			||||||
 | 
							if (getpeername(sccp->bsc->write_queue.bfd.fd, (struct sockaddr *) &sock, &len) != 0) {
 | 
				
			||||||
 | 
								LOGP(DMGCP, LOGL_ERROR, "Can not get the peername...%d/%s\n",
 | 
				
			||||||
 | 
								      errno, strerror(errno));
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								mgcp_endp->bts = sock.sin_addr;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* send the message and a fake MDCX for force sending of a dummy packet */
 | 
				
			||||||
 | 
							sccp->crcx = 1;
 | 
				
			||||||
 | 
							bsc_write(sccp->bsc, bsc_msg, NAT_IPAC_PROTO_MGCP);
 | 
				
			||||||
 | 
							bsc_mgcp_send_mdcx(sccp->bsc, mgcp_endp);
 | 
				
			||||||
 | 
							return MGCP_POLICY_DEFER;
 | 
				
			||||||
 | 
						} else if (state == MGCP_ENDP_DLCX) {
 | 
				
			||||||
 | 
							/* we will free the endpoint now and send a DLCX to the BSC */
 | 
				
			||||||
 | 
							msgb_free(bsc_msg);
 | 
				
			||||||
 | 
							bsc_mgcp_dlcx(sccp);
 | 
				
			||||||
 | 
							return MGCP_POLICY_CONT;
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							bsc_write(sccp->bsc, bsc_msg, NAT_IPAC_PROTO_MGCP);
 | 
				
			||||||
 | 
							return MGCP_POLICY_DEFER;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * We have received a msg from the BSC. We will see if we know
 | 
				
			||||||
 | 
					 * this transaction and if it belongs to the BSC. Then we will
 | 
				
			||||||
 | 
					 * need to patch the content to point to the local network and we
 | 
				
			||||||
 | 
					 * need to update the I: that was assigned by the BSS.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct msgb *output;
 | 
				
			||||||
 | 
						struct bsc_endpoint *bsc_endp = NULL;
 | 
				
			||||||
 | 
						struct mgcp_endpoint *endp = NULL;
 | 
				
			||||||
 | 
						int i, code;
 | 
				
			||||||
 | 
						char transaction_id[60];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Some assumption that our buffer is big enough.. and null terminate */
 | 
				
			||||||
 | 
						if (msgb_l2len(msg) > 2000) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "MGCP message too long.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg->l2h[msgb_l2len(msg)] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc_mgcp_parse_response((const char *) msg->l2h, &code, transaction_id) != 0) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to parse response code.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 1; i < bsc->nat->mgcp_cfg->number_endpoints; ++i) {
 | 
				
			||||||
 | 
							if (bsc->nat->bsc_endpoints[i].bsc != bsc)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							/* no one listening? a bug? */
 | 
				
			||||||
 | 
							if (!bsc->nat->bsc_endpoints[i].transaction_id)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if (strcmp(transaction_id, bsc->nat->bsc_endpoints[i].transaction_id) != 0)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							endp = &bsc->nat->mgcp_cfg->endpoints[i];
 | 
				
			||||||
 | 
							bsc_endp = &bsc->nat->bsc_endpoints[i];
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!bsc_endp) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Could not find active endpoint: %s for msg: '%s'\n",
 | 
				
			||||||
 | 
							     transaction_id, (const char *) msg->l2h);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						endp->ci = bsc_mgcp_extract_ci((const char *) msg->l2h);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* free some stuff */
 | 
				
			||||||
 | 
						talloc_free(bsc_endp->transaction_id);
 | 
				
			||||||
 | 
						bsc_endp->transaction_id = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * rewrite the information. In case the endpoint was deleted
 | 
				
			||||||
 | 
						 * there should be nothing for us to rewrite so putting endp->rtp_port
 | 
				
			||||||
 | 
						 * with the value of 0 should be no problem.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						output = bsc_mgcp_rewrite((char * ) msg->l2h, msgb_l2len(msg),
 | 
				
			||||||
 | 
									  bsc->nat->mgcp_cfg->source_addr, endp->rtp_port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!output) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to rewrite MGCP msg.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (write_queue_enqueue(&bsc->nat->mgcp_queue, output) != 0) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to queue MGCP msg.\n");
 | 
				
			||||||
 | 
							msgb_free(output);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						/* we want to parse two strings */
 | 
				
			||||||
 | 
						return sscanf(str, "%3d %59s\n", code, transaction) != 2;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_mgcp_extract_ci(const char *str)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int ci;
 | 
				
			||||||
 | 
						char *res = strstr(str, "I: ");
 | 
				
			||||||
 | 
						if (!res)
 | 
				
			||||||
 | 
							return CI_UNUSED;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (sscanf(res, "I: %d", &ci) != 1)
 | 
				
			||||||
 | 
							return CI_UNUSED;
 | 
				
			||||||
 | 
						return ci;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* we need to replace some strings... */
 | 
				
			||||||
 | 
					struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static const char *ip_str = "c=IN IP4 ";
 | 
				
			||||||
 | 
						static const char *aud_str = "m=audio ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						char buf[128];
 | 
				
			||||||
 | 
						char *running, *token;
 | 
				
			||||||
 | 
						struct msgb *output;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (length > 4096 - 128) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Input is too long.\n");
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						output = msgb_alloc_headroom(4096, 128, "MGCP rewritten");
 | 
				
			||||||
 | 
						if (!output) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to allocate new MGCP msg.\n");
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						running = input;
 | 
				
			||||||
 | 
						output->l2h = output->data;
 | 
				
			||||||
 | 
						for (token = strsep(&running, "\n"); running; token = strsep(&running, "\n")) {
 | 
				
			||||||
 | 
							int len = strlen(token);
 | 
				
			||||||
 | 
							int cr = len > 0 && token[len - 1] == '\r';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (strncmp(ip_str, token, (sizeof ip_str) - 1) == 0) {
 | 
				
			||||||
 | 
								output->l3h = msgb_put(output, strlen(ip_str));
 | 
				
			||||||
 | 
								memcpy(output->l3h, ip_str, strlen(ip_str));
 | 
				
			||||||
 | 
								output->l3h = msgb_put(output, strlen(ip));
 | 
				
			||||||
 | 
								memcpy(output->l3h, ip, strlen(ip));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (cr) {
 | 
				
			||||||
 | 
									output->l3h = msgb_put(output, 2);
 | 
				
			||||||
 | 
									output->l3h[0] = '\r';
 | 
				
			||||||
 | 
									output->l3h[1] = '\n';
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									output->l3h = msgb_put(output, 1);
 | 
				
			||||||
 | 
									output->l3h[0] = '\n';
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else if (strncmp(aud_str, token, (sizeof aud_str) - 1) == 0) {
 | 
				
			||||||
 | 
								int payload;
 | 
				
			||||||
 | 
								if (sscanf(token, "m=audio %*d RTP/AVP %d", &payload) != 1) {
 | 
				
			||||||
 | 
									LOGP(DMGCP, LOGL_ERROR, "Could not parsed audio line.\n");
 | 
				
			||||||
 | 
									msgb_free(output);
 | 
				
			||||||
 | 
									return NULL;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								snprintf(buf, sizeof(buf)-1, "m=audio %d RTP/AVP %d%s",
 | 
				
			||||||
 | 
									 port, payload, cr ? "\r\n" : "\n");
 | 
				
			||||||
 | 
								buf[sizeof(buf)-1] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								output->l3h = msgb_put(output, strlen(buf));
 | 
				
			||||||
 | 
								memcpy(output->l3h, buf, strlen(buf));
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								output->l3h = msgb_put(output, len + 1);
 | 
				
			||||||
 | 
								memcpy(output->l3h, token, len);
 | 
				
			||||||
 | 
								output->l3h[len] = '\n';
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return output;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int mgcp_do_read(struct bsc_fd *fd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_nat *nat;
 | 
				
			||||||
 | 
						struct msgb *msg, *resp;
 | 
				
			||||||
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat = fd->data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rc = read(fd->fd, nat->mgcp_msg, sizeof(nat->mgcp_msg) - 1);
 | 
				
			||||||
 | 
						if (rc <= 0) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to read errno: %d\n", errno);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat->mgcp_msg[rc] = '\0';
 | 
				
			||||||
 | 
						nat->mgcp_length = rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg = msgb_alloc(sizeof(nat->mgcp_msg), "MGCP GW Read");
 | 
				
			||||||
 | 
						if (!msg) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to create buffer.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg->l2h = msgb_put(msg, rc);
 | 
				
			||||||
 | 
						memcpy(msg->l2h, nat->mgcp_msg, msgb_l2len(msg));
 | 
				
			||||||
 | 
						resp = mgcp_handle_message(nat->mgcp_cfg, msg);
 | 
				
			||||||
 | 
						msgb_free(msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* we do have a direct answer... e.g. AUEP */
 | 
				
			||||||
 | 
						if (resp) {
 | 
				
			||||||
 | 
							if (write_queue_enqueue(&nat->mgcp_queue, resp) != 0) {
 | 
				
			||||||
 | 
								LOGP(DMGCP, LOGL_ERROR, "Failed to enqueue msg.\n");
 | 
				
			||||||
 | 
								msgb_free(resp);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int mgcp_do_write(struct bsc_fd *bfd, struct msgb *msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rc = write(bfd->fd, msg->data, msg->len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (rc != msg->len) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to write msg to MGCP CallAgent.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return rc;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_mgcp_nat_init(struct bsc_nat *nat)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int on;
 | 
				
			||||||
 | 
						struct sockaddr_in addr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!nat->mgcp_cfg->call_agent_addr) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "The BSC nat requires the call agent ip to be set.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (nat->mgcp_cfg->bts_ip) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Do not set the BTS ip for the nat.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat->mgcp_queue.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0);
 | 
				
			||||||
 | 
						if (nat->mgcp_queue.bfd.fd < 0) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to create MGCP socket. errno: %d\n", errno);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						on = 1;
 | 
				
			||||||
 | 
						setsockopt(nat->mgcp_queue.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						addr.sin_family = AF_INET;
 | 
				
			||||||
 | 
						addr.sin_port = htons(nat->mgcp_cfg->source_port);
 | 
				
			||||||
 | 
						inet_aton(nat->mgcp_cfg->source_addr, &addr.sin_addr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bind(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to bind. errno: %d\n", errno);
 | 
				
			||||||
 | 
							close(nat->mgcp_queue.bfd.fd);
 | 
				
			||||||
 | 
							nat->mgcp_queue.bfd.fd = -1;
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						addr.sin_port = htons(2727);
 | 
				
			||||||
 | 
						inet_aton(nat->mgcp_cfg->call_agent_addr, &addr.sin_addr);
 | 
				
			||||||
 | 
						if (connect(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to connect to: '%s'. errno: %d\n",
 | 
				
			||||||
 | 
							     nat->mgcp_cfg->call_agent_addr, errno);
 | 
				
			||||||
 | 
							close(nat->mgcp_queue.bfd.fd);
 | 
				
			||||||
 | 
							nat->mgcp_queue.bfd.fd = -1;
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						write_queue_init(&nat->mgcp_queue, 10);
 | 
				
			||||||
 | 
						nat->mgcp_queue.bfd.when = BSC_FD_READ;
 | 
				
			||||||
 | 
						nat->mgcp_queue.bfd.data = nat;
 | 
				
			||||||
 | 
						nat->mgcp_queue.read_cb = mgcp_do_read;
 | 
				
			||||||
 | 
						nat->mgcp_queue.write_cb = mgcp_do_write;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc_register_fd(&nat->mgcp_queue.bfd) != 0) {
 | 
				
			||||||
 | 
							LOGP(DMGCP, LOGL_ERROR, "Failed to register MGCP fd.\n");
 | 
				
			||||||
 | 
							close(nat->mgcp_queue.bfd.fd);
 | 
				
			||||||
 | 
							nat->mgcp_queue.bfd.fd = -1;
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* some more MGCP config handling */
 | 
				
			||||||
 | 
						nat->mgcp_cfg->audio_payload = -1;
 | 
				
			||||||
 | 
						nat->mgcp_cfg->data = nat;
 | 
				
			||||||
 | 
						nat->mgcp_cfg->policy_cb = bsc_mgcp_policy_cb;
 | 
				
			||||||
 | 
						nat->mgcp_cfg->force_realloc = 1;
 | 
				
			||||||
 | 
						nat->mgcp_cfg->bts_ip = "";
 | 
				
			||||||
 | 
						nat->bsc_endpoints = talloc_zero_array(nat,
 | 
				
			||||||
 | 
										       struct bsc_endpoint,
 | 
				
			||||||
 | 
										       nat->mgcp_cfg->number_endpoints + 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
						for (i = 1; i < bsc->nat->mgcp_cfg->number_endpoints; ++i) {
 | 
				
			||||||
 | 
							struct bsc_endpoint *bsc_endp = &bsc->nat->bsc_endpoints[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (bsc_endp->bsc != bsc)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							bsc_mgcp_free_endpoint(bsc->nat, i);
 | 
				
			||||||
 | 
							mgcp_free_endp(&bsc->nat->mgcp_cfg->endpoints[i]);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										989
									
								
								openbsc/src/nat/bsc_nat.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										989
									
								
								openbsc/src/nat/bsc_nat.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,989 @@
 | 
				
			|||||||
 | 
					/* BSC Multiplexer/NAT */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
 | 
				
			||||||
 | 
					 * (C) 2010 by On-Waves
 | 
				
			||||||
 | 
					 * (C) 2009 by Harald Welte <laforge@gnumonks.org>
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#include <sys/socket.h>
 | 
				
			||||||
 | 
					#include <netinet/in.h>
 | 
				
			||||||
 | 
					#include <netinet/tcp.h>
 | 
				
			||||||
 | 
					#include <arpa/inet.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <errno.h>
 | 
				
			||||||
 | 
					#include <signal.h>
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include <time.h>
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define _GNU_SOURCE
 | 
				
			||||||
 | 
					#include <getopt.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <openbsc/debug.h>
 | 
				
			||||||
 | 
					#include <openbsc/bsc_msc.h>
 | 
				
			||||||
 | 
					#include <openbsc/bsc_nat.h>
 | 
				
			||||||
 | 
					#include <openbsc/bssap.h>
 | 
				
			||||||
 | 
					#include <openbsc/ipaccess.h>
 | 
				
			||||||
 | 
					#include <openbsc/abis_nm.h>
 | 
				
			||||||
 | 
					#include <openbsc/telnet_interface.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/talloc.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vty/vty.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sccp/sccp.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct log_target *stderr_target;
 | 
				
			||||||
 | 
					static const char *config_file = "bsc-nat.cfg";
 | 
				
			||||||
 | 
					static struct in_addr local_addr;
 | 
				
			||||||
 | 
					static struct bsc_fd bsc_listen;
 | 
				
			||||||
 | 
					static const char *msc_ip = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct bsc_nat *nat;
 | 
				
			||||||
 | 
					static void bsc_send_data(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length, int);
 | 
				
			||||||
 | 
					static void msc_send_reset(struct bsc_msc_connection *con);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_config *conf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(conf, &nat->bsc_configs, entry)
 | 
				
			||||||
 | 
							if (conf->nr == num)
 | 
				
			||||||
 | 
								return conf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * below are stubs we need to link
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
 | 
				
			||||||
 | 
							   struct gsm_nm_state *old_state, struct gsm_nm_state *new_state)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx)
 | 
				
			||||||
 | 
					{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void queue_for_msc(struct bsc_msc_connection *con, struct msgb *msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (write_queue_enqueue(&nat->msc_con->write_queue, msg) != 0) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to enqueue the write.\n");
 | 
				
			||||||
 | 
							msgb_free(msg);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void send_reset_ack(struct bsc_connection *bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static const u_int8_t gsm_reset_ack[] = {
 | 
				
			||||||
 | 
							0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
 | 
				
			||||||
 | 
							0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x03,
 | 
				
			||||||
 | 
							0x00, 0x01, 0x31,
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_send_data(bsc, gsm_reset_ack, sizeof(gsm_reset_ack), IPAC_PROTO_SCCP);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void send_ping(struct bsc_connection *bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static const u_int8_t id_ping[] = {
 | 
				
			||||||
 | 
							IPAC_MSGT_PING,
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_send_data(bsc, id_ping, sizeof(id_ping), IPAC_PROTO_IPACCESS);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void send_pong(struct bsc_connection *bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static const u_int8_t id_pong[] = {
 | 
				
			||||||
 | 
							IPAC_MSGT_PONG,
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_send_data(bsc, id_pong, sizeof(id_pong), IPAC_PROTO_IPACCESS);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void bsc_pong_timeout(void *_bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_connection *bsc = _bsc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DNAT, LOGL_ERROR, "BSC Nr: %d PONG timeout.\n", bsc->cfg->nr);
 | 
				
			||||||
 | 
						bsc_close_connection(bsc);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void bsc_ping_timeout(void *_bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_connection *bsc = _bsc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc->nat->ping_timeout < 0)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						send_ping(bsc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* send another ping in 20 seconds */
 | 
				
			||||||
 | 
						bsc_schedule_timer(&bsc->ping_timeout, bsc->nat->ping_timeout, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* also start a pong timer */
 | 
				
			||||||
 | 
						bsc_schedule_timer(&bsc->pong_timeout, bsc->nat->pong_timeout, 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void start_ping_pong(struct bsc_connection *bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						bsc->pong_timeout.data = bsc;
 | 
				
			||||||
 | 
						bsc->pong_timeout.cb = bsc_pong_timeout;
 | 
				
			||||||
 | 
						bsc->ping_timeout.data = bsc;
 | 
				
			||||||
 | 
						bsc->ping_timeout.cb = bsc_ping_timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_ping_timeout(bsc);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void send_id_ack(struct bsc_connection *bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static const u_int8_t id_ack[] = {
 | 
				
			||||||
 | 
							IPAC_MSGT_ID_ACK
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_send_data(bsc, id_ack, sizeof(id_ack), IPAC_PROTO_IPACCESS);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void send_id_req(struct bsc_connection *bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static const u_int8_t id_req[] = {
 | 
				
			||||||
 | 
							IPAC_MSGT_ID_GET,
 | 
				
			||||||
 | 
							0x01, IPAC_IDTAG_UNIT,
 | 
				
			||||||
 | 
							0x01, IPAC_IDTAG_MACADDR,
 | 
				
			||||||
 | 
							0x01, IPAC_IDTAG_LOCATION1,
 | 
				
			||||||
 | 
							0x01, IPAC_IDTAG_LOCATION2,
 | 
				
			||||||
 | 
							0x01, IPAC_IDTAG_EQUIPVERS,
 | 
				
			||||||
 | 
							0x01, IPAC_IDTAG_SWVERSION,
 | 
				
			||||||
 | 
							0x01, IPAC_IDTAG_UNITNAME,
 | 
				
			||||||
 | 
							0x01, IPAC_IDTAG_SERNR,
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_send_data(bsc, id_req, sizeof(id_req), IPAC_PROTO_IPACCESS);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void nat_send_rlsd(struct sccp_connections *conn)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connection_released *rel;
 | 
				
			||||||
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg = msgb_alloc_headroom(4096, 128, "rlsd");
 | 
				
			||||||
 | 
						if (!msg) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Failed to allocate clear command.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg->l2h = msgb_put(msg, sizeof(*rel));
 | 
				
			||||||
 | 
						rel = (struct sccp_connection_released *) msg->l2h;
 | 
				
			||||||
 | 
						rel->type = SCCP_MSG_TYPE_RLSD;
 | 
				
			||||||
 | 
						rel->release_cause = SCCP_RELEASE_CAUSE_SCCP_FAILURE;
 | 
				
			||||||
 | 
						rel->destination_local_reference = conn->remote_ref;
 | 
				
			||||||
 | 
						rel->source_local_reference = conn->patched_ref;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ipaccess_prepend_header(msg, IPAC_PROTO_SCCP);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						queue_for_msc(nat->msc_con, msg);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void nat_send_rlc(struct sccp_source_reference *src,
 | 
				
			||||||
 | 
								 struct sccp_source_reference *dst)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connection_release_complete *rlc;
 | 
				
			||||||
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg = msgb_alloc_headroom(4096, 128, "rlc");
 | 
				
			||||||
 | 
						if (!msg) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Failed to allocate clear command.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg->l2h = msgb_put(msg, sizeof(*rlc));
 | 
				
			||||||
 | 
						rlc = (struct sccp_connection_release_complete *) msg->l2h;
 | 
				
			||||||
 | 
						rlc->type = SCCP_MSG_TYPE_RLC;
 | 
				
			||||||
 | 
						rlc->destination_local_reference = *dst;
 | 
				
			||||||
 | 
						rlc->source_local_reference = *src;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ipaccess_prepend_header(msg, IPAC_PROTO_SCCP);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						queue_for_msc(nat->msc_con, msg);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void send_mgcp_reset(struct bsc_connection *bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static const u_int8_t mgcp_reset[] = {
 | 
				
			||||||
 | 
						    "RSIP 1 13@mgw MGCP 1.0\r\n"
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_write_mgcp(bsc, mgcp_reset, sizeof mgcp_reset - 1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Below is the handling of messages coming
 | 
				
			||||||
 | 
					 * from the MSC and need to be forwarded to
 | 
				
			||||||
 | 
					 * a real BSC.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static void initialize_msc_if_needed()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (nat->first_contact)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat->first_contact = 1;
 | 
				
			||||||
 | 
						msc_send_reset(nat->msc_con);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Currently we are lacking refcounting so we need to copy each message.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static void bsc_send_data(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length, int proto)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (length > 4096 - 128) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Can not send message of that size.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg = msgb_alloc_headroom(4096, 128, "to-bsc");
 | 
				
			||||||
 | 
						if (!msg) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to allocate memory for BSC msg.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg->l2h = msgb_put(msg, length);
 | 
				
			||||||
 | 
						memcpy(msg->data, data, length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_write(bsc, msg, proto);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int forward_sccp_to_bts(struct msgb *msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connections *con;
 | 
				
			||||||
 | 
						struct bsc_connection *bsc;
 | 
				
			||||||
 | 
						struct bsc_nat_parsed *parsed;
 | 
				
			||||||
 | 
						int proto;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* filter, drop, patch the message? */
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						if (!parsed) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Can not parse msg from BSC.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc_nat_filter_ipa(DIR_BSC, msg, parsed))
 | 
				
			||||||
 | 
							goto exit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						proto = parsed->ipa_proto;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Route and modify the SCCP packet */
 | 
				
			||||||
 | 
						if (proto == IPAC_PROTO_SCCP) {
 | 
				
			||||||
 | 
							switch (parsed->sccp_type) {
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_UDT:
 | 
				
			||||||
 | 
								/* forward UDT messages to every BSC */
 | 
				
			||||||
 | 
								goto send_to_all;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_RLSD:
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_CREF:
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_DT1:
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_IT:
 | 
				
			||||||
 | 
								con = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
 | 
				
			||||||
 | 
								if (parsed->gsm_type == BSS_MAP_MSG_ASSIGMENT_RQST) {
 | 
				
			||||||
 | 
									counter_inc(nat->stats.sccp.calls);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (con) {
 | 
				
			||||||
 | 
										counter_inc(con->bsc->cfg->stats.sccp.calls);
 | 
				
			||||||
 | 
										if (bsc_mgcp_assign(con, msg) != 0)
 | 
				
			||||||
 | 
											LOGP(DNAT, LOGL_ERROR, "Failed to assign...\n");
 | 
				
			||||||
 | 
									} else
 | 
				
			||||||
 | 
										LOGP(DNAT, LOGL_ERROR, "Assignment command but no BSC.\n");
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_CC:
 | 
				
			||||||
 | 
								con = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
 | 
				
			||||||
 | 
								if (!con || update_sccp_src_ref(con, parsed) != 0)
 | 
				
			||||||
 | 
									goto exit;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_RLC:
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_ERROR, "Unexpected release complete from MSC.\n");
 | 
				
			||||||
 | 
								goto exit;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_CR:
 | 
				
			||||||
 | 
								/* MSC never opens a SCCP connection, fall through */
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								goto exit;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!con && parsed->sccp_type == SCCP_MSG_TYPE_RLSD) {
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_NOTICE, "Sending fake RLC on RLSD message to network.\n");
 | 
				
			||||||
 | 
								/* Exchange src/dest for the reply */
 | 
				
			||||||
 | 
								nat_send_rlc(parsed->dest_local_ref, parsed->src_local_ref);
 | 
				
			||||||
 | 
							} else if (!con)
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_ERROR, "Unknown connection for msg type: 0x%x.\n", parsed->sccp_type);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						talloc_free(parsed);
 | 
				
			||||||
 | 
						if (!con)
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						if (!con->bsc->authenticated) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Selected BSC not authenticated.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_send_data(con->bsc, msg->l2h, msgb_l2len(msg), proto);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					send_to_all:
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Filter Paging from the network. We do not want to send a PAGING
 | 
				
			||||||
 | 
						 * Command to every BSC in our network. We will analys the PAGING
 | 
				
			||||||
 | 
						 * message and then send it to the authenticated messages...
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (parsed->ipa_proto == IPAC_PROTO_SCCP && parsed->gsm_type == BSS_MAP_MSG_PAGING) {
 | 
				
			||||||
 | 
							int lac;
 | 
				
			||||||
 | 
							bsc = bsc_nat_find_bsc(nat, msg, &lac);
 | 
				
			||||||
 | 
							if (bsc && bsc->cfg->forbid_paging)
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_DEBUG, "Paging forbidden for BTS: %d\n", bsc->cfg->nr);
 | 
				
			||||||
 | 
							else if (bsc)
 | 
				
			||||||
 | 
								bsc_send_data(bsc, msg->l2h, msgb_l2len(msg), parsed->ipa_proto);
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_ERROR, "Could not determine BSC for paging on lac: %d/0x%x\n",
 | 
				
			||||||
 | 
								     lac, lac);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							goto exit;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						/* currently send this to every BSC connected */
 | 
				
			||||||
 | 
						llist_for_each_entry(bsc, &nat->bsc_connections, list_entry) {
 | 
				
			||||||
 | 
							if (!bsc->authenticated)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							bsc_send_data(bsc, msg->l2h, msgb_l2len(msg), parsed->ipa_proto);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
						talloc_free(parsed);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void msc_connection_was_lost(struct bsc_msc_connection *con)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_connection *bsc, *tmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						counter_inc(nat->stats.msc.reconn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DMSC, LOGL_ERROR, "Closing all connections downstream.\n");
 | 
				
			||||||
 | 
						llist_for_each_entry_safe(bsc, tmp, &nat->bsc_connections, list_entry)
 | 
				
			||||||
 | 
							bsc_close_connection(bsc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat->first_contact = 0;
 | 
				
			||||||
 | 
						bsc_mgcp_free_endpoints(nat);
 | 
				
			||||||
 | 
						bsc_msc_schedule_connect(con);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void msc_send_reset(struct bsc_msc_connection *msc_con)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static const u_int8_t reset[] = {
 | 
				
			||||||
 | 
							0x00, 0x12, 0xfd,
 | 
				
			||||||
 | 
							0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe,
 | 
				
			||||||
 | 
							0x02, 0x42, 0xfe, 0x06, 0x00, 0x04, 0x30, 0x04,
 | 
				
			||||||
 | 
							0x01, 0x20
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg = msgb_alloc_headroom(4096, 128, "08.08 reset");
 | 
				
			||||||
 | 
						if (!msg) {
 | 
				
			||||||
 | 
							LOGP(DMSC, LOGL_ERROR, "Failed to allocate reset msg.\n");
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg->l2h = msgb_put(msg, sizeof(reset));
 | 
				
			||||||
 | 
						memcpy(msg->l2h, reset, msgb_l2len(msg));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						queue_for_msc(nat->msc_con, msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DMSC, LOGL_NOTICE, "Scheduled GSM0808 reset msg for the MSC.\n");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int ipaccess_msc_read_cb(struct bsc_fd *bfd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int error;
 | 
				
			||||||
 | 
						struct msgb *msg = ipaccess_read_msg(bfd, &error);
 | 
				
			||||||
 | 
						struct ipaccess_head *hh;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!msg) {
 | 
				
			||||||
 | 
							if (error == 0)
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_FATAL, "The connection the MSC was lost, exiting\n");
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_ERROR, "Failed to parse ip access message: %d\n", error);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							bsc_msc_lost(nat->msc_con);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DNAT, LOGL_DEBUG, "MSG from MSC: %s proto: %d\n", hexdump(msg->data, msg->len), msg->l2h[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* handle base message handling */
 | 
				
			||||||
 | 
						hh = (struct ipaccess_head *) msg->data;
 | 
				
			||||||
 | 
						ipaccess_rcvmsg_base(msg, bfd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* initialize the networking. This includes sending a GSM08.08 message */
 | 
				
			||||||
 | 
						if (hh->proto == IPAC_PROTO_IPACCESS && msg->l2h[0] == IPAC_MSGT_ID_ACK)
 | 
				
			||||||
 | 
							initialize_msc_if_needed();
 | 
				
			||||||
 | 
						else if (hh->proto == IPAC_PROTO_SCCP)
 | 
				
			||||||
 | 
							forward_sccp_to_bts(msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msgb_free(msg);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int ipaccess_msc_write_cb(struct bsc_fd *bfd, struct msgb *msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int rc;
 | 
				
			||||||
 | 
						rc = write(bfd->fd, msg->data, msg->len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (rc != msg->len) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Failed to write MSG to MSC.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return rc;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Below is the handling of messages coming
 | 
				
			||||||
 | 
					 * from the BSC and need to be forwarded to
 | 
				
			||||||
 | 
					 * a real BSC.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Remove the connection from the connections list,
 | 
				
			||||||
 | 
					 * remove it from the patching of SCCP header lists
 | 
				
			||||||
 | 
					 * as well. Maybe in the future even close connection..
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void bsc_close_connection(struct bsc_connection *connection)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connections *sccp_patch, *tmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* stop the timeout timer */
 | 
				
			||||||
 | 
						bsc_del_timer(&connection->id_timeout);
 | 
				
			||||||
 | 
						bsc_del_timer(&connection->ping_timeout);
 | 
				
			||||||
 | 
						bsc_del_timer(&connection->pong_timeout);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* remove all SCCP connections */
 | 
				
			||||||
 | 
						llist_for_each_entry_safe(sccp_patch, tmp, &nat->sccp_connections, list_entry) {
 | 
				
			||||||
 | 
							if (sccp_patch->bsc != connection)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (sccp_patch->has_remote_ref)
 | 
				
			||||||
 | 
								nat_send_rlsd(sccp_patch);
 | 
				
			||||||
 | 
							sccp_connection_destroy(sccp_patch);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* close endpoints allocated by this BSC */
 | 
				
			||||||
 | 
						bsc_mgcp_clear_endpoints_for(connection);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_unregister_fd(&connection->write_queue.bfd);
 | 
				
			||||||
 | 
						close(connection->write_queue.bfd.fd);
 | 
				
			||||||
 | 
						write_queue_clear(&connection->write_queue);
 | 
				
			||||||
 | 
						llist_del(&connection->list_entry);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						talloc_free(connection);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void ipaccess_close_bsc(void *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sockaddr_in sock;
 | 
				
			||||||
 | 
						socklen_t len = sizeof(sock);
 | 
				
			||||||
 | 
						struct bsc_connection *conn = data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						getpeername(conn->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
 | 
				
			||||||
 | 
						LOGP(DNAT, LOGL_ERROR, "BSC on %s didn't respond to identity request. Closing.\n",
 | 
				
			||||||
 | 
						     inet_ntoa(sock.sin_addr));
 | 
				
			||||||
 | 
						bsc_close_connection(conn);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void ipaccess_auth_bsc(struct tlv_parsed *tvp, struct bsc_connection *bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_config *conf;
 | 
				
			||||||
 | 
						const char* token = (const char *) TLVP_VAL(tvp, IPAC_IDTAG_UNITNAME);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc->cfg) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Reauth on fd %d bsc nr %d\n",
 | 
				
			||||||
 | 
							     bsc->write_queue.bfd.fd, bsc->cfg->nr);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(conf, &bsc->nat->bsc_configs, entry) {
 | 
				
			||||||
 | 
							if (strcmp(conf->token, token) == 0) {
 | 
				
			||||||
 | 
								counter_inc(conf->stats.net.reconn);
 | 
				
			||||||
 | 
								bsc->authenticated = 1;
 | 
				
			||||||
 | 
								bsc->cfg = conf;
 | 
				
			||||||
 | 
								bsc_del_timer(&bsc->id_timeout);
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_NOTICE, "Authenticated bsc nr: %d lac: %d on fd %d\n",
 | 
				
			||||||
 | 
								     conf->nr, conf->lac, bsc->write_queue.bfd.fd);
 | 
				
			||||||
 | 
								start_ping_pong(bsc);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DNAT, LOGL_ERROR, "No bsc found for token %s on fd: %d.\n", token,
 | 
				
			||||||
 | 
						     bsc->write_queue.bfd.fd);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int forward_sccp_to_msc(struct bsc_connection *bsc, struct msgb *msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connections *con;
 | 
				
			||||||
 | 
						struct bsc_nat_parsed *parsed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Parse and filter messages */
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						if (!parsed) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Can not parse msg from BSC.\n");
 | 
				
			||||||
 | 
							msgb_free(msg);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc_nat_filter_ipa(DIR_MSC, msg, parsed))
 | 
				
			||||||
 | 
							goto exit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * check authentication after filtering to not reject auth
 | 
				
			||||||
 | 
						 * responses coming from the BSC. We have to make sure that
 | 
				
			||||||
 | 
						 * nothing from the exit path will forward things to the MSC
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (!bsc->authenticated) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "BSC is not authenticated.\n");
 | 
				
			||||||
 | 
							msgb_free(msg);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* modify the SCCP entries */
 | 
				
			||||||
 | 
						if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
 | 
				
			||||||
 | 
							switch (parsed->sccp_type) {
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_CR:
 | 
				
			||||||
 | 
								if (create_sccp_src_ref(bsc, msg, parsed) != 0)
 | 
				
			||||||
 | 
									goto exit2;
 | 
				
			||||||
 | 
								con = patch_sccp_src_ref_to_msc(msg, parsed, bsc);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_RLSD:
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_CREF:
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_DT1:
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_CC:
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_IT:
 | 
				
			||||||
 | 
								con = patch_sccp_src_ref_to_msc(msg, parsed, bsc);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_RLC:
 | 
				
			||||||
 | 
								con = patch_sccp_src_ref_to_msc(msg, parsed, bsc);
 | 
				
			||||||
 | 
								remove_sccp_src_ref(bsc, msg, parsed);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case SCCP_MSG_TYPE_UDT:
 | 
				
			||||||
 | 
								/* simply forward everything */
 | 
				
			||||||
 | 
								con = NULL;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_ERROR, "Not forwarding to msc sccp type: 0x%x\n", parsed->sccp_type);
 | 
				
			||||||
 | 
								con = NULL;
 | 
				
			||||||
 | 
								goto exit2;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					        } else if (parsed->ipa_proto == NAT_IPAC_PROTO_MGCP) {
 | 
				
			||||||
 | 
					                bsc_mgcp_forward(bsc, msg);
 | 
				
			||||||
 | 
					                goto exit2;
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Not forwarding unknown stream id: 0x%x\n", parsed->ipa_proto);
 | 
				
			||||||
 | 
							goto exit2;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (con && con->bsc != bsc) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "The connection belongs to a different BTS: input: %d con: %d\n",
 | 
				
			||||||
 | 
							     bsc->cfg->nr, con->bsc->cfg->nr);
 | 
				
			||||||
 | 
							goto exit2;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* send the non-filtered but maybe modified msg */
 | 
				
			||||||
 | 
						queue_for_msc(nat->msc_con, msg);
 | 
				
			||||||
 | 
						talloc_free(parsed);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
						/* if we filter out the reset send an ack to the BSC */
 | 
				
			||||||
 | 
						if (parsed->bssap == 0 && parsed->gsm_type == BSS_MAP_MSG_RESET) {
 | 
				
			||||||
 | 
							send_reset_ack(bsc);
 | 
				
			||||||
 | 
							send_reset_ack(bsc);
 | 
				
			||||||
 | 
						} else if (parsed->ipa_proto == IPAC_PROTO_IPACCESS) {
 | 
				
			||||||
 | 
							/* do we know who is handling this? */
 | 
				
			||||||
 | 
							if (msg->l2h[0] == IPAC_MSGT_ID_RESP) {
 | 
				
			||||||
 | 
								struct tlv_parsed tvp;
 | 
				
			||||||
 | 
								ipaccess_idtag_parse(&tvp,
 | 
				
			||||||
 | 
										     (unsigned char *) msg->l2h + 2,
 | 
				
			||||||
 | 
										     msgb_l2len(msg) - 2);
 | 
				
			||||||
 | 
								if (TLVP_PRESENT(&tvp, IPAC_IDTAG_UNITNAME))
 | 
				
			||||||
 | 
									ipaccess_auth_bsc(&tvp, bsc);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							goto exit2;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit2:
 | 
				
			||||||
 | 
						talloc_free(parsed);
 | 
				
			||||||
 | 
						msgb_free(msg);
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int ipaccess_bsc_read_cb(struct bsc_fd *bfd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int error;
 | 
				
			||||||
 | 
						struct bsc_connection *bsc = bfd->data;
 | 
				
			||||||
 | 
						struct msgb *msg = ipaccess_read_msg(bfd, &error);
 | 
				
			||||||
 | 
						struct ipaccess_head *hh;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!msg) {
 | 
				
			||||||
 | 
							if (error == 0)
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_ERROR,
 | 
				
			||||||
 | 
								     "The connection to the BSC Nr: %d was lost. Cleaning it\n",
 | 
				
			||||||
 | 
								     bsc->cfg ? bsc->cfg->nr : -1);
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_ERROR,
 | 
				
			||||||
 | 
								     "Stream error on BSC Nr: %d. Failed to parse ip access message: %d\n",
 | 
				
			||||||
 | 
								     bsc->cfg ? bsc->cfg->nr : -1, error);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							bsc_close_connection(bsc);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DNAT, LOGL_DEBUG, "MSG from BSC: %s proto: %d\n", hexdump(msg->data, msg->len), msg->l2h[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Handle messages from the BSC */
 | 
				
			||||||
 | 
						hh = (struct ipaccess_head *) msg->data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* stop the pong timeout */
 | 
				
			||||||
 | 
						if (hh->proto == IPAC_PROTO_IPACCESS) {
 | 
				
			||||||
 | 
							if (msg->l2h[0] == IPAC_MSGT_PONG) {
 | 
				
			||||||
 | 
								bsc_del_timer(&bsc->pong_timeout);
 | 
				
			||||||
 | 
								msgb_free(msg);
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							} else if (msg->l2h[0] == IPAC_MSGT_PING) {
 | 
				
			||||||
 | 
								send_pong(bsc);
 | 
				
			||||||
 | 
								msgb_free(msg);
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* FIXME: Currently no PONG is sent to the BSC */
 | 
				
			||||||
 | 
						/* FIXME: Currently no ID ACK is sent to the BSC */
 | 
				
			||||||
 | 
						forward_sccp_to_msc(bsc, msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int ipaccess_bsc_write_cb(struct bsc_fd *bfd, struct msgb *msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rc = write(bfd->fd, msg->data, msg->len);
 | 
				
			||||||
 | 
						if (rc != msg->len)
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Failed to write message to the BSC.\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return rc;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int ipaccess_listen_bsc_cb(struct bsc_fd *bfd, unsigned int what)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_connection *bsc;
 | 
				
			||||||
 | 
						int fd, rc, on;
 | 
				
			||||||
 | 
						struct sockaddr_in sa;
 | 
				
			||||||
 | 
						socklen_t sa_len = sizeof(sa);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!(what & BSC_FD_READ))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd = accept(bfd->fd, (struct sockaddr *) &sa, &sa_len);
 | 
				
			||||||
 | 
						if (fd < 0) {
 | 
				
			||||||
 | 
							perror("accept");
 | 
				
			||||||
 | 
							return fd;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* count the reconnect */
 | 
				
			||||||
 | 
						counter_inc(nat->stats.bsc.reconn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * if we are not connected to a msc... just close the socket
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (!nat->msc_con->is_connected) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_NOTICE, "Disconnecting BSC due lack of MSC connection.\n");
 | 
				
			||||||
 | 
							close(fd);
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						on = 1;
 | 
				
			||||||
 | 
						rc = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
 | 
				
			||||||
 | 
						if (rc != 0)
 | 
				
			||||||
 | 
					                LOGP(DNAT, LOGL_ERROR, "Failed to set TCP_NODELAY: %s\n", strerror(errno));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* todo... do something with the connection */
 | 
				
			||||||
 | 
						/* todo... use GNUtls to see if we want to trust this as a BTS */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						bsc = bsc_connection_alloc(nat);
 | 
				
			||||||
 | 
						if (!bsc) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Failed to allocate BSC struct.\n");
 | 
				
			||||||
 | 
							close(fd);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc->write_queue.bfd.data = bsc;
 | 
				
			||||||
 | 
						bsc->write_queue.bfd.fd = fd;
 | 
				
			||||||
 | 
						bsc->write_queue.read_cb = ipaccess_bsc_read_cb;
 | 
				
			||||||
 | 
						bsc->write_queue.write_cb = ipaccess_bsc_write_cb;
 | 
				
			||||||
 | 
						bsc->write_queue.bfd.when = BSC_FD_READ;
 | 
				
			||||||
 | 
						if (bsc_register_fd(&bsc->write_queue.bfd) < 0) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Failed to register BSC fd.\n");
 | 
				
			||||||
 | 
							close(fd);
 | 
				
			||||||
 | 
							talloc_free(bsc);
 | 
				
			||||||
 | 
							return -2;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DNAT, LOGL_NOTICE, "BSC connection on %d with IP: %s\n",
 | 
				
			||||||
 | 
							fd, inet_ntoa(sa.sin_addr));
 | 
				
			||||||
 | 
						llist_add(&bsc->list_entry, &nat->bsc_connections);
 | 
				
			||||||
 | 
						send_id_ack(bsc);
 | 
				
			||||||
 | 
						send_id_req(bsc);
 | 
				
			||||||
 | 
						send_mgcp_reset(bsc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * start the hangup timer
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						bsc->id_timeout.data = bsc;
 | 
				
			||||||
 | 
						bsc->id_timeout.cb = ipaccess_close_bsc;
 | 
				
			||||||
 | 
						bsc_schedule_timer(&bsc->id_timeout, nat->auth_timeout, 0);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int listen_for_bsc(struct bsc_fd *bfd, struct in_addr *in_addr, int port)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sockaddr_in addr;
 | 
				
			||||||
 | 
						int ret, on = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bfd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 | 
				
			||||||
 | 
						bfd->cb = ipaccess_listen_bsc_cb;
 | 
				
			||||||
 | 
						bfd->when = BSC_FD_READ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memset(&addr, 0, sizeof(addr));
 | 
				
			||||||
 | 
						addr.sin_family = AF_INET;
 | 
				
			||||||
 | 
						addr.sin_port = htons(port);
 | 
				
			||||||
 | 
						addr.sin_addr.s_addr = in_addr->s_addr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = bind(bfd->fd, (struct sockaddr *) &addr, sizeof(addr));
 | 
				
			||||||
 | 
						if (ret < 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Could not bind the BSC socket %s\n",
 | 
				
			||||||
 | 
								strerror(errno));
 | 
				
			||||||
 | 
							return -EIO;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = listen(bfd->fd, 1);
 | 
				
			||||||
 | 
						if (ret < 0) {
 | 
				
			||||||
 | 
							perror("listen");
 | 
				
			||||||
 | 
							return ret;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ret = bsc_register_fd(bfd);
 | 
				
			||||||
 | 
						if (ret < 0) {
 | 
				
			||||||
 | 
							perror("register_listen_fd");
 | 
				
			||||||
 | 
							return ret;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void print_usage()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						printf("Usage: bsc_nat\n");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void print_help()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						printf("  Some useful help...\n");
 | 
				
			||||||
 | 
						printf("  -h --help this text\n");
 | 
				
			||||||
 | 
						printf("  -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
 | 
				
			||||||
 | 
						printf("  -s --disable-color\n");
 | 
				
			||||||
 | 
						printf("  -c --config-file filename The config file to use.\n");
 | 
				
			||||||
 | 
						printf("  -m --msc=IP. The address of the MSC.\n");
 | 
				
			||||||
 | 
						printf("  -l --local=IP. The local address of this BSC.\n");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void handle_options(int argc, char** argv)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						while (1) {
 | 
				
			||||||
 | 
							int option_index = 0, c;
 | 
				
			||||||
 | 
							static struct option long_options[] = {
 | 
				
			||||||
 | 
								{"help", 0, 0, 'h'},
 | 
				
			||||||
 | 
								{"debug", 1, 0, 'd'},
 | 
				
			||||||
 | 
								{"config-file", 1, 0, 'c'},
 | 
				
			||||||
 | 
								{"disable-color", 0, 0, 's'},
 | 
				
			||||||
 | 
								{"timestamp", 0, 0, 'T'},
 | 
				
			||||||
 | 
								{"msc", 1, 0, 'm'},
 | 
				
			||||||
 | 
								{"local", 1, 0, 'l'},
 | 
				
			||||||
 | 
								{0, 0, 0, 0}
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							c = getopt_long(argc, argv, "hd:sTPc:m:l:",
 | 
				
			||||||
 | 
									long_options, &option_index);
 | 
				
			||||||
 | 
							if (c == -1)
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							switch (c) {
 | 
				
			||||||
 | 
							case 'h':
 | 
				
			||||||
 | 
								print_usage();
 | 
				
			||||||
 | 
								print_help();
 | 
				
			||||||
 | 
								exit(0);
 | 
				
			||||||
 | 
							case 's':
 | 
				
			||||||
 | 
								log_set_use_color(stderr_target, 0);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case 'd':
 | 
				
			||||||
 | 
								log_parse_category_mask(stderr_target, optarg);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case 'c':
 | 
				
			||||||
 | 
								config_file = strdup(optarg);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case 'T':
 | 
				
			||||||
 | 
								log_set_print_timestamp(stderr_target, 1);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case 'm':
 | 
				
			||||||
 | 
								msc_ip = optarg;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							case 'l':
 | 
				
			||||||
 | 
								inet_aton(optarg, &local_addr);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								/* ignore */
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void signal_handler(int signal)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						switch (signal) {
 | 
				
			||||||
 | 
						case SIGABRT:
 | 
				
			||||||
 | 
							/* in case of abort, we want to obtain a talloc report
 | 
				
			||||||
 | 
							 * and then return to the caller, who will abort the process */
 | 
				
			||||||
 | 
						case SIGUSR1:
 | 
				
			||||||
 | 
							talloc_report_full(tall_bsc_ctx, stderr);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern void *tall_msgb_ctx;
 | 
				
			||||||
 | 
					extern void *tall_ctr_ctx;
 | 
				
			||||||
 | 
					static void talloc_init_ctx()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						tall_bsc_ctx = talloc_named_const(NULL, 0, "nat");
 | 
				
			||||||
 | 
						tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 0, "msgb");
 | 
				
			||||||
 | 
						tall_ctr_ctx = talloc_named_const(tall_bsc_ctx, 0, "counter");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char** argv)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						talloc_init_ctx();
 | 
				
			||||||
 | 
						log_init(&log_info);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						stderr_target = log_target_create_stderr();
 | 
				
			||||||
 | 
						log_add_target(stderr_target);
 | 
				
			||||||
 | 
						log_set_all_filter(stderr_target, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat = bsc_nat_alloc();
 | 
				
			||||||
 | 
						if (!nat) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to allocate the BSC nat.\n");
 | 
				
			||||||
 | 
							return -4;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat->mgcp_cfg = talloc_zero(nat, struct mgcp_config);
 | 
				
			||||||
 | 
						if (!nat->mgcp_cfg) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to allocate MGCP cfg.\n");
 | 
				
			||||||
 | 
							return -5;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* parse options */
 | 
				
			||||||
 | 
						local_addr.s_addr = INADDR_ANY;
 | 
				
			||||||
 | 
						handle_options(argc, argv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* init vty and parse */
 | 
				
			||||||
 | 
						bsc_nat_vty_init(nat);
 | 
				
			||||||
 | 
						telnet_init(NULL, 4244);
 | 
				
			||||||
 | 
						if (mgcp_parse_config(config_file, nat->mgcp_cfg) < 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
 | 
				
			||||||
 | 
							return -3;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* over rule the VTY config */
 | 
				
			||||||
 | 
						if (msc_ip)
 | 
				
			||||||
 | 
							bsc_nat_set_msc_ip(nat, msc_ip);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* seed the PRNG */
 | 
				
			||||||
 | 
						srand(time(NULL));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * Setup the MGCP code..
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (bsc_mgcp_nat_init(nat) != 0)
 | 
				
			||||||
 | 
							return -4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* connect to the MSC */
 | 
				
			||||||
 | 
						nat->msc_con = bsc_msc_create(nat->msc_ip, nat->msc_port);
 | 
				
			||||||
 | 
						if (!nat->msc_con) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Creating a bsc_msc_connection failed.\n");
 | 
				
			||||||
 | 
							exit(1);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat->msc_con->connection_loss = msc_connection_was_lost;
 | 
				
			||||||
 | 
						nat->msc_con->write_queue.read_cb = ipaccess_msc_read_cb;
 | 
				
			||||||
 | 
						nat->msc_con->write_queue.write_cb = ipaccess_msc_write_cb;;
 | 
				
			||||||
 | 
						bsc_msc_connect(nat->msc_con);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* wait for the BSC */
 | 
				
			||||||
 | 
						if (listen_for_bsc(&bsc_listen, &local_addr, 5000) < 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to listen for BSC.\n");
 | 
				
			||||||
 | 
							exit(1);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						signal(SIGABRT, &signal_handler);
 | 
				
			||||||
 | 
						signal(SIGUSR1, &signal_handler);
 | 
				
			||||||
 | 
						signal(SIGPIPE, SIG_IGN);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (1) {
 | 
				
			||||||
 | 
							bsc_select_main(0);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										195
									
								
								openbsc/src/nat/bsc_nat_utils.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										195
									
								
								openbsc/src/nat/bsc_nat_utils.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,195 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					/* BSC Multiplexer/NAT Utilities */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
 | 
				
			||||||
 | 
					 * (C) 2010 by On-Waves
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <openbsc/bsc_nat.h>
 | 
				
			||||||
 | 
					#include <openbsc/gsm_data.h>
 | 
				
			||||||
 | 
					#include <openbsc/bssap.h>
 | 
				
			||||||
 | 
					#include <openbsc/debug.h>
 | 
				
			||||||
 | 
					#include <openbsc/ipaccess.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/linuxlist.h>
 | 
				
			||||||
 | 
					#include <osmocore/talloc.h>
 | 
				
			||||||
 | 
					#include <osmocore/gsm0808.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sccp/sccp.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <netinet/in.h>
 | 
				
			||||||
 | 
					#include <arpa/inet.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_nat *bsc_nat_alloc(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_nat *nat = talloc_zero(tall_bsc_ctx, struct bsc_nat);
 | 
				
			||||||
 | 
						if (!nat)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						INIT_LLIST_HEAD(&nat->sccp_connections);
 | 
				
			||||||
 | 
						INIT_LLIST_HEAD(&nat->bsc_connections);
 | 
				
			||||||
 | 
						INIT_LLIST_HEAD(&nat->bsc_configs);
 | 
				
			||||||
 | 
						nat->stats.sccp.conn = counter_alloc("nat.sccp.conn");
 | 
				
			||||||
 | 
						nat->stats.sccp.calls = counter_alloc("nat.sccp.calls");
 | 
				
			||||||
 | 
						nat->stats.bsc.reconn = counter_alloc("nat.bsc.conn");
 | 
				
			||||||
 | 
						nat->stats.bsc.auth_fail = counter_alloc("nat.bsc.auth_fail");
 | 
				
			||||||
 | 
						nat->stats.msc.reconn = counter_alloc("nat.msc.conn");
 | 
				
			||||||
 | 
						nat->msc_ip = talloc_strdup(nat, "127.0.0.1");
 | 
				
			||||||
 | 
						nat->msc_port = 5000;
 | 
				
			||||||
 | 
						nat->auth_timeout = 2;
 | 
				
			||||||
 | 
						nat->ping_timeout = 20;
 | 
				
			||||||
 | 
						nat->pong_timeout = 5;
 | 
				
			||||||
 | 
						return nat;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void bsc_nat_set_msc_ip(struct bsc_nat *nat, const char *ip)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (nat->msc_ip)
 | 
				
			||||||
 | 
							talloc_free(nat->msc_ip);
 | 
				
			||||||
 | 
						nat->msc_ip = talloc_strdup(nat, ip);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_connection *con = talloc_zero(nat, struct bsc_connection);
 | 
				
			||||||
 | 
						if (!con)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						con->nat = nat;
 | 
				
			||||||
 | 
						write_queue_init(&con->write_queue, 100);
 | 
				
			||||||
 | 
						return con;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token, unsigned int lac)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_config *conf = talloc_zero(nat, struct bsc_config);
 | 
				
			||||||
 | 
						if (!conf)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						conf->token = talloc_strdup(conf, token);
 | 
				
			||||||
 | 
						conf->lac = lac;
 | 
				
			||||||
 | 
						conf->nr = nat->num_bsc;
 | 
				
			||||||
 | 
						conf->nat = nat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_add_tail(&conf->entry, &nat->bsc_configs);
 | 
				
			||||||
 | 
						++nat->num_bsc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						conf->stats.sccp.conn = counter_alloc("nat.bsc.sccp.conn");
 | 
				
			||||||
 | 
						conf->stats.sccp.calls = counter_alloc("nat.bsc.sccp.calls");
 | 
				
			||||||
 | 
						conf->stats.net.reconn = counter_alloc("nat.bsc.net.reconnects");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return conf;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void sccp_connection_destroy(struct sccp_connections *conn)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						LOGP(DNAT, LOGL_DEBUG, "Destroy 0x%x <-> 0x%x mapping for con %p\n",
 | 
				
			||||||
 | 
						     sccp_src_ref_to_int(&conn->real_ref),
 | 
				
			||||||
 | 
						     sccp_src_ref_to_int(&conn->patched_ref), conn->bsc);
 | 
				
			||||||
 | 
						bsc_mgcp_dlcx(conn);
 | 
				
			||||||
 | 
						llist_del(&conn->list_entry);
 | 
				
			||||||
 | 
						talloc_free(conn);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct bsc_connection *bsc_nat_find_bsc(struct bsc_nat *nat, struct msgb *msg, int *lac_out)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_connection *bsc;
 | 
				
			||||||
 | 
						int data_length;
 | 
				
			||||||
 | 
						const u_int8_t *data;
 | 
				
			||||||
 | 
						struct tlv_parsed tp;
 | 
				
			||||||
 | 
						int i = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						*lac_out = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!msg->l3h || msgb_l3len(msg) < 3) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Paging message is too short.\n");
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 3, msgb_l3len(msg) - 3, 0, 0);
 | 
				
			||||||
 | 
						if (!TLVP_PRESENT(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST)) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "No CellIdentifier List inside paging msg.\n");
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						data_length = TLVP_LEN(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST);
 | 
				
			||||||
 | 
						data = TLVP_VAL(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* No need to try a different BSS */
 | 
				
			||||||
 | 
						if (data[0] == CELL_IDENT_BSS) {
 | 
				
			||||||
 | 
							return NULL;	
 | 
				
			||||||
 | 
						} else if (data[0] != CELL_IDENT_LAC) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Unhandled cell ident discrminator: %d\n", data[0]);
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Currently we only handle one BSC */
 | 
				
			||||||
 | 
						for (i = 1; i < data_length - 1; i += 2) {
 | 
				
			||||||
 | 
							unsigned int _lac = ntohs(*(unsigned int *) &data[i]);
 | 
				
			||||||
 | 
							*lac_out = _lac;
 | 
				
			||||||
 | 
							llist_for_each_entry(bsc, &nat->bsc_connections, list_entry) {
 | 
				
			||||||
 | 
								if (!bsc->cfg)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								if (!bsc->authenticated || _lac != bsc->cfg->lac)
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return bsc;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_write_mgcp(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (length > 4096 - 128) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Can not send message of that size.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg = msgb_alloc_headroom(4096, 128, "to-bsc");
 | 
				
			||||||
 | 
						if (!msg) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to allocate memory for BSC msg.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* copy the data */
 | 
				
			||||||
 | 
						msg->l3h = msgb_put(msg, length);
 | 
				
			||||||
 | 
						memcpy(msg->l3h, data, length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return bsc_write(bsc, msg, NAT_IPAC_PROTO_MGCP);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_write(struct bsc_connection *bsc, struct msgb *msg, int proto)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						/* prepend the header */
 | 
				
			||||||
 | 
						ipaccess_prepend_header(msg, proto);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (write_queue_enqueue(&bsc->write_queue, msg) != 0) {
 | 
				
			||||||
 | 
							LOGP(DINP, LOGL_ERROR, "Failed to enqueue the write.\n");
 | 
				
			||||||
 | 
							msgb_free(msg);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										460
									
								
								openbsc/src/nat/bsc_nat_vty.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										460
									
								
								openbsc/src/nat/bsc_nat_vty.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,460 @@
 | 
				
			|||||||
 | 
					/* OpenBSC NAT interface to quagga VTY */
 | 
				
			||||||
 | 
					/* (C) 2010 by Holger Hans Peter Freyther
 | 
				
			||||||
 | 
					 * (C) 2010 by On-Waves
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vty/command.h>
 | 
				
			||||||
 | 
					#include <vty/buffer.h>
 | 
				
			||||||
 | 
					#include <vty/vty.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <openbsc/bsc_nat.h>
 | 
				
			||||||
 | 
					#include <openbsc/bsc_msc.h>
 | 
				
			||||||
 | 
					#include <openbsc/gsm_04_08.h>
 | 
				
			||||||
 | 
					#include <openbsc/mgcp.h>
 | 
				
			||||||
 | 
					#include <openbsc/vty.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/talloc.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sccp/sccp.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct bsc_nat *_nat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct cmd_node nat_node = {
 | 
				
			||||||
 | 
						NAT_NODE,
 | 
				
			||||||
 | 
						"%s(nat)#",
 | 
				
			||||||
 | 
						1,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct cmd_node bsc_node = {
 | 
				
			||||||
 | 
						BSC_NODE,
 | 
				
			||||||
 | 
						"%s(bsc)#",
 | 
				
			||||||
 | 
						1,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int config_write_nat(struct vty *vty)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						vty_out(vty, "nat%s", VTY_NEWLINE);
 | 
				
			||||||
 | 
						if (_nat->imsi_allow)
 | 
				
			||||||
 | 
							vty_out(vty, " imsi allow %s%s", _nat->imsi_allow, VTY_NEWLINE);
 | 
				
			||||||
 | 
						if (_nat->imsi_deny)
 | 
				
			||||||
 | 
							vty_out(vty, " insi deny %s%s", _nat->imsi_deny, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " msc ip %s%s", _nat->msc_ip, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " msc port %d%s", _nat->msc_port, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " timeout auth %d%s", _nat->auth_timeout, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " timeout ping %d%s", _nat->ping_timeout, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " timeout pong %d%s", _nat->pong_timeout, VTY_NEWLINE);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, "  token %s%s", bsc->token, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, "  location_area_code %u%s", bsc->lac, VTY_NEWLINE);
 | 
				
			||||||
 | 
						if (bsc->imsi_allow)
 | 
				
			||||||
 | 
							vty_out(vty, "   imsi allow %s%s", bsc->imsi_allow, VTY_NEWLINE);
 | 
				
			||||||
 | 
						if (bsc->imsi_deny)
 | 
				
			||||||
 | 
							vty_out(vty, "   imsi deny %s%s", bsc->imsi_deny, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, "  paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int config_write_bsc(struct vty *vty)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_config *bsc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(bsc, &_nat->bsc_configs, entry)
 | 
				
			||||||
 | 
							config_write_bsc_single(vty, bsc);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(show_sccp, show_sccp_cmd, "show sccp connections",
 | 
				
			||||||
 | 
					      SHOW_STR "Display information about current SCCP connections")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connections *con;
 | 
				
			||||||
 | 
						vty_out(vty, "Listing all opening SCCP connections%s", VTY_NEWLINE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(con, &_nat->sccp_connections, list_entry) {
 | 
				
			||||||
 | 
							vty_out(vty, "For BSC Nr: %d lac: %d; BSC ref: 0x%x; MUX ref: 0x%x; Network has ref: %d ref: 0x%x MSC/BSC mux: 0x%x/0x%x%s",
 | 
				
			||||||
 | 
								con->bsc->cfg ? con->bsc->cfg->nr : -1,
 | 
				
			||||||
 | 
								con->bsc->cfg ? con->bsc->cfg->lac : -1,
 | 
				
			||||||
 | 
								sccp_src_ref_to_int(&con->real_ref),
 | 
				
			||||||
 | 
								sccp_src_ref_to_int(&con->patched_ref),
 | 
				
			||||||
 | 
								con->has_remote_ref,
 | 
				
			||||||
 | 
								sccp_src_ref_to_int(&con->remote_ref),
 | 
				
			||||||
 | 
								con->msc_timeslot, con->bsc_timeslot,
 | 
				
			||||||
 | 
								VTY_NEWLINE);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(show_bsc, show_bsc_cmd, "show bsc connections",
 | 
				
			||||||
 | 
					      SHOW_STR "Display information about current BSCs")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_connection *con;
 | 
				
			||||||
 | 
						struct sockaddr_in sock;
 | 
				
			||||||
 | 
						socklen_t len = sizeof(sock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
 | 
				
			||||||
 | 
							getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
 | 
				
			||||||
 | 
							vty_out(vty, "BSC nr: %d lac: %d auth: %d fd: %d peername: %s%s",
 | 
				
			||||||
 | 
								con->cfg ? con->cfg->nr : -1,
 | 
				
			||||||
 | 
								con->cfg ? con->cfg->lac : -1,
 | 
				
			||||||
 | 
								con->authenticated, con->write_queue.bfd.fd,
 | 
				
			||||||
 | 
								inet_ntoa(sock.sin_addr), VTY_NEWLINE);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
 | 
				
			||||||
 | 
					      SHOW_STR "Display information about known BSC configs")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_config *conf;
 | 
				
			||||||
 | 
						llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
 | 
				
			||||||
 | 
							vty_out(vty, "BSC token: '%s' lac: %u nr: %u%s",
 | 
				
			||||||
 | 
								conf->token, conf->lac, conf->nr, VTY_NEWLINE);
 | 
				
			||||||
 | 
							vty_out(vty, " imsi_allow: '%s' imsi_deny: '%s'%s",
 | 
				
			||||||
 | 
								conf->imsi_allow ? conf->imsi_allow: "any",
 | 
				
			||||||
 | 
								conf->imsi_deny  ? conf->imsi_deny : "none",
 | 
				
			||||||
 | 
								VTY_NEWLINE);
 | 
				
			||||||
 | 
							vty_out(vty, " paging forbidden: %d%s",
 | 
				
			||||||
 | 
								conf->forbid_paging, VTY_NEWLINE);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(show_stats,
 | 
				
			||||||
 | 
					      show_stats_cmd,
 | 
				
			||||||
 | 
					      "show statistics [NR]",
 | 
				
			||||||
 | 
						SHOW_STR "Display network statistics")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_config *conf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						int nr = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (argc == 1)
 | 
				
			||||||
 | 
							nr = atoi(argv[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
 | 
				
			||||||
 | 
							counter_get(_nat->stats.sccp.conn),
 | 
				
			||||||
 | 
							counter_get(_nat->stats.sccp.calls), VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " MSC Connections %lu%s",
 | 
				
			||||||
 | 
							counter_get(_nat->stats.msc.reconn), VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
 | 
				
			||||||
 | 
							counter_get(_nat->stats.bsc.reconn),
 | 
				
			||||||
 | 
							counter_get(_nat->stats.bsc.auth_fail), VTY_NEWLINE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
 | 
				
			||||||
 | 
							if (argc == 1 && nr != conf->nr)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							vty_out(vty, " BSC lac: %d nr: %d%s",
 | 
				
			||||||
 | 
								conf->lac, conf->nr, VTY_NEWLINE);
 | 
				
			||||||
 | 
							vty_out(vty, "   SCCP Connnections %lu total, %lu calls%s",
 | 
				
			||||||
 | 
								counter_get(conf->stats.sccp.conn),
 | 
				
			||||||
 | 
								counter_get(conf->stats.sccp.calls), VTY_NEWLINE);
 | 
				
			||||||
 | 
							vty_out(vty, "   BSC Connections %lu total%s",
 | 
				
			||||||
 | 
								counter_get(conf->stats.net.reconn), VTY_NEWLINE);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(show_msc,
 | 
				
			||||||
 | 
					      show_msc_cmd,
 | 
				
			||||||
 | 
					      "show msc connection",
 | 
				
			||||||
 | 
					      SHOW_STR "Show the status of the MSC connection.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!_nat->msc_con) {
 | 
				
			||||||
 | 
							vty_out(vty, "The MSC is not yet configured.\n");
 | 
				
			||||||
 | 
							return CMD_WARNING;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
 | 
				
			||||||
 | 
							_nat->msc_con->ip, _nat->msc_con->port,
 | 
				
			||||||
 | 
							_nat->msc_con->is_connected, VTY_NEWLINE);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(close_bsc,
 | 
				
			||||||
 | 
					      close_bsc_cmd,
 | 
				
			||||||
 | 
					      "close bsc connection BSC_NR",
 | 
				
			||||||
 | 
					      "Close the connection with the BSC identified by the config number.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_connection *bsc;
 | 
				
			||||||
 | 
						int bsc_nr = atoi(argv[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
 | 
				
			||||||
 | 
							if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							bsc_close_connection(bsc);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						vty->index = _nat;
 | 
				
			||||||
 | 
						vty->node = NAT_NODE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void parse_reg(void *ctx, regex_t *reg, char **imsi, int argc, const char **argv)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (*imsi) {
 | 
				
			||||||
 | 
							talloc_free(*imsi);
 | 
				
			||||||
 | 
							*imsi = NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						regfree(reg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (argc > 0) {
 | 
				
			||||||
 | 
							*imsi = talloc_strdup(ctx, argv[0]);
 | 
				
			||||||
 | 
							regcomp(reg, argv[0], 0);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_nat_imsi_allow,
 | 
				
			||||||
 | 
					      cfg_nat_imsi_allow_cmd,
 | 
				
			||||||
 | 
					      "imsi allow [REGEXP]",
 | 
				
			||||||
 | 
					      "Allow matching IMSIs to talk to the MSC. "
 | 
				
			||||||
 | 
					      "The defualt is to allow everyone.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						parse_reg(_nat, &_nat->imsi_allow_re, &_nat->imsi_allow, argc, argv);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_nat_imsi_deny,
 | 
				
			||||||
 | 
					      cfg_nat_imsi_deny_cmd,
 | 
				
			||||||
 | 
					      "imsi deny [REGEXP]",
 | 
				
			||||||
 | 
					      "Deny matching IMSIs to talk to the MSC. "
 | 
				
			||||||
 | 
					      "The defualt is to not deny.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						parse_reg(_nat, &_nat->imsi_deny_re, &_nat->imsi_deny, argc, argv);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_nat_msc_ip,
 | 
				
			||||||
 | 
					      cfg_nat_msc_ip_cmd,
 | 
				
			||||||
 | 
					      "msc ip IP",
 | 
				
			||||||
 | 
					      "Set the IP address of the MSC.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						bsc_nat_set_msc_ip(_nat, argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_nat_msc_port,
 | 
				
			||||||
 | 
					      cfg_nat_msc_port_cmd,
 | 
				
			||||||
 | 
					      "msc port <1-65500>",
 | 
				
			||||||
 | 
					      "Set the port of the MSC.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						_nat->msc_port = atoi(argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_nat_auth_time,
 | 
				
			||||||
 | 
					      cfg_nat_auth_time_cmd,
 | 
				
			||||||
 | 
					      "timeout auth <1-256>",
 | 
				
			||||||
 | 
					      "The time to wait for an auth response.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						_nat->auth_timeout = atoi(argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_nat_ping_time,
 | 
				
			||||||
 | 
					      cfg_nat_ping_time_cmd,
 | 
				
			||||||
 | 
					      "timeout ping NR",
 | 
				
			||||||
 | 
					      "Send a ping every NR seconds. Negative to disable.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						_nat->ping_timeout = atoi(argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_nat_pong_time,
 | 
				
			||||||
 | 
					      cfg_nat_pong_time_cmd,
 | 
				
			||||||
 | 
					      "timeout pong NR",
 | 
				
			||||||
 | 
					      "Wait NR seconds for the PONG response. Should be smaller than ping.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						_nat->pong_timeout = atoi(argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* per BSC configuration */
 | 
				
			||||||
 | 
					DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int bsc_nr = atoi(argv[0]);
 | 
				
			||||||
 | 
						struct bsc_config *bsc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc_nr > _nat->num_bsc) {
 | 
				
			||||||
 | 
							vty_out(vty, "%% The next unused BSC number is %u%s",
 | 
				
			||||||
 | 
								_nat->num_bsc, VTY_NEWLINE);
 | 
				
			||||||
 | 
							return CMD_WARNING;
 | 
				
			||||||
 | 
						} else if (bsc_nr == _nat->num_bsc) {
 | 
				
			||||||
 | 
							/* allocate a new one */
 | 
				
			||||||
 | 
							bsc = bsc_config_alloc(_nat, "unknown", 0);
 | 
				
			||||||
 | 
						} else
 | 
				
			||||||
 | 
							bsc = bsc_config_num(_nat, bsc_nr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!bsc)
 | 
				
			||||||
 | 
							return CMD_WARNING;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						vty->index = bsc;
 | 
				
			||||||
 | 
						vty->node = BSC_NODE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_config *conf = vty->index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (conf->token)
 | 
				
			||||||
 | 
						    talloc_free(conf->token);
 | 
				
			||||||
 | 
						conf->token = talloc_strdup(conf, argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
 | 
				
			||||||
 | 
					      "Set the Location Area Code (LAC) of this BSC")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_config *tmp;
 | 
				
			||||||
 | 
						struct bsc_config *conf = vty->index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						int lac = atoi(argv[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (lac < 0 || lac > 0xffff) {
 | 
				
			||||||
 | 
							vty_out(vty, "%% LAC %d is not in the valid range (0-65535)%s",
 | 
				
			||||||
 | 
								lac, VTY_NEWLINE);
 | 
				
			||||||
 | 
							return CMD_WARNING;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
 | 
				
			||||||
 | 
							vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
 | 
				
			||||||
 | 
								lac, VTY_NEWLINE);
 | 
				
			||||||
 | 
							return CMD_WARNING;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* verify that the LACs are unique */
 | 
				
			||||||
 | 
						llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
 | 
				
			||||||
 | 
							if (tmp->lac == lac) {
 | 
				
			||||||
 | 
								vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
 | 
				
			||||||
 | 
								return CMD_ERR_INCOMPLETE;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						conf->lac = lac;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_bsc_imsi_allow,
 | 
				
			||||||
 | 
					      cfg_bsc_imsi_allow_cmd,
 | 
				
			||||||
 | 
					      "imsi allow [REGEXP]",
 | 
				
			||||||
 | 
					      "Allow IMSIs with the following network to talk to the MSC."
 | 
				
			||||||
 | 
					      "The default is to allow everyone)")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_config *conf = vty->index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						parse_reg(conf, &conf->imsi_allow_re, &conf->imsi_allow, argc, argv);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_bsc_imsi_deny,
 | 
				
			||||||
 | 
					      cfg_bsc_imsi_deny_cmd,
 | 
				
			||||||
 | 
					      "imsi deny [REGEXP]",
 | 
				
			||||||
 | 
					      "Deny IMSIs with the following network to talk to the MSC."
 | 
				
			||||||
 | 
					      "The default is to not deny anyone.)")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_config *conf = vty->index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						parse_reg(conf, &conf->imsi_deny_re, &conf->imsi_deny, argc, argv);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_bsc_paging,
 | 
				
			||||||
 | 
					      cfg_bsc_paging_cmd,
 | 
				
			||||||
 | 
					      "paging forbidden (0|1)",
 | 
				
			||||||
 | 
					      "Forbid sending PAGING REQUESTS to the BSC.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_config *conf = vty->index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (strcmp("1", argv[0]) == 0)
 | 
				
			||||||
 | 
							conf->forbid_paging = 1;
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							conf->forbid_paging = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_nat_vty_init(struct bsc_nat *nat)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						_nat = nat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cmd_init(1);
 | 
				
			||||||
 | 
						vty_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* show commands */
 | 
				
			||||||
 | 
						install_element(VIEW_NODE, &show_sccp_cmd);
 | 
				
			||||||
 | 
						install_element(VIEW_NODE, &show_bsc_cmd);
 | 
				
			||||||
 | 
						install_element(VIEW_NODE, &show_bsc_cfg_cmd);
 | 
				
			||||||
 | 
						install_element(VIEW_NODE, &show_stats_cmd);
 | 
				
			||||||
 | 
						install_element(VIEW_NODE, &close_bsc_cmd);
 | 
				
			||||||
 | 
						install_element(VIEW_NODE, &show_msc_cmd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						openbsc_vty_add_cmds();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* nat group */
 | 
				
			||||||
 | 
						install_element(CONFIG_NODE, &cfg_nat_cmd);
 | 
				
			||||||
 | 
						install_node(&nat_node, config_write_nat);
 | 
				
			||||||
 | 
						install_default(NAT_NODE);
 | 
				
			||||||
 | 
						install_element(NAT_NODE, &cfg_nat_imsi_allow_cmd);
 | 
				
			||||||
 | 
						install_element(NAT_NODE, &cfg_nat_imsi_deny_cmd);
 | 
				
			||||||
 | 
						install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
 | 
				
			||||||
 | 
						install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
 | 
				
			||||||
 | 
						install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
 | 
				
			||||||
 | 
						install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
 | 
				
			||||||
 | 
						install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* BSC subgroups */
 | 
				
			||||||
 | 
						install_element(NAT_NODE, &cfg_bsc_cmd);
 | 
				
			||||||
 | 
						install_node(&bsc_node, config_write_bsc);
 | 
				
			||||||
 | 
						install_default(BSC_NODE);
 | 
				
			||||||
 | 
						install_element(BSC_NODE, &cfg_bsc_token_cmd);
 | 
				
			||||||
 | 
						install_element(BSC_NODE, &cfg_bsc_lac_cmd);
 | 
				
			||||||
 | 
						install_element(BSC_NODE, &cfg_bsc_imsi_allow_cmd);
 | 
				
			||||||
 | 
						install_element(BSC_NODE, &cfg_bsc_imsi_deny_cmd);
 | 
				
			||||||
 | 
						install_element(BSC_NODE, &cfg_bsc_paging_cmd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mgcp_vty_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* called by the telnet interface... we have our own init above */
 | 
				
			||||||
 | 
					void bsc_vty_init()
 | 
				
			||||||
 | 
					{}
 | 
				
			||||||
							
								
								
									
										232
									
								
								openbsc/src/nat/bsc_sccp.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										232
									
								
								openbsc/src/nat/bsc_sccp.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,232 @@
 | 
				
			|||||||
 | 
					/* SCCP patching and handling routines */
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
 | 
				
			||||||
 | 
					 * (C) 2010 by On-Waves
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <openbsc/debug.h>
 | 
				
			||||||
 | 
					#include <openbsc/bsc_nat.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sccp/sccp.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/talloc.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int equal(struct sccp_source_reference *ref1, struct sccp_source_reference *ref2)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return memcmp(ref1, ref2, sizeof(*ref1)) == 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * SCCP patching below
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* check if we are using this ref for patched already */
 | 
				
			||||||
 | 
					static int sccp_ref_is_free(struct sccp_source_reference *ref, struct bsc_nat *nat)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connections *conn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(conn, &nat->sccp_connections, list_entry) {
 | 
				
			||||||
 | 
							if (memcmp(ref, &conn->patched_ref, sizeof(*ref)) == 0)
 | 
				
			||||||
 | 
								return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* copied from sccp.c */
 | 
				
			||||||
 | 
					static int assign_src_local_reference(struct sccp_source_reference *ref, struct bsc_nat *nat)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static u_int32_t last_ref = 0x50000;
 | 
				
			||||||
 | 
						int wrapped = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						do {
 | 
				
			||||||
 | 
							struct sccp_source_reference reference;
 | 
				
			||||||
 | 
							reference.octet1 = (last_ref >>  0) & 0xff;
 | 
				
			||||||
 | 
							reference.octet2 = (last_ref >>  8) & 0xff;
 | 
				
			||||||
 | 
							reference.octet3 = (last_ref >> 16) & 0xff;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							++last_ref;
 | 
				
			||||||
 | 
							/* do not use the reversed word and wrap around */
 | 
				
			||||||
 | 
							if ((last_ref & 0x00FFFFFF) == 0x00FFFFFF) {
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_NOTICE, "Wrapped searching for a free code\n");
 | 
				
			||||||
 | 
								last_ref = 0;
 | 
				
			||||||
 | 
								++wrapped;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (sccp_ref_is_free(&reference, nat) == 0) {
 | 
				
			||||||
 | 
								*ref = reference;
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} while (wrapped != 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DNAT, LOGL_ERROR, "Finding a free reference failed\n");
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int create_sccp_src_ref(struct bsc_connection *bsc, struct msgb *msg, struct bsc_nat_parsed *parsed)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connections *conn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Some commercial BSCs like to reassign there SRC ref */
 | 
				
			||||||
 | 
						llist_for_each_entry(conn, &bsc->nat->sccp_connections, list_entry) {
 | 
				
			||||||
 | 
							if (conn->bsc != bsc)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if (memcmp(&conn->real_ref, parsed->src_local_ref, sizeof(conn->real_ref)) != 0)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* the BSC has reassigned the SRC ref and we failed to keep track */
 | 
				
			||||||
 | 
							memset(&conn->remote_ref, 0, sizeof(conn->remote_ref));
 | 
				
			||||||
 | 
							if (assign_src_local_reference(&conn->patched_ref, bsc->nat) != 0) {
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_ERROR, "BSC %d reused src ref: %d and we failed to generate a new id.\n",
 | 
				
			||||||
 | 
								     bsc->cfg->nr, sccp_src_ref_to_int(parsed->src_local_ref));
 | 
				
			||||||
 | 
								llist_del(&conn->list_entry);
 | 
				
			||||||
 | 
								talloc_free(conn);
 | 
				
			||||||
 | 
								return -1;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								bsc_mgcp_dlcx(conn);
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						conn = talloc_zero(bsc->nat, struct sccp_connections);
 | 
				
			||||||
 | 
						if (!conn) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Memory allocation failure.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						conn->bsc = bsc;
 | 
				
			||||||
 | 
						conn->real_ref = *parsed->src_local_ref;
 | 
				
			||||||
 | 
						if (assign_src_local_reference(&conn->patched_ref, bsc->nat) != 0) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "Failed to assign a ref.\n");
 | 
				
			||||||
 | 
							talloc_free(conn);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_mgcp_init(conn);
 | 
				
			||||||
 | 
						llist_add_tail(&conn->list_entry, &bsc->nat->sccp_connections);
 | 
				
			||||||
 | 
						counter_inc(bsc->cfg->stats.sccp.conn);
 | 
				
			||||||
 | 
						counter_inc(bsc->cfg->nat->stats.sccp.conn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DNAT, LOGL_DEBUG, "Created 0x%x <-> 0x%x mapping for con %p\n",
 | 
				
			||||||
 | 
						     sccp_src_ref_to_int(&conn->real_ref),
 | 
				
			||||||
 | 
						     sccp_src_ref_to_int(&conn->patched_ref), bsc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int update_sccp_src_ref(struct sccp_connections *sccp, struct bsc_nat_parsed *parsed)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!parsed->dest_local_ref || !parsed->src_local_ref) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "CC MSG should contain both local and dest address.\n");
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sccp->remote_ref = *parsed->src_local_ref;
 | 
				
			||||||
 | 
						sccp->has_remote_ref = 1;
 | 
				
			||||||
 | 
						LOGP(DNAT, LOGL_DEBUG, "Updating 0x%x to remote 0x%x on %p\n",
 | 
				
			||||||
 | 
						     sccp_src_ref_to_int(&sccp->patched_ref),
 | 
				
			||||||
 | 
						     sccp_src_ref_to_int(&sccp->remote_ref), sccp->bsc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void remove_sccp_src_ref(struct bsc_connection *bsc, struct msgb *msg, struct bsc_nat_parsed *parsed)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connections *conn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(conn, &bsc->nat->sccp_connections, list_entry) {
 | 
				
			||||||
 | 
							if (memcmp(parsed->src_local_ref,
 | 
				
			||||||
 | 
								   &conn->patched_ref, sizeof(conn->patched_ref)) == 0) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sccp_connection_destroy(conn);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DNAT, LOGL_ERROR, "Can not remove connection: 0x%x\n",
 | 
				
			||||||
 | 
						     sccp_src_ref_to_int(parsed->src_local_ref));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * We have a message from the MSC to the BSC. The MSC is using
 | 
				
			||||||
 | 
					 * an address that was assigned by the MUX, we need to update the
 | 
				
			||||||
 | 
					 * dest reference to the real network.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct sccp_connections *patch_sccp_src_ref_to_bsc(struct msgb *msg,
 | 
				
			||||||
 | 
											   struct bsc_nat_parsed *parsed,
 | 
				
			||||||
 | 
											   struct bsc_nat *nat)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connections *conn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!parsed->dest_local_ref) {
 | 
				
			||||||
 | 
							LOGP(DNAT, LOGL_ERROR, "MSG should contain dest_local_ref.\n");
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(conn, &nat->sccp_connections, list_entry) {
 | 
				
			||||||
 | 
							if (!equal(parsed->dest_local_ref, &conn->patched_ref))
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* Change the dest address to the real one */
 | 
				
			||||||
 | 
							*parsed->dest_local_ref = conn->real_ref;
 | 
				
			||||||
 | 
							return conn;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * These are message to the MSC. We will need to find the BSC
 | 
				
			||||||
 | 
					 * Connection by either the SRC or the DST local reference.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * In case of a CR we need to work by the SRC local reference
 | 
				
			||||||
 | 
					 * in all other cases we need to work by the destination local
 | 
				
			||||||
 | 
					 * reference..
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct sccp_connections *patch_sccp_src_ref_to_msc(struct msgb *msg,
 | 
				
			||||||
 | 
											   struct bsc_nat_parsed *parsed,
 | 
				
			||||||
 | 
											   struct bsc_connection *bsc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct sccp_connections *conn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(conn, &bsc->nat->sccp_connections, list_entry) {
 | 
				
			||||||
 | 
							if (conn->bsc != bsc)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (parsed->src_local_ref) {
 | 
				
			||||||
 | 
								if (equal(parsed->src_local_ref, &conn->real_ref)) {
 | 
				
			||||||
 | 
									*parsed->src_local_ref = conn->patched_ref;
 | 
				
			||||||
 | 
									return conn;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else if (parsed->dest_local_ref) {
 | 
				
			||||||
 | 
								if (equal(parsed->dest_local_ref, &conn->remote_ref))
 | 
				
			||||||
 | 
									return conn;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								LOGP(DNAT, LOGL_ERROR, "Header has neither loc/dst ref.\n");
 | 
				
			||||||
 | 
								return NULL;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -49,6 +49,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void *tall_paging_ctx;
 | 
					void *tall_paging_ctx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define PAGING_TIMER 0, 500000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static unsigned int calculate_group(struct gsm_bts *bts, struct gsm_subscriber *subscr)
 | 
					static unsigned int calculate_group(struct gsm_bts *bts, struct gsm_subscriber *subscr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ccch_conf;
 | 
						int ccch_conf;
 | 
				
			||||||
@@ -96,6 +98,72 @@ static void page_ms(struct gsm_paging_request *request)
 | 
				
			|||||||
			request->chan_type);
 | 
								request->chan_type);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void paging_schedule_if_needed(struct gsm_bts_paging_state *paging_bts)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (llist_empty(&paging_bts->pending_requests))
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!bsc_timer_pending(&paging_bts->work_timer))
 | 
				
			||||||
 | 
							bsc_schedule_timer(&paging_bts->work_timer, PAGING_TIMER);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts);
 | 
				
			||||||
 | 
					static void paging_give_credit(void *data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct gsm_bts_paging_state *paging_bts = data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LOGP(DPAG, LOGL_NOTICE, "No slots available on bts nr %d\n", paging_bts->bts->nr);
 | 
				
			||||||
 | 
						paging_bts->available_slots = 20;
 | 
				
			||||||
 | 
						paging_handle_pending_requests(paging_bts);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int can_send_pag_req(struct gsm_bts *bts, int rsl_type)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct pchan_load pl;
 | 
				
			||||||
 | 
						int count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memset(&pl, 0, sizeof(pl));
 | 
				
			||||||
 | 
						bts_chan_load(&pl, bts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch (rsl_type) {
 | 
				
			||||||
 | 
						case RSL_CHANNEED_TCH_F:
 | 
				
			||||||
 | 
						case RSL_CHANNEED_TCH_ForH:
 | 
				
			||||||
 | 
							goto count_tch;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case RSL_CHANNEED_SDCCH:
 | 
				
			||||||
 | 
							goto count_sdcch;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case RSL_CHANNEED_ANY:
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							if (bts->network->pag_any_tch)
 | 
				
			||||||
 | 
								goto count_tch;
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								goto count_sdcch;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* could available SDCCH */
 | 
				
			||||||
 | 
					count_sdcch:
 | 
				
			||||||
 | 
						count = 0;
 | 
				
			||||||
 | 
						count += pl.pchan[GSM_PCHAN_SDCCH8_SACCH8C].total
 | 
				
			||||||
 | 
								- pl.pchan[GSM_PCHAN_SDCCH8_SACCH8C].used;
 | 
				
			||||||
 | 
						count += pl.pchan[GSM_PCHAN_CCCH_SDCCH4].total
 | 
				
			||||||
 | 
								- pl.pchan[GSM_PCHAN_CCCH_SDCCH4].used;
 | 
				
			||||||
 | 
						return bts->paging.free_chans_need > count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					count_tch:
 | 
				
			||||||
 | 
						count = 0;
 | 
				
			||||||
 | 
						count += pl.pchan[GSM_PCHAN_TCH_F].total
 | 
				
			||||||
 | 
								- pl.pchan[GSM_PCHAN_TCH_F].used;
 | 
				
			||||||
 | 
						if (bts->network->neci)
 | 
				
			||||||
 | 
							count += pl.pchan[GSM_PCHAN_TCH_H].total
 | 
				
			||||||
 | 
									- pl.pchan[GSM_PCHAN_TCH_H].used;
 | 
				
			||||||
 | 
						return bts->paging.free_chans_need > count;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * This is kicked by the periodic PAGING LOAD Indicator
 | 
					 * This is kicked by the periodic PAGING LOAD Indicator
 | 
				
			||||||
 * coming from abis_rsl.c
 | 
					 * coming from abis_rsl.c
 | 
				
			||||||
@@ -105,8 +173,7 @@ static void page_ms(struct gsm_paging_request *request)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts)
 | 
					static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_bts)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct gsm_paging_request *initial_request = NULL;
 | 
						struct gsm_paging_request *request = NULL;
 | 
				
			||||||
	struct gsm_paging_request *current_request = NULL;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Determine if the pending_requests list is empty and
 | 
						 * Determine if the pending_requests list is empty and
 | 
				
			||||||
@@ -118,39 +185,37 @@ static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_b
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * In case the BTS does not provide us with load indication just fill
 | 
						 * In case the BTS does not provide us with load indication and we
 | 
				
			||||||
	 * up our slots for this round. We should be able to page 20 subscribers
 | 
						 * ran out of slots, call an autofill routine. It might be that the
 | 
				
			||||||
	 * every two seconds. So we will just give the BTS some extra credit.
 | 
						 * BTS did not like our paging messages and then we have counted down
 | 
				
			||||||
	 * We will have to see how often we run out of this credit, so we might
 | 
						 * to zero and we do not get any messages.
 | 
				
			||||||
	 * need a low watermark and then add credit or give 20 every run when
 | 
					 | 
				
			||||||
	 * the bts sets an option for that.
 | 
					 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (paging_bts->available_slots == 0) {
 | 
						if (paging_bts->available_slots == 0) {
 | 
				
			||||||
		LOGP(DPAG, LOGL_NOTICE, "No slots available on bts nr %d\n",
 | 
							paging_bts->credit_timer.cb = paging_give_credit;
 | 
				
			||||||
		     paging_bts->bts->nr);
 | 
							paging_bts->credit_timer.data = paging_bts;
 | 
				
			||||||
		paging_bts->available_slots = 20;
 | 
							bsc_schedule_timer(&paging_bts->credit_timer, 5, 0);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	initial_request = llist_entry(paging_bts->pending_requests.next,
 | 
						request = llist_entry(paging_bts->pending_requests.next,
 | 
				
			||||||
				      struct gsm_paging_request, entry);
 | 
								      struct gsm_paging_request, entry);
 | 
				
			||||||
	current_request = initial_request;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	do {
 | 
						/* we need to determine the number of free channels */
 | 
				
			||||||
		/* handle the paging request now */
 | 
						if (paging_bts->free_chans_need != -1) {
 | 
				
			||||||
		page_ms(current_request);
 | 
							if (can_send_pag_req(request->bts, request->chan_type) != 0)
 | 
				
			||||||
		paging_bts->available_slots--;
 | 
								goto skip_paging;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* take the current and add it to the back */
 | 
						/* handle the paging request now */
 | 
				
			||||||
		llist_del(¤t_request->entry);
 | 
						page_ms(request);
 | 
				
			||||||
		llist_add_tail(¤t_request->entry, &paging_bts->pending_requests);
 | 
						paging_bts->available_slots--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* take the next request */
 | 
						/* take the current and add it to the back */
 | 
				
			||||||
		current_request = llist_entry(paging_bts->pending_requests.next,
 | 
						llist_del(&request->entry);
 | 
				
			||||||
					      struct gsm_paging_request, entry);
 | 
						llist_add_tail(&request->entry, &paging_bts->pending_requests);
 | 
				
			||||||
	} while (paging_bts->available_slots > 0
 | 
					 | 
				
			||||||
		    &&  initial_request != current_request);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bsc_schedule_timer(&paging_bts->work_timer, 2, 0);
 | 
					skip_paging:
 | 
				
			||||||
 | 
						bsc_schedule_timer(&paging_bts->work_timer, PAGING_TIMER);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void paging_worker(void *data)
 | 
					static void paging_worker(void *data)
 | 
				
			||||||
@@ -233,9 +298,7 @@ static int _paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscr,
 | 
				
			|||||||
	req->T3113.data = req;
 | 
						req->T3113.data = req;
 | 
				
			||||||
	bsc_schedule_timer(&req->T3113, bts->network->T3113, 0);
 | 
						bsc_schedule_timer(&req->T3113, bts->network->T3113, 0);
 | 
				
			||||||
	llist_add_tail(&req->entry, &bts_entry->pending_requests);
 | 
						llist_add_tail(&req->entry, &bts_entry->pending_requests);
 | 
				
			||||||
 | 
						paging_schedule_if_needed(bts_entry);
 | 
				
			||||||
	if (!bsc_timer_pending(&bts_entry->work_timer))
 | 
					 | 
				
			||||||
		bsc_schedule_timer(&bts_entry->work_timer, 2, 0);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -325,5 +388,19 @@ void paging_request_stop(struct gsm_bts *_bts, struct gsm_subscriber *subscr,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void paging_update_buffer_space(struct gsm_bts *bts, u_int16_t free_slots)
 | 
					void paging_update_buffer_space(struct gsm_bts *bts, u_int16_t free_slots)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						bsc_del_timer(&bts->paging.credit_timer);
 | 
				
			||||||
	bts->paging.available_slots = free_slots;
 | 
						bts->paging.available_slots = free_slots;
 | 
				
			||||||
 | 
						paging_schedule_if_needed(&bts->paging);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsigned int paging_pending_requests_nr(struct gsm_bts *bts)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						unsigned int requests = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct gsm_paging_request *req;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						llist_for_each_entry(req, &bts->paging.pending_requests, entry)
 | 
				
			||||||
 | 
							++requests;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return requests;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,6 +91,9 @@ struct rtp_x_hdr {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#define RTP_VERSION	2
 | 
					#define RTP_VERSION	2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define RTP_PT_GSM_FULL	3
 | 
				
			||||||
 | 
					#define RTP_PT_GSM_EFR	97
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* decode an rtp frame and create a new buffer with payload */
 | 
					/* decode an rtp frame and create a new buffer with payload */
 | 
				
			||||||
static int rtp_decode(struct msgb *msg, u_int32_t callref, struct msgb **data)
 | 
					static int rtp_decode(struct msgb *msg, u_int32_t callref, struct msgb **data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -81,7 +81,7 @@ static struct sccp_data_callback *_find_ssn(u_int8_t ssn)
 | 
				
			|||||||
	/* need to add one */
 | 
						/* need to add one */
 | 
				
			||||||
	cb = talloc_zero(tall_sccp_ctx, struct sccp_data_callback);
 | 
						cb = talloc_zero(tall_sccp_ctx, struct sccp_data_callback);
 | 
				
			||||||
	if (!cb) {
 | 
						if (!cb) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Failed to allocate sccp callback.\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "Failed to allocate sccp callback.\n");
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -108,13 +108,13 @@ static int copy_address(struct sccp_address *addr, u_int8_t offset, struct msgb
 | 
				
			|||||||
	u_int8_t length;
 | 
						u_int8_t length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (room <= 0) {
 | 
						if (room <= 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Not enough room for an address: %u\n", room);
 | 
							LOGP(DSCCP, LOGL_ERROR, "Not enough room for an address: %u\n", room);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	length = msgb->l2h[offset];
 | 
						length = msgb->l2h[offset];
 | 
				
			||||||
	if (room <= length) {
 | 
						if (room <= length) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Not enough room for optional data %u %u\n", room, length);
 | 
							LOGP(DSCCP, LOGL_ERROR, "Not enough room for optional data %u %u\n", room, length);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -122,7 +122,7 @@ static int copy_address(struct sccp_address *addr, u_int8_t offset, struct msgb
 | 
				
			|||||||
	party = (struct sccp_called_party_address *)(msgb->l2h + offset + 1);
 | 
						party = (struct sccp_called_party_address *)(msgb->l2h + offset + 1);
 | 
				
			||||||
	if (party->point_code_indicator) {
 | 
						if (party->point_code_indicator) {
 | 
				
			||||||
		if (length <= read + 2) {
 | 
							if (length <= read + 2) {
 | 
				
			||||||
		    DEBUGP(DSCCP, "POI does not fit %u\n", length);
 | 
							    LOGP(DSCCP, LOGL_ERROR, "POI does not fit %u\n", length);
 | 
				
			||||||
		    return -1;
 | 
							    return -1;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -133,7 +133,7 @@ static int copy_address(struct sccp_address *addr, u_int8_t offset, struct msgb
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (party->ssn_indicator) {
 | 
						if (party->ssn_indicator) {
 | 
				
			||||||
		if (length <= read + 1) {
 | 
							if (length <= read + 1) {
 | 
				
			||||||
		    DEBUGP(DSCCP, "SSN does not fit %u\n", length);
 | 
							    LOGP(DSCCP, LOGL_ERROR, "SSN does not fit %u\n", length);
 | 
				
			||||||
		    return -1;
 | 
							    return -1;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -142,7 +142,7 @@ static int copy_address(struct sccp_address *addr, u_int8_t offset, struct msgb
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (party->global_title_indicator) {
 | 
						if (party->global_title_indicator) {
 | 
				
			||||||
		DEBUGP(DSCCP, "GTI not supported %u\n", *(u_int8_t *)party);
 | 
							LOGP(DSCCP, LOGL_ERROR, "GTI not supported %u\n", *(u_int8_t *)party);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -156,7 +156,8 @@ static int check_address(struct sccp_address *addr)
 | 
				
			|||||||
	if (addr->address.ssn_indicator != 1
 | 
						if (addr->address.ssn_indicator != 1
 | 
				
			||||||
	    || addr->address.global_title_indicator == 1
 | 
						    || addr->address.global_title_indicator == 1
 | 
				
			||||||
	    || addr->address.routing_indicator != 1) {
 | 
						    || addr->address.routing_indicator != 1) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Invalid called address according to 08.06: 0x%x 0x%x\n",
 | 
							LOGP(DSCCP, LOGL_ERROR,
 | 
				
			||||||
 | 
								"Invalid called address according to 08.06: 0x%x 0x%x\n",
 | 
				
			||||||
			*(u_int8_t *)&addr->address, addr->ssn);
 | 
								*(u_int8_t *)&addr->address, addr->ssn);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -176,7 +177,7 @@ static int _sccp_parse_optional_data(const int offset,
 | 
				
			|||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (read + 1 >= room) {
 | 
							if (read + 1 >= room) {
 | 
				
			||||||
			DEBUGP(DSCCP, "no place for length\n");
 | 
								LOGP(DSCCP, LOGL_ERROR, "no place for length\n");
 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -185,7 +186,8 @@ static int _sccp_parse_optional_data(const int offset,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (room <= read) {
 | 
							if (room <= read) {
 | 
				
			||||||
			DEBUGP(DSCCP, "no space for the data: type: %d read: %d room: %d l2: %d\n",
 | 
								LOGP(DSCCP, LOGL_ERROR,
 | 
				
			||||||
 | 
								       "no space for the data: type: %d read: %d room: %d l2: %d\n",
 | 
				
			||||||
			       type, read, room, msgb_l2len(msgb));
 | 
								       type, read, room, msgb_l2len(msgb));
 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -214,7 +216,7 @@ int _sccp_parse_connection_request(struct msgb *msgb, struct sccp_parse_result *
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* header check */
 | 
						/* header check */
 | 
				
			||||||
	if (msgb_l2len(msgb) < header_size) {
 | 
						if (msgb_l2len(msgb) < header_size) {
 | 
				
			||||||
		DEBUGP(DSCCP, "msgb < header_size %u %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
 | 
				
			||||||
		        msgb_l2len(msgb), header_size);
 | 
							        msgb_l2len(msgb), header_size);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -224,7 +226,7 @@ int _sccp_parse_connection_request(struct msgb *msgb, struct sccp_parse_result *
 | 
				
			|||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (check_address(&result->called) != 0) {
 | 
						if (check_address(&result->called) != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Invalid called address according to 08.06: 0x%x 0x%x\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "Invalid called address according to 08.06: 0x%x 0x%x\n",
 | 
				
			||||||
			*(u_int8_t *)&result->called.address, result->called.ssn);
 | 
								*(u_int8_t *)&result->called.address, result->called.ssn);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -236,7 +238,7 @@ int _sccp_parse_connection_request(struct msgb *msgb, struct sccp_parse_result *
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	memset(&optional_data, 0, sizeof(optional_data));
 | 
						memset(&optional_data, 0, sizeof(optional_data));
 | 
				
			||||||
	if (_sccp_parse_optional_data(optional_offset + req->optional_start, msgb, &optional_data) != 0) {
 | 
						if (_sccp_parse_optional_data(optional_offset + req->optional_start, msgb, &optional_data) != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "parsing of optional data failed.\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "parsing of optional data failed.\n");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -260,14 +262,14 @@ int _sccp_parse_connection_released(struct msgb *msgb, struct sccp_parse_result
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* we don't have enough size for the struct */
 | 
						/* we don't have enough size for the struct */
 | 
				
			||||||
	if (msgb_l2len(msgb) < header_size) {
 | 
						if (msgb_l2len(msgb) < header_size) {
 | 
				
			||||||
		DEBUGP(DSCCP, "msgb > header_size %u %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "msgb > header_size %u %u\n",
 | 
				
			||||||
		        msgb_l2len(msgb), header_size);
 | 
							        msgb_l2len(msgb), header_size);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memset(&optional_data, 0, sizeof(optional_data));
 | 
						memset(&optional_data, 0, sizeof(optional_data));
 | 
				
			||||||
	if (_sccp_parse_optional_data(optional_offset + rls->optional_start, msgb, &optional_data) != 0) {
 | 
						if (_sccp_parse_optional_data(optional_offset + rls->optional_start, msgb, &optional_data) != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "parsing of optional data failed.\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "parsing of optional data failed.\n");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -295,7 +297,7 @@ int _sccp_parse_connection_refused(struct msgb *msgb, struct sccp_parse_result *
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* header check */
 | 
						/* header check */
 | 
				
			||||||
	if (msgb_l2len(msgb) < header_size) {
 | 
						if (msgb_l2len(msgb) < header_size) {
 | 
				
			||||||
		DEBUGP(DSCCP, "msgb < header_size %u %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
 | 
				
			||||||
		        msgb_l2len(msgb), header_size);
 | 
							        msgb_l2len(msgb), header_size);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -306,7 +308,7 @@ int _sccp_parse_connection_refused(struct msgb *msgb, struct sccp_parse_result *
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	memset(&optional_data, 0, sizeof(optional_data));
 | 
						memset(&optional_data, 0, sizeof(optional_data));
 | 
				
			||||||
	if (_sccp_parse_optional_data(optional_offset + ref->optional_start, msgb, &optional_data) != 0) {
 | 
						if (_sccp_parse_optional_data(optional_offset + ref->optional_start, msgb, &optional_data) != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "parsing of optional data failed.\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "parsing of optional data failed.\n");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -333,7 +335,7 @@ int _sccp_parse_connection_confirm(struct msgb *msgb, struct sccp_parse_result *
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* header check */
 | 
						/* header check */
 | 
				
			||||||
	if (msgb_l2len(msgb) < header_size) {
 | 
						if (msgb_l2len(msgb) < header_size) {
 | 
				
			||||||
		DEBUGP(DSCCP, "msgb < header_size %u %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
 | 
				
			||||||
		        msgb_l2len(msgb), header_size);
 | 
							        msgb_l2len(msgb), header_size);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -344,7 +346,7 @@ int _sccp_parse_connection_confirm(struct msgb *msgb, struct sccp_parse_result *
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	memset(&optional_data, 0, sizeof(optional_data));
 | 
						memset(&optional_data, 0, sizeof(optional_data));
 | 
				
			||||||
	if (_sccp_parse_optional_data(optional_offset + con->optional_start, msgb, &optional_data) != 0) {
 | 
						if (_sccp_parse_optional_data(optional_offset + con->optional_start, msgb, &optional_data) != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "parsing of optional data failed.\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "parsing of optional data failed.\n");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -366,7 +368,7 @@ int _sccp_parse_connection_release_complete(struct msgb *msgb, struct sccp_parse
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* header check */
 | 
						/* header check */
 | 
				
			||||||
	if (msgb_l2len(msgb) < header_size) {
 | 
						if (msgb_l2len(msgb) < header_size) {
 | 
				
			||||||
		DEBUGP(DSCCP, "msgb < header_size %u %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
 | 
				
			||||||
		        msgb_l2len(msgb), header_size);
 | 
							        msgb_l2len(msgb), header_size);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -387,13 +389,13 @@ int _sccp_parse_connection_dt1(struct msgb *msgb, struct sccp_parse_result *resu
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* we don't have enough size for the struct */
 | 
						/* we don't have enough size for the struct */
 | 
				
			||||||
	if (msgb_l2len(msgb) < header_size) {
 | 
						if (msgb_l2len(msgb) < header_size) {
 | 
				
			||||||
		DEBUGP(DSCCP, "msgb > header_size %u %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "msgb > header_size %u %u\n",
 | 
				
			||||||
		        msgb_l2len(msgb), header_size);
 | 
							        msgb_l2len(msgb), header_size);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (dt1->segmenting != 0) {
 | 
						if (dt1->segmenting != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "This packet has segmenting, not supported: %d\n", dt1->segmenting);
 | 
							LOGP(DSCCP, LOGL_ERROR, "This packet has segmenting, not supported: %d\n", dt1->segmenting);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -401,7 +403,7 @@ int _sccp_parse_connection_dt1(struct msgb *msgb, struct sccp_parse_result *resu
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* some more  size checks in here */
 | 
						/* some more  size checks in here */
 | 
				
			||||||
	if (msgb_l2len(msgb) < variable_offset + dt1->variable_start + 1) {
 | 
						if (msgb_l2len(msgb) < variable_offset + dt1->variable_start + 1) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Not enough space for variable start: %u %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "Not enough space for variable start: %u %u\n",
 | 
				
			||||||
			msgb_l2len(msgb), dt1->variable_start);
 | 
								msgb_l2len(msgb), dt1->variable_start);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -410,7 +412,7 @@ int _sccp_parse_connection_dt1(struct msgb *msgb, struct sccp_parse_result *resu
 | 
				
			|||||||
	msgb->l3h = &msgb->l2h[dt1->variable_start + variable_offset + 1];
 | 
						msgb->l3h = &msgb->l2h[dt1->variable_start + variable_offset + 1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (msgb_l3len(msgb) < result->data_len) {
 | 
						if (msgb_l3len(msgb) < result->data_len) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Not enough room for the payload: %u %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "Not enough room for the payload: %u %u\n",
 | 
				
			||||||
			msgb_l3len(msgb), result->data_len);
 | 
								msgb_l3len(msgb), result->data_len);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -428,7 +430,7 @@ int _sccp_parse_udt(struct msgb *msgb, struct sccp_parse_result *result)
 | 
				
			|||||||
	struct sccp_data_unitdata *udt = (struct sccp_data_unitdata *)msgb->l2h;
 | 
						struct sccp_data_unitdata *udt = (struct sccp_data_unitdata *)msgb->l2h;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (msgb_l2len(msgb) < header_size) {
 | 
						if (msgb_l2len(msgb) < header_size) {
 | 
				
			||||||
		DEBUGP(DSCCP, "msgb < header_size %u %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
 | 
				
			||||||
		        msgb_l2len(msgb), header_size);
 | 
							        msgb_l2len(msgb), header_size);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -438,7 +440,7 @@ int _sccp_parse_udt(struct msgb *msgb, struct sccp_parse_result *result)
 | 
				
			|||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (check_address(&result->called) != 0) {
 | 
						if (check_address(&result->called) != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Invalid called address according to 08.06: 0x%x 0x%x\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "Invalid called address according to 08.06: 0x%x 0x%x\n",
 | 
				
			||||||
			*(u_int8_t *)&result->called.address, result->called.ssn);
 | 
								*(u_int8_t *)&result->called.address, result->called.ssn);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -447,13 +449,13 @@ int _sccp_parse_udt(struct msgb *msgb, struct sccp_parse_result *result)
 | 
				
			|||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (check_address(&result->calling) != 0) {
 | 
						if (check_address(&result->calling) != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Invalid called address according to 08.06: 0x%x 0x%x\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "Invalid called address according to 08.06: 0x%x 0x%x\n",
 | 
				
			||||||
			*(u_int8_t *)&result->called.address, result->called.ssn);
 | 
								*(u_int8_t *)&result->called.address, result->called.ssn);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* we don't have enough size for the data */
 | 
						/* we don't have enough size for the data */
 | 
				
			||||||
	if (msgb_l2len(msgb) < data_offset + udt->variable_data + 1) {
 | 
						if (msgb_l2len(msgb) < data_offset + udt->variable_data + 1) {
 | 
				
			||||||
		DEBUGP(DSCCP, "msgb < header + offset %u %u %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "msgb < header + offset %u %u %u\n",
 | 
				
			||||||
			msgb_l2len(msgb), header_size, udt->variable_data);
 | 
								msgb_l2len(msgb), header_size, udt->variable_data);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -463,7 +465,7 @@ int _sccp_parse_udt(struct msgb *msgb, struct sccp_parse_result *result)
 | 
				
			|||||||
	result->data_len = msgb_l3len(msgb);
 | 
						result->data_len = msgb_l3len(msgb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (msgb_l3len(msgb) !=  msgb->l3h[-1]) {
 | 
						if (msgb_l3len(msgb) !=  msgb->l3h[-1]) {
 | 
				
			||||||
		DEBUGP(DSCCP, "msgb is truncated is: %u should: %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "msgb is truncated is: %u should: %u\n",
 | 
				
			||||||
			msgb_l3len(msgb), msgb->l3h[-1]);
 | 
								msgb_l3len(msgb), msgb->l3h[-1]);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -478,7 +480,7 @@ static int _sccp_parse_it(struct msgb *msgb, struct sccp_parse_result *result)
 | 
				
			|||||||
	struct sccp_data_it *it;
 | 
						struct sccp_data_it *it;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (msgb_l2len(msgb) < header_size) {
 | 
						if (msgb_l2len(msgb) < header_size) {
 | 
				
			||||||
		DEBUGP(DSCCP, "msgb < header_size %u %u\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
 | 
				
			||||||
		        msgb_l2len(msgb), header_size);
 | 
							        msgb_l2len(msgb), header_size);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -490,6 +492,23 @@ static int _sccp_parse_it(struct msgb *msgb, struct sccp_parse_result *result)
 | 
				
			|||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int _sccp_parse_err(struct msgb *msgb, struct sccp_parse_result *result)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						static const u_int32_t header_size = sizeof(struct sccp_proto_err);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct sccp_proto_err *err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (msgb_l2len(msgb) < header_size) {
 | 
				
			||||||
 | 
							LOGP(DSCCP, LOGL_ERROR, "msgb < header_size %u %u\n",
 | 
				
			||||||
 | 
							     msgb_l2len(msgb), header_size);
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = (struct sccp_proto_err *) msgb->l2h;
 | 
				
			||||||
 | 
						result->data_len = 0;
 | 
				
			||||||
 | 
						result->destination_local_reference = &err->destination_local_reference;
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Send UDT. Currently we have a fixed address...
 | 
					 * Send UDT. Currently we have a fixed address...
 | 
				
			||||||
@@ -501,7 +520,7 @@ static int _sccp_send_data(int class, const struct sockaddr_sccp *in,
 | 
				
			|||||||
	u_int8_t *data;
 | 
						u_int8_t *data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (msgb_l3len(payload) > 256) {
 | 
						if (msgb_l3len(payload) > 256) {
 | 
				
			||||||
		DEBUGP(DSCCP, "The payload is too big for one udt\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "The payload is too big for one udt\n");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -546,7 +565,7 @@ static int _sccp_handle_read(struct msgb *msgb)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	cb = _find_ssn(result.called.ssn);
 | 
						cb = _find_ssn(result.called.ssn);
 | 
				
			||||||
	if (!cb || !cb->read_cb) {
 | 
						if (!cb || !cb->read_cb) {
 | 
				
			||||||
		DEBUGP(DSCCP, "No routing for UDT for called SSN: %u\n", result.called.ssn);
 | 
							LOGP(DSCCP, LOGL_ERROR, "No routing for UDT for called SSN: %u\n", result.called.ssn);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -595,7 +614,7 @@ static int assign_source_local_reference(struct sccp_connection *connection)
 | 
				
			|||||||
		++last_ref;
 | 
							++last_ref;
 | 
				
			||||||
		/* do not use the reversed word and wrap around */
 | 
							/* do not use the reversed word and wrap around */
 | 
				
			||||||
		if ((last_ref & 0x00FFFFFF) == 0x00FFFFFF) {
 | 
							if ((last_ref & 0x00FFFFFF) == 0x00FFFFFF) {
 | 
				
			||||||
			DEBUGP(DSCCP, "Wrapped searching for a free code\n");
 | 
								LOGP(DSCCP, LOGL_DEBUG, "Wrapped searching for a free code\n");
 | 
				
			||||||
			last_ref = 0;
 | 
								last_ref = 0;
 | 
				
			||||||
			++wrapped;
 | 
								++wrapped;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -606,7 +625,7 @@ static int assign_source_local_reference(struct sccp_connection *connection)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	} while (wrapped != 2);
 | 
						} while (wrapped != 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DEBUGP(DSCCP, "Finding a free reference failed\n");
 | 
						LOGP(DSCCP, LOGL_ERROR, "Finding a free reference failed\n");
 | 
				
			||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -686,13 +705,13 @@ static int _sccp_send_connection_request(struct sccp_connection *connection,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (msg && (msgb_l3len(msg) < 3 || msgb_l3len(msg) > 130)) {
 | 
						if (msg && (msgb_l3len(msg) < 3 || msgb_l3len(msg) > 130)) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Invalid amount of data... %d\n", msgb_l3len(msg));
 | 
							LOGP(DSCCP, LOGL_ERROR, "Invalid amount of data... %d\n", msgb_l3len(msg));
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* try to find a id */
 | 
						/* try to find a id */
 | 
				
			||||||
	if (assign_source_local_reference(connection) != 0) {
 | 
						if (assign_source_local_reference(connection) != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Assigning a local reference failed.\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "Assigning a local reference failed.\n");
 | 
				
			||||||
		_sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_SETUP_ERROR);
 | 
							_sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_SETUP_ERROR);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -744,7 +763,7 @@ static int _sccp_send_connection_data(struct sccp_connection *conn, struct msgb
 | 
				
			|||||||
	int extra_size;
 | 
						int extra_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (msgb_l3len(_data) < 2 || msgb_l3len(_data) > 256) {
 | 
						if (msgb_l3len(_data) < 2 || msgb_l3len(_data) > 256) {
 | 
				
			||||||
		DEBUGP(DSCCP, "data size too big, segmenting unimplemented.\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "data size too big, segmenting unimplemented.\n");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -840,14 +859,14 @@ static int _sccp_handle_connection_request(struct msgb *msgb)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	cb = _find_ssn(result.called.ssn);
 | 
						cb = _find_ssn(result.called.ssn);
 | 
				
			||||||
	if (!cb || !cb->accept_cb) {
 | 
						if (!cb || !cb->accept_cb) {
 | 
				
			||||||
		DEBUGP(DSCCP, "No routing for CR for called SSN: %u\n", result.called.ssn);
 | 
							LOGP(DSCCP, LOGL_ERROR, "No routing for CR for called SSN: %u\n", result.called.ssn);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* check if the system wants this connection */
 | 
						/* check if the system wants this connection */
 | 
				
			||||||
	connection = talloc_zero(tall_sccp_ctx, struct sccp_connection);
 | 
						connection = talloc_zero(tall_sccp_ctx, struct sccp_connection);
 | 
				
			||||||
	if (!connection) {
 | 
						if (!connection) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Allocation failed\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "Allocation failed\n");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -859,7 +878,7 @@ static int _sccp_handle_connection_request(struct msgb *msgb)
 | 
				
			|||||||
	 * one....
 | 
						 * one....
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (destination_local_reference_is_free(result.source_local_reference) != 0) {
 | 
						if (destination_local_reference_is_free(result.source_local_reference) != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Need to reject connection with existing reference\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "Need to reject connection with existing reference\n");
 | 
				
			||||||
		_sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE);
 | 
							_sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE);
 | 
				
			||||||
		talloc_free(connection);
 | 
							talloc_free(connection);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
@@ -879,7 +898,7 @@ static int _sccp_handle_connection_request(struct msgb *msgb)
 | 
				
			|||||||
	llist_add_tail(&connection->list, &sccp_connections);
 | 
						llist_add_tail(&connection->list, &sccp_connections);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (_sccp_send_connection_confirm(connection) != 0) {
 | 
						if (_sccp_send_connection_confirm(connection) != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Sending confirm failed... no available source reference?\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "Sending confirm failed... no available source reference?\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		_sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE);
 | 
							_sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE);
 | 
				
			||||||
		_sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REFUSED);
 | 
							_sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REFUSED);
 | 
				
			||||||
@@ -922,7 +941,7 @@ static int _sccp_handle_connection_release_complete(struct msgb *msgb)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DEBUGP(DSCCP, "Release complete of unknown connection\n");
 | 
						LOGP(DSCCP, LOGL_ERROR, "Release complete of unknown connection\n");
 | 
				
			||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
found:
 | 
					found:
 | 
				
			||||||
@@ -950,7 +969,7 @@ static int _sccp_handle_connection_dt1(struct msgb *msgb)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DEBUGP(DSCCP, "No connection found for dt1 data\n");
 | 
						LOGP(DSCCP, LOGL_ERROR, "No connection found for dt1 data\n");
 | 
				
			||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
found:
 | 
					found:
 | 
				
			||||||
@@ -1009,7 +1028,7 @@ static int _sccp_handle_connection_released(struct msgb *msgb)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DEBUGP(DSCCP, "Unknown connection was released.\n");
 | 
						LOGP(DSCCP, LOGL_ERROR, "Unknown connection was released.\n");
 | 
				
			||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* we have found a connection */
 | 
						/* we have found a connection */
 | 
				
			||||||
@@ -1021,7 +1040,7 @@ found:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* generate a response */
 | 
						/* generate a response */
 | 
				
			||||||
	if (_sccp_send_connection_release_complete(conn) != 0) {
 | 
						if (_sccp_send_connection_release_complete(conn) != 0) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Sending release confirmed failed\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "Sending release confirmed failed\n");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1046,7 +1065,7 @@ static int _sccp_handle_connection_refused(struct msgb *msgb)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DEBUGP(DSCCP, "Refused but no connection found\n");
 | 
						LOGP(DSCCP, LOGL_ERROR, "Refused but no connection found\n");
 | 
				
			||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
found:
 | 
					found:
 | 
				
			||||||
@@ -1079,7 +1098,7 @@ static int _sccp_handle_connection_confirm(struct msgb *msgb)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DEBUGP(DSCCP, "Confirmed but no connection found\n");
 | 
						LOGP(DSCCP, LOGL_ERROR, "Confirmed but no connection found\n");
 | 
				
			||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
found:
 | 
					found:
 | 
				
			||||||
@@ -1108,7 +1127,7 @@ int sccp_system_init(void (*outgoing)(struct msgb *data, void *ctx), void *ctx)
 | 
				
			|||||||
int sccp_system_incoming(struct msgb *msgb)
 | 
					int sccp_system_incoming(struct msgb *msgb)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (msgb_l2len(msgb) < 1 ) {
 | 
						if (msgb_l2len(msgb) < 1 ) {
 | 
				
			||||||
		DEBUGP(DSCCP, "Too short packet\n");
 | 
							LOGP(DSCCP, LOGL_ERROR, "Too short packet\n");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1137,7 +1156,7 @@ int sccp_system_incoming(struct msgb *msgb)
 | 
				
			|||||||
		return _sccp_handle_read(msgb);
 | 
							return _sccp_handle_read(msgb);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		DEBUGP(DSCCP, "unimplemented msg type: %d\n", type);
 | 
							LOGP(DSCCP, LOGL_ERROR, "unimplemented msg type: %d\n", type);
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
@@ -1148,7 +1167,7 @@ int sccp_connection_write(struct sccp_connection *connection, struct msgb *data)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
 | 
						if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
 | 
				
			||||||
	    || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
 | 
						    || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
 | 
				
			||||||
		DEBUGP(DSCCP, "sccp_connection_write: Wrong connection state: %p %d\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "sccp_connection_write: Wrong connection state: %p %d\n",
 | 
				
			||||||
		       connection, connection->connection_state);
 | 
							       connection, connection->connection_state);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1165,7 +1184,7 @@ int sccp_connection_send_it(struct sccp_connection *connection)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
 | 
						if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
 | 
				
			||||||
	    || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
 | 
						    || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
 | 
				
			||||||
		DEBUGP(DSCCP, "sccp_connection_write: Wrong connection state: %p %d\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "sccp_connection_write: Wrong connection state: %p %d\n",
 | 
				
			||||||
		       connection, connection->connection_state);
 | 
							       connection, connection->connection_state);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1178,7 +1197,7 @@ int sccp_connection_close(struct sccp_connection *connection, int cause)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
 | 
						if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
 | 
				
			||||||
	    || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
 | 
						    || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
 | 
				
			||||||
		DEBUGPC(DSCCP, "Can not close the connection. It was never opened: %p %d\n",
 | 
							LOGP(DSCCP, LOGL_ERROR, "Can not close the connection. It was never opened: %p %d\n",
 | 
				
			||||||
			connection, connection->connection_state);
 | 
								connection, connection->connection_state);
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1190,7 +1209,7 @@ int sccp_connection_free(struct sccp_connection *connection)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	if (connection->connection_state > SCCP_CONNECTION_STATE_NONE
 | 
						if (connection->connection_state > SCCP_CONNECTION_STATE_NONE
 | 
				
			||||||
	    && connection->connection_state < SCCP_CONNECTION_STATE_RELEASE_COMPLETE) {
 | 
						    && connection->connection_state < SCCP_CONNECTION_STATE_RELEASE_COMPLETE) {
 | 
				
			||||||
		DEBUGP(DSCCP, "The connection needs to be released before it is freed");
 | 
							LOGP(DSCCP, LOGL_ERROR, "The connection needs to be released before it is freed");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1318,6 +1337,9 @@ int sccp_parse_header(struct msgb *msg, struct sccp_parse_result *result)
 | 
				
			|||||||
	case SCCP_MSG_TYPE_IT:
 | 
						case SCCP_MSG_TYPE_IT:
 | 
				
			||||||
		return _sccp_parse_it(msg, result);
 | 
							return _sccp_parse_it(msg, result);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
						case SCCP_MSG_TYPE_ERR:
 | 
				
			||||||
 | 
							return _sccp_parse_err(msg, result);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	LOGP(DSCCP, LOGL_ERROR, "Unimplemented MSG Type: 0x%x\n", type);
 | 
						LOGP(DSCCP, LOGL_ERROR, "Unimplemented MSG Type: 0x%x\n", type);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -140,7 +140,7 @@ int gsm_silent_call_stop(struct gsm_subscriber *subscr)
 | 
				
			|||||||
	if (!conn->silent_call)
 | 
						if (!conn->silent_call)
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	put_subscr_con(conn);
 | 
						put_subscr_con(conn, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,7 @@
 | 
				
			|||||||
#include <openbsc/gsm_04_08.h>
 | 
					#include <openbsc/gsm_04_08.h>
 | 
				
			||||||
#include <openbsc/mncc.h>
 | 
					#include <openbsc/mncc.h>
 | 
				
			||||||
#include <openbsc/paging.h>
 | 
					#include <openbsc/paging.h>
 | 
				
			||||||
 | 
					#include <openbsc/chan_alloc.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *tall_trans_ctx;
 | 
					void *tall_trans_ctx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -95,14 +96,14 @@ void trans_free(struct gsm_trans *trans)
 | 
				
			|||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (trans->conn)
 | 
					 | 
				
			||||||
		put_subscr_con(trans->conn);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!trans->conn && trans->subscr && trans->subscr->net) {
 | 
						if (!trans->conn && trans->subscr && trans->subscr->net) {
 | 
				
			||||||
		/* Stop paging on all bts' */
 | 
							/* Stop paging on all bts' */
 | 
				
			||||||
		paging_request_stop(NULL, trans->subscr, NULL);
 | 
							paging_request_stop(NULL, trans->subscr, NULL);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (trans->conn)
 | 
				
			||||||
 | 
							put_subscr_con(trans->conn, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (trans->subscr)
 | 
						if (trans->subscr)
 | 
				
			||||||
		subscr_put(trans->subscr);
 | 
							subscr_put(trans->subscr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -159,7 +160,7 @@ int trans_lchan_change(struct gsm_subscriber_connection *conn_old,
 | 
				
			|||||||
		if (trans->conn == conn_old) {
 | 
							if (trans->conn == conn_old) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			/* drop old channel use count */
 | 
								/* drop old channel use count */
 | 
				
			||||||
			put_subscr_con(conn_old);
 | 
								put_subscr_con(conn_old, 0);
 | 
				
			||||||
			/* assign new channel */
 | 
								/* assign new channel */
 | 
				
			||||||
			trans->conn = conn_new;
 | 
								trans->conn = conn_new;
 | 
				
			||||||
			/* bump new channel use count */
 | 
								/* bump new channel use count */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -65,11 +65,11 @@ struct buffer_data {
 | 
				
			|||||||
#define BUFFER_DATA_FREE(D) talloc_free((D))
 | 
					#define BUFFER_DATA_FREE(D) talloc_free((D))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Make new buffer. */
 | 
					/* Make new buffer. */
 | 
				
			||||||
struct buffer *buffer_new(size_t size)
 | 
					struct buffer *buffer_new(void *ctx, size_t size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct buffer *b;
 | 
						struct buffer *b;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	b = talloc_zero(tall_vty_ctx, struct buffer);
 | 
						b = talloc_zero(ctx, struct buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (size)
 | 
						if (size)
 | 
				
			||||||
		b->size = size;
 | 
							b->size = size;
 | 
				
			||||||
@@ -138,7 +138,7 @@ static struct buffer_data *buffer_add(struct buffer *b)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	struct buffer_data *d;
 | 
						struct buffer_data *d;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	d = _talloc_zero(tall_vty_ctx,
 | 
						d = _talloc_zero(b,
 | 
				
			||||||
			 offsetof(struct buffer_data, data[b->size]),
 | 
								 offsetof(struct buffer_data, data[b->size]),
 | 
				
			||||||
			 "buffer_add");
 | 
								 "buffer_add");
 | 
				
			||||||
	if (!d)
 | 
						if (!d)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,6 +47,7 @@ Boston, MA 02111-1307, USA.  */
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <openbsc/gsm_data.h>
 | 
					#include <openbsc/gsm_data.h>
 | 
				
			||||||
#include <openbsc/gsm_subscriber.h>
 | 
					#include <openbsc/gsm_subscriber.h>
 | 
				
			||||||
 | 
					#include <openbsc/bsc_nat.h>
 | 
				
			||||||
#include <osmocore/talloc.h>
 | 
					#include <osmocore/talloc.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *tall_vty_cmd_ctx;
 | 
					void *tall_vty_cmd_ctx;
 | 
				
			||||||
@@ -1949,6 +1950,13 @@ enum node_type vty_go_parent(struct vty *vty)
 | 
				
			|||||||
		subscr_put(vty->index);
 | 
							subscr_put(vty->index);
 | 
				
			||||||
		vty->index = NULL;
 | 
							vty->index = NULL;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
						case BSC_NODE:
 | 
				
			||||||
 | 
							vty->node = NAT_NODE;
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								struct bsc_config *bsc = vty->index;
 | 
				
			||||||
 | 
								vty->index = bsc->nat;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		vty->node = CONFIG_NODE;
 | 
							vty->node = CONFIG_NODE;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -2365,6 +2373,15 @@ DEFUN(config_exit,
 | 
				
			|||||||
	case MGCP_NODE:
 | 
						case MGCP_NODE:
 | 
				
			||||||
		vty->node = CONFIG_NODE;
 | 
							vty->node = CONFIG_NODE;
 | 
				
			||||||
		vty->index = NULL;
 | 
							vty->index = NULL;
 | 
				
			||||||
 | 
						case NAT_NODE:
 | 
				
			||||||
 | 
							vty->node = CONFIG_NODE;
 | 
				
			||||||
 | 
							vty->index = NULL;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case BSC_NODE:
 | 
				
			||||||
 | 
							vty->node = NAT_NODE;
 | 
				
			||||||
 | 
							vty->index = NULL;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,10 +51,10 @@ struct vty *vty_new()
 | 
				
			|||||||
	if (!new)
 | 
						if (!new)
 | 
				
			||||||
		goto out;
 | 
							goto out;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	new->obuf = buffer_new(0);	/* Use default buffer size. */
 | 
						new->obuf = buffer_new(new, 0);	/* Use default buffer size. */
 | 
				
			||||||
	if (!new->obuf)
 | 
						if (!new->obuf)
 | 
				
			||||||
		goto out_new;
 | 
							goto out_new;
 | 
				
			||||||
	new->buf = _talloc_zero(tall_vty_ctx, VTY_BUFSIZ, "vty_new->buf");
 | 
						new->buf = _talloc_zero(new, VTY_BUFSIZ, "vty_new->buf");
 | 
				
			||||||
	if (!new->buf)
 | 
						if (!new->buf)
 | 
				
			||||||
		goto out_obuf;
 | 
							goto out_obuf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -170,8 +170,7 @@ void vty_close(struct vty *vty)
 | 
				
			|||||||
	/* Check configure. */
 | 
						/* Check configure. */
 | 
				
			||||||
	vty_config_unlock(vty);
 | 
						vty_config_unlock(vty);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* FIXME: memory leak. We need to call telnet_close_client() but don't
 | 
						/* VTY_CLOSED is handled by the telnet_interface */
 | 
				
			||||||
	 * have bfd */
 | 
					 | 
				
			||||||
	vty_event(VTY_CLOSED, vty->fd, vty);
 | 
						vty_event(VTY_CLOSED, vty->fd, vty);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* OK free vty. */
 | 
						/* OK free vty. */
 | 
				
			||||||
@@ -211,7 +210,7 @@ int vty_out(struct vty *vty, const char *format, ...)
 | 
				
			|||||||
				else
 | 
									else
 | 
				
			||||||
					size = size * 2;
 | 
										size = size * 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				p = talloc_realloc_size(tall_vty_ctx, p, size);
 | 
									p = talloc_realloc_size(vty, p, size);
 | 
				
			||||||
				if (!p)
 | 
									if (!p)
 | 
				
			||||||
					return -1;
 | 
										return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -358,7 +357,7 @@ static void vty_ensure(struct vty *vty, int length)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	if (vty->max <= length) {
 | 
						if (vty->max <= length) {
 | 
				
			||||||
		vty->max *= 2;
 | 
							vty->max *= 2;
 | 
				
			||||||
		vty->buf = talloc_realloc_size(tall_vty_ctx, vty->buf, vty->max);
 | 
							vty->buf = talloc_realloc_size(vty, vty->buf, vty->max);
 | 
				
			||||||
		// FIXME: check return
 | 
							// FIXME: check return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -459,7 +458,7 @@ static void vty_hist_add(struct vty *vty)
 | 
				
			|||||||
	/* Insert history entry. */
 | 
						/* Insert history entry. */
 | 
				
			||||||
	if (vty->hist[vty->hindex])
 | 
						if (vty->hist[vty->hindex])
 | 
				
			||||||
		talloc_free(vty->hist[vty->hindex]);
 | 
							talloc_free(vty->hist[vty->hindex]);
 | 
				
			||||||
	vty->hist[vty->hindex] = talloc_strdup(tall_vty_ctx, vty->buf);
 | 
						vty->hist[vty->hindex] = talloc_strdup(vty, vty->buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* History index rotation. */
 | 
						/* History index rotation. */
 | 
				
			||||||
	vty->hindex++;
 | 
						vty->hindex++;
 | 
				
			||||||
@@ -916,7 +915,7 @@ static void vty_complete_command(struct vty *vty)
 | 
				
			|||||||
		vty_backward_pure_word(vty);
 | 
							vty_backward_pure_word(vty);
 | 
				
			||||||
		vty_insert_word_overwrite(vty, matched[0]);
 | 
							vty_insert_word_overwrite(vty, matched[0]);
 | 
				
			||||||
		vty_self_insert(vty, ' ');
 | 
							vty_self_insert(vty, ' ');
 | 
				
			||||||
		//talloc_free(matched[0]);
 | 
							talloc_free(matched[0]);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case CMD_COMPLETE_MATCH:
 | 
						case CMD_COMPLETE_MATCH:
 | 
				
			||||||
		vty_prompt(vty);
 | 
							vty_prompt(vty);
 | 
				
			||||||
@@ -924,8 +923,6 @@ static void vty_complete_command(struct vty *vty)
 | 
				
			|||||||
		vty_backward_pure_word(vty);
 | 
							vty_backward_pure_word(vty);
 | 
				
			||||||
		vty_insert_word_overwrite(vty, matched[0]);
 | 
							vty_insert_word_overwrite(vty, matched[0]);
 | 
				
			||||||
		talloc_free(matched[0]);
 | 
							talloc_free(matched[0]);
 | 
				
			||||||
		vector_only_index_free(matched);
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case CMD_COMPLETE_LIST_MATCH:
 | 
						case CMD_COMPLETE_LIST_MATCH:
 | 
				
			||||||
		for (i = 0; matched[i] != NULL; i++) {
 | 
							for (i = 0; matched[i] != NULL; i++) {
 | 
				
			||||||
@@ -966,7 +963,7 @@ vty_describe_fold(struct vty *vty, int cmd_width,
 | 
				
			|||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	buf = _talloc_zero(tall_vty_ctx, strlen(desc->str) + 1, "describe_fold");
 | 
						buf = _talloc_zero(vty, strlen(desc->str) + 1, "describe_fold");
 | 
				
			||||||
	if (!buf)
 | 
						if (!buf)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,6 +39,8 @@
 | 
				
			|||||||
#include <osmocore/talloc.h>
 | 
					#include <osmocore/talloc.h>
 | 
				
			||||||
#include <openbsc/telnet_interface.h>
 | 
					#include <openbsc/telnet_interface.h>
 | 
				
			||||||
#include <openbsc/vty.h>
 | 
					#include <openbsc/vty.h>
 | 
				
			||||||
 | 
					#include <openbsc/ipaccess.h>
 | 
				
			||||||
 | 
					#include <openbsc/paging.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct gsm_network *gsmnet;
 | 
					static struct gsm_network *gsmnet;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -100,6 +102,7 @@ static void dump_pchan_load_vty(struct vty *vty, char *prefix,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void net_dump_vty(struct vty *vty, struct gsm_network *net)
 | 
					static void net_dump_vty(struct vty *vty, struct gsm_network *net)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
	struct pchan_load pl;
 | 
						struct pchan_load pl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	vty_out(vty, "BSC is on Country Code %u, Network Code %u "
 | 
						vty_out(vty, "BSC is on Country Code %u, Network Code %u "
 | 
				
			||||||
@@ -117,6 +120,8 @@ static void net_dump_vty(struct vty *vty, struct gsm_network *net)
 | 
				
			|||||||
		VTY_NEWLINE);
 | 
							VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, "  NECI (TCH/H): %u%s", net->neci,
 | 
						vty_out(vty, "  NECI (TCH/H): %u%s", net->neci,
 | 
				
			||||||
		VTY_NEWLINE);
 | 
							VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, "  Use TCH for Paging any: %d%s", net->pag_any_tch,
 | 
				
			||||||
 | 
							VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, "  RRLP Mode: %s%s", rrlp_mode_name(net->rrlp.mode),
 | 
						vty_out(vty, "  RRLP Mode: %s%s", rrlp_mode_name(net->rrlp.mode),
 | 
				
			||||||
		VTY_NEWLINE);
 | 
							VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, "  MM Info: %s%s", net->send_mm_info ? "On" : "Off",
 | 
						vty_out(vty, "  MM Info: %s%s", net->send_mm_info ? "On" : "Off",
 | 
				
			||||||
@@ -126,6 +131,12 @@ static void net_dump_vty(struct vty *vty, struct gsm_network *net)
 | 
				
			|||||||
	network_chan_load(&pl, net);
 | 
						network_chan_load(&pl, net);
 | 
				
			||||||
	vty_out(vty, "  Current Channel Load:%s", VTY_NEWLINE);
 | 
						vty_out(vty, "  Current Channel Load:%s", VTY_NEWLINE);
 | 
				
			||||||
	dump_pchan_load_vty(vty, "    ", &pl);
 | 
						dump_pchan_load_vty(vty, "    ", &pl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						vty_out(vty, "  Allowed Audio Codecs: ");
 | 
				
			||||||
 | 
						for (i = 0; i < net->audio_length; ++i)
 | 
				
			||||||
 | 
							vty_out(vty, "hr: %d ver: %d, ",
 | 
				
			||||||
 | 
								net->audio_support[i]->hr, net->audio_support[i]->ver);
 | 
				
			||||||
 | 
						vty_out(vty, "%s", VTY_NEWLINE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DEFUN(show_net, show_net_cmd, "show network",
 | 
					DEFUN(show_net, show_net_cmd, "show network",
 | 
				
			||||||
@@ -186,7 +197,8 @@ static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
 | 
				
			|||||||
	net_dump_nmstate(vty, &bts->nm_state);
 | 
						net_dump_nmstate(vty, &bts->nm_state);
 | 
				
			||||||
	vty_out(vty, "  Site Mgr NM State: ");
 | 
						vty_out(vty, "  Site Mgr NM State: ");
 | 
				
			||||||
	net_dump_nmstate(vty, &bts->site_mgr.nm_state);
 | 
						net_dump_nmstate(vty, &bts->site_mgr.nm_state);
 | 
				
			||||||
	vty_out(vty, "  Paging: FIXME pending requests, %u free slots%s",
 | 
						vty_out(vty, "  Paging: %u pending requests, %u free slots%s",
 | 
				
			||||||
 | 
							paging_pending_requests_nr(bts),
 | 
				
			||||||
		bts->paging.available_slots, VTY_NEWLINE);
 | 
							bts->paging.available_slots, VTY_NEWLINE);
 | 
				
			||||||
	if (!is_ipaccess_bts(bts)) {
 | 
						if (!is_ipaccess_bts(bts)) {
 | 
				
			||||||
		vty_out(vty, "  E1 Signalling Link:%s", VTY_NEWLINE);
 | 
							vty_out(vty, "  E1 Signalling Link:%s", VTY_NEWLINE);
 | 
				
			||||||
@@ -224,6 +236,36 @@ DEFUN(show_bts, show_bts_cmd, "show bts [number]",
 | 
				
			|||||||
	return CMD_SUCCESS;
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(test_bts_lchan_alloc, test_bts_lchan_alloc_cmd, "test bts alloc (sdcch|tch_h|tch_f)",
 | 
				
			||||||
 | 
					      "Test command to allocate all channels. You will need to restart. To free these channels.\n")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct gsm_network *net = gsmnet;
 | 
				
			||||||
 | 
						int bts_nr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						enum gsm_chan_t type = GSM_LCHAN_NONE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (strcmp("sdcch", argv[0]) == 0)
 | 
				
			||||||
 | 
							type = GSM_LCHAN_SDCCH;
 | 
				
			||||||
 | 
						else if (strcmp("tch_h", argv[0]) == 0)
 | 
				
			||||||
 | 
							type = GSM_LCHAN_TCH_H;
 | 
				
			||||||
 | 
						else if (strcmp("tch_f", argv[0]) == 0)
 | 
				
			||||||
 | 
							type = GSM_LCHAN_TCH_F;
 | 
				
			||||||
 | 
						else {
 | 
				
			||||||
 | 
							vty_out(vty, "Unknown mode for allocation.%s", VTY_NEWLINE);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (bts_nr = 0; bts_nr < net->num_bts; ++bts_nr) {
 | 
				
			||||||
 | 
							struct gsm_bts *bts = gsm_bts_num(net, bts_nr);
 | 
				
			||||||
 | 
							struct gsm_lchan *lchan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* alloc the channel */
 | 
				
			||||||
 | 
							while ((lchan = lchan_alloc(bts, type, 0)) != NULL)
 | 
				
			||||||
 | 
								rsl_lchan_set_state(lchan, LCHAN_S_REL_ERR);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* utility functions */
 | 
					/* utility functions */
 | 
				
			||||||
static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
 | 
					static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
 | 
				
			||||||
			  const char *ts, const char *ss)
 | 
								  const char *ts, const char *ss)
 | 
				
			||||||
@@ -308,6 +350,13 @@ static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
 | 
				
			|||||||
	vty_out(vty, "  rach max transmission %u%s",
 | 
						vty_out(vty, "  rach max transmission %u%s",
 | 
				
			||||||
		rach_max_trans_raw2val(bts->si_common.rach_control.max_trans),
 | 
							rach_max_trans_raw2val(bts->si_common.rach_control.max_trans),
 | 
				
			||||||
		VTY_NEWLINE);
 | 
							VTY_NEWLINE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bts->rach_b_thresh != -1)
 | 
				
			||||||
 | 
							vty_out(vty, "  rach nm busy threshold %u%s",
 | 
				
			||||||
 | 
								bts->rach_b_thresh, VTY_NEWLINE);
 | 
				
			||||||
 | 
						if (bts->rach_ldavg_slots != -1)
 | 
				
			||||||
 | 
							vty_out(vty, "  rach nm load average %u%s",
 | 
				
			||||||
 | 
								bts->rach_ldavg_slots, VTY_NEWLINE);
 | 
				
			||||||
	if (bts->si_common.rach_control.cell_bar)
 | 
						if (bts->si_common.rach_control.cell_bar)
 | 
				
			||||||
		vty_out(vty, "  cell barred 1%s", VTY_NEWLINE);
 | 
							vty_out(vty, "  cell barred 1%s", VTY_NEWLINE);
 | 
				
			||||||
	if (is_ipaccess_bts(bts)) {
 | 
						if (is_ipaccess_bts(bts)) {
 | 
				
			||||||
@@ -318,6 +367,11 @@ static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
 | 
				
			|||||||
		config_write_e1_link(vty, &bts->oml_e1_link, "  oml ");
 | 
							config_write_e1_link(vty, &bts->oml_e1_link, "  oml ");
 | 
				
			||||||
		vty_out(vty, "  oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
 | 
							vty_out(vty, "  oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* if we have a limit, write it */
 | 
				
			||||||
 | 
						if (bts->paging.free_chans_need >= 0)
 | 
				
			||||||
 | 
							vty_out(vty, "  paging free %d%s", bts->paging.free_chans_need, VTY_NEWLINE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	vty_out(vty, "  gprs mode %s%s", bts_gprs_mode_name(bts->gprs.mode),
 | 
						vty_out(vty, "  gprs mode %s%s", bts_gprs_mode_name(bts->gprs.mode),
 | 
				
			||||||
		VTY_NEWLINE);
 | 
							VTY_NEWLINE);
 | 
				
			||||||
	if (bts->gprs.mode != BTS_GPRS_NONE) {
 | 
						if (bts->gprs.mode != BTS_GPRS_NONE) {
 | 
				
			||||||
@@ -362,7 +416,11 @@ static int config_write_net(struct vty *vty)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	vty_out(vty, "network%s", VTY_NEWLINE);
 | 
						vty_out(vty, "network%s", VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
 | 
						vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
 | 
				
			||||||
 | 
						if (gsmnet->core_country_code > 0)
 | 
				
			||||||
 | 
							vty_out(vty, " core network country code %u%s", gsmnet->core_country_code, VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
 | 
						vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
 | 
				
			||||||
 | 
						if (gsmnet->core_network_code > 0)
 | 
				
			||||||
 | 
							vty_out(vty, " core mobile network code %u%s", gsmnet->core_network_code, VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
 | 
						vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
 | 
						vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
 | 
						vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
 | 
				
			||||||
@@ -370,6 +428,7 @@ static int config_write_net(struct vty *vty)
 | 
				
			|||||||
		gsmnet->reject_cause, VTY_NEWLINE);
 | 
							gsmnet->reject_cause, VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, " encryption a5 %u%s", gsmnet->a5_encryption, VTY_NEWLINE);
 | 
						vty_out(vty, " encryption a5 %u%s", gsmnet->a5_encryption, VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, " neci %u%s", gsmnet->neci, VTY_NEWLINE);
 | 
						vty_out(vty, " neci %u%s", gsmnet->neci, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " paging any use tch %d%s", gsmnet->pag_any_tch, VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, " rrlp mode %s%s", rrlp_mode_name(gsmnet->rrlp.mode),
 | 
						vty_out(vty, " rrlp mode %s%s", rrlp_mode_name(gsmnet->rrlp.mode),
 | 
				
			||||||
		VTY_NEWLINE);
 | 
							VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, " mm info %u%s", gsmnet->send_mm_info, VTY_NEWLINE);
 | 
						vty_out(vty, " mm info %u%s", gsmnet->send_mm_info, VTY_NEWLINE);
 | 
				
			||||||
@@ -397,6 +456,32 @@ static int config_write_net(struct vty *vty)
 | 
				
			|||||||
	vty_out(vty, " timer t3117 %u%s", gsmnet->T3117, VTY_NEWLINE);
 | 
						vty_out(vty, " timer t3117 %u%s", gsmnet->T3117, VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, " timer t3119 %u%s", gsmnet->T3119, VTY_NEWLINE);
 | 
						vty_out(vty, " timer t3119 %u%s", gsmnet->T3119, VTY_NEWLINE);
 | 
				
			||||||
	vty_out(vty, " timer t3141 %u%s", gsmnet->T3141, VTY_NEWLINE);
 | 
						vty_out(vty, " timer t3141 %u%s", gsmnet->T3141, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " ipacc rtp_payload %u%s", gsmnet->rtp_payload, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " rtp base %u%s", gsmnet->rtp_base_port, VTY_NEWLINE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (gsmnet->audio_length != 0) {
 | 
				
			||||||
 | 
							int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							vty_out(vty, " codec_list ");
 | 
				
			||||||
 | 
							for (i = 0; i < gsmnet->audio_length; ++i) {
 | 
				
			||||||
 | 
								printf("I... %d %d\n", i, gsmnet->audio_length);
 | 
				
			||||||
 | 
								if (i != 0)
 | 
				
			||||||
 | 
									vty_out(vty, ", ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (gsmnet->audio_support[i]->hr)
 | 
				
			||||||
 | 
									vty_out(vty, "hr%.1u", gsmnet->audio_support[i]->ver);
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									vty_out(vty, "fr%.1u", gsmnet->audio_support[i]->ver);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							vty_out(vty, "%s", VTY_NEWLINE);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (gsmnet->bsc_token)
 | 
				
			||||||
 | 
							vty_out(vty, " bsc_token %s%s", gsmnet->bsc_token, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " msc ip %s%s", gsmnet->msc_ip, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " msc port %d%s", gsmnet->msc_port, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " timeout ping %d%s", gsmnet->ping_timeout, VTY_NEWLINE);
 | 
				
			||||||
 | 
						vty_out(vty, " timeout pong %d%s", gsmnet->pong_timeout, VTY_NEWLINE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return CMD_SUCCESS;
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -879,6 +964,50 @@ DEFUN(show_paging,
 | 
				
			|||||||
	return CMD_SUCCESS;
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(drop_bts,
 | 
				
			||||||
 | 
					      drop_bts_cmd,
 | 
				
			||||||
 | 
					      "drop bts connection <0-65535> (oml|rsl)",
 | 
				
			||||||
 | 
					      "Debug/Simulation command to drop ipaccess BTS\n")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct gsm_bts_trx *trx;
 | 
				
			||||||
 | 
						struct gsm_bts *bts;
 | 
				
			||||||
 | 
						unsigned int bts_nr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bts_nr = atoi(argv[0]);
 | 
				
			||||||
 | 
						if (bts_nr >= gsmnet->num_bts) {
 | 
				
			||||||
 | 
							vty_out(vty, "BTS number must be between 0 and %d. It was %d.%s",
 | 
				
			||||||
 | 
								gsmnet->num_bts, bts_nr, VTY_NEWLINE);
 | 
				
			||||||
 | 
							return CMD_WARNING;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bts = gsm_bts_num(gsmnet, bts_nr);
 | 
				
			||||||
 | 
						if (!bts) {
 | 
				
			||||||
 | 
							vty_out(vty, "BTS Nr. %d could not be found.%s", bts_nr, VTY_NEWLINE);
 | 
				
			||||||
 | 
							return CMD_WARNING;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!is_ipaccess_bts(bts)) {
 | 
				
			||||||
 | 
							vty_out(vty, "This command only works for ipaccess.%s", VTY_NEWLINE);
 | 
				
			||||||
 | 
							return CMD_WARNING;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* close all connections */
 | 
				
			||||||
 | 
						if (strcmp(argv[1], "oml") == 0)
 | 
				
			||||||
 | 
							ipaccess_drop_oml(bts);
 | 
				
			||||||
 | 
						else if (strcmp(argv[1], "rsl") == 0) {
 | 
				
			||||||
 | 
							/* close all rsl connections */
 | 
				
			||||||
 | 
							llist_for_each_entry(trx, &bts->trx_list, list) {
 | 
				
			||||||
 | 
								ipaccess_drop_rsl(trx);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							vty_out(vty, "Argument must be 'oml' or 'rsl'.%s", VTY_NEWLINE);
 | 
				
			||||||
 | 
							return CMD_WARNING;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DEFUN(cfg_net,
 | 
					DEFUN(cfg_net,
 | 
				
			||||||
      cfg_net_cmd,
 | 
					      cfg_net_cmd,
 | 
				
			||||||
      "network",
 | 
					      "network",
 | 
				
			||||||
@@ -901,6 +1030,16 @@ DEFUN(cfg_net_ncc,
 | 
				
			|||||||
	return CMD_SUCCESS;
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_core_net_ncc,
 | 
				
			||||||
 | 
					      cfg_core_net_ncc_cmd,
 | 
				
			||||||
 | 
					      "core network country code <1-999>",
 | 
				
			||||||
 | 
					      "Set the GSM country code to be used in the MSC connection")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						gsmnet->core_country_code = atoi(argv[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DEFUN(cfg_net_mnc,
 | 
					DEFUN(cfg_net_mnc,
 | 
				
			||||||
      cfg_net_mnc_cmd,
 | 
					      cfg_net_mnc_cmd,
 | 
				
			||||||
      "mobile network code <1-999>",
 | 
					      "mobile network code <1-999>",
 | 
				
			||||||
@@ -911,6 +1050,16 @@ DEFUN(cfg_net_mnc,
 | 
				
			|||||||
	return CMD_SUCCESS;
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_core_net_mnc,
 | 
				
			||||||
 | 
					      cfg_core_net_mnc_cmd,
 | 
				
			||||||
 | 
					      "core mobile network code <1-999>",
 | 
				
			||||||
 | 
					      "Set the GSM mobile network code to be used in the MSC connection")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						gsmnet->core_network_code = atoi(argv[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DEFUN(cfg_net_name_short,
 | 
					DEFUN(cfg_net_name_short,
 | 
				
			||||||
      cfg_net_name_short_cmd,
 | 
					      cfg_net_name_short_cmd,
 | 
				
			||||||
      "short name NAME",
 | 
					      "short name NAME",
 | 
				
			||||||
@@ -975,6 +1124,7 @@ DEFUN(cfg_net_neci,
 | 
				
			|||||||
      "Set if NECI of cell selection is to be set")
 | 
					      "Set if NECI of cell selection is to be set")
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	gsmnet->neci = atoi(argv[0]);
 | 
						gsmnet->neci = atoi(argv[0]);
 | 
				
			||||||
 | 
						gsm_net_update_ctype(gsmnet);
 | 
				
			||||||
	return CMD_SUCCESS;
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1061,6 +1211,150 @@ DEFUN(cfg_net_ho_max_distance, cfg_net_ho_max_distance_cmd,
 | 
				
			|||||||
	return CMD_SUCCESS;
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_net_supported_codecs,
 | 
				
			||||||
 | 
					      cfg_net_supported_codecs_cmd,
 | 
				
			||||||
 | 
					      "codec_list .LIST",
 | 
				
			||||||
 | 
					      "Set the three preferred audio codecs.\n"
 | 
				
			||||||
 | 
					      "Codec List")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int saw_fr, saw_hr;
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						saw_fr = saw_hr = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* free the old list... if it exists */
 | 
				
			||||||
 | 
						if (gsmnet->audio_support) {
 | 
				
			||||||
 | 
							talloc_free(gsmnet->audio_support);
 | 
				
			||||||
 | 
							gsmnet->audio_support = NULL;
 | 
				
			||||||
 | 
							gsmnet->audio_length = 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* create a new array */
 | 
				
			||||||
 | 
						gsmnet->audio_support =
 | 
				
			||||||
 | 
								talloc_zero_array(gsmnet, struct gsm_audio_support *, argc);
 | 
				
			||||||
 | 
						gsmnet->audio_length = argc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < argc; ++i) {
 | 
				
			||||||
 | 
							/* check for hrX or frX */
 | 
				
			||||||
 | 
							if (strlen(argv[i]) != 3
 | 
				
			||||||
 | 
							    || argv[i][1] != 'r'
 | 
				
			||||||
 | 
							    || (argv[i][0] != 'h' && argv[i][0] != 'f')
 | 
				
			||||||
 | 
							    || argv[i][2] < 0x30
 | 
				
			||||||
 | 
							    || argv[i][2] > 0x39)
 | 
				
			||||||
 | 
								goto error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							gsmnet->audio_support[i] = talloc_zero(gsmnet->audio_support,
 | 
				
			||||||
 | 
											       struct gsm_audio_support);
 | 
				
			||||||
 | 
							gsmnet->audio_support[i]->ver = atoi(argv[i] + 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (strncmp("hr", argv[i], 2) == 0) {
 | 
				
			||||||
 | 
								gsmnet->audio_support[i]->hr = 1;
 | 
				
			||||||
 | 
								saw_hr = 1;
 | 
				
			||||||
 | 
							} else if (strncmp("fr", argv[i], 2) == 0) {
 | 
				
			||||||
 | 
								gsmnet->audio_support[i]->hr = 0;
 | 
				
			||||||
 | 
								saw_fr = 1;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (saw_hr && saw_fr) {
 | 
				
			||||||
 | 
								vty_out(vty, "Can not have full-rate and half-rate codec.%s",
 | 
				
			||||||
 | 
									VTY_NEWLINE);
 | 
				
			||||||
 | 
								return CMD_ERR_INCOMPLETE;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					error:
 | 
				
			||||||
 | 
						vty_out(vty, "Codec name must be hrX or frX. Was '%s'%s",
 | 
				
			||||||
 | 
							argv[i], VTY_NEWLINE);
 | 
				
			||||||
 | 
						return CMD_ERR_INCOMPLETE;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_net_ipacc_rtp_payload,
 | 
				
			||||||
 | 
					      cfg_net_ipacc_rtp_payload_cmd,
 | 
				
			||||||
 | 
					      "ipacc rtp_payload <0-256>",
 | 
				
			||||||
 | 
					      "Override the RTP payload to use")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						gsmnet->rtp_payload = atoi(argv[0]) & 0xff;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_net_rtp_base_port,
 | 
				
			||||||
 | 
					      cfg_net_rtp_base_port_cmd,
 | 
				
			||||||
 | 
					      "rtp base <0-65534>",
 | 
				
			||||||
 | 
					      "Base port to use for MGCP RTP")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						unsigned int port = atoi(argv[0]);
 | 
				
			||||||
 | 
						if (port > 65534) {
 | 
				
			||||||
 | 
							vty_out(vty, "%% wrong base port '%s'%s", argv[0], VTY_NEWLINE);
 | 
				
			||||||
 | 
							return CMD_WARNING;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						gsmnet->rtp_base_port = port;
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_net_bsc_token,
 | 
				
			||||||
 | 
					      cfg_net_bsc_token_cmd,
 | 
				
			||||||
 | 
					      "bsc_token TOKEN",
 | 
				
			||||||
 | 
					      "A token for the BSC to be sent to the MSC")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (gsmnet->bsc_token)
 | 
				
			||||||
 | 
							talloc_free(gsmnet->bsc_token);
 | 
				
			||||||
 | 
						gsmnet->bsc_token = talloc_strdup(gsmnet, argv[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_net_pag_any_tch,
 | 
				
			||||||
 | 
					      cfg_net_pag_any_tch_cmd,
 | 
				
			||||||
 | 
					      "paging any use tch (0|1)",
 | 
				
			||||||
 | 
					      "Assign a TCH when receiving a Paging Any request")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						gsmnet->pag_any_tch = atoi(argv[0]);
 | 
				
			||||||
 | 
						gsm_net_update_ctype(gsmnet);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_net_msc_ip,
 | 
				
			||||||
 | 
					      cfg_net_msc_ip_cmd,
 | 
				
			||||||
 | 
					      "msc ip IP",
 | 
				
			||||||
 | 
					      "Set the MSC/MUX IP address.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (gsmnet->msc_ip)
 | 
				
			||||||
 | 
							talloc_free(gsmnet->msc_ip);
 | 
				
			||||||
 | 
						gsmnet->msc_ip = talloc_strdup(gsmnet, argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_net_msc_port,
 | 
				
			||||||
 | 
					      cfg_net_msc_port_cmd,
 | 
				
			||||||
 | 
					      "msc port <1-65000>",
 | 
				
			||||||
 | 
					      "Set the MSC/MUX port.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						gsmnet->msc_port = atoi(argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_net_ping_time,
 | 
				
			||||||
 | 
					      cfg_net_ping_time_cmd,
 | 
				
			||||||
 | 
					      "timeout ping NR",
 | 
				
			||||||
 | 
					      "Set the PING interval, negative for not sending PING")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						gsmnet->ping_timeout = atoi(argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_net_pong_time,
 | 
				
			||||||
 | 
					      cfg_net_pong_time_cmd,
 | 
				
			||||||
 | 
					      "timeout pong NR",
 | 
				
			||||||
 | 
					      "Set the time to wait for a PONG.")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						gsmnet->pong_timeout = atoi(argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define DECLARE_TIMER(number, doc) \
 | 
					#define DECLARE_TIMER(number, doc) \
 | 
				
			||||||
    DEFUN(cfg_net_T##number,					\
 | 
					    DEFUN(cfg_net_T##number,					\
 | 
				
			||||||
      cfg_net_T##number##_cmd,					\
 | 
					      cfg_net_T##number##_cmd,					\
 | 
				
			||||||
@@ -1071,7 +1365,7 @@ DEFUN(cfg_net_ho_max_distance, cfg_net_ho_max_distance_cmd,
 | 
				
			|||||||
								\
 | 
													\
 | 
				
			||||||
	if (value < 0 || value > 65535) {			\
 | 
						if (value < 0 || value > 65535) {			\
 | 
				
			||||||
		vty_out(vty, "Timer value %s out of range.%s",	\
 | 
							vty_out(vty, "Timer value %s out of range.%s",	\
 | 
				
			||||||
		        argv[0], VTY_NEWLINE);			\
 | 
								argv[0], VTY_NEWLINE);			\
 | 
				
			||||||
		return CMD_WARNING;				\
 | 
							return CMD_WARNING;				\
 | 
				
			||||||
	}							\
 | 
						}							\
 | 
				
			||||||
								\
 | 
													\
 | 
				
			||||||
@@ -1084,14 +1378,13 @@ DECLARE_TIMER(3103, "Set the timeout value for HANDOVER.")
 | 
				
			|||||||
DECLARE_TIMER(3105, "Currently not used.")
 | 
					DECLARE_TIMER(3105, "Currently not used.")
 | 
				
			||||||
DECLARE_TIMER(3107, "Currently not used.")
 | 
					DECLARE_TIMER(3107, "Currently not used.")
 | 
				
			||||||
DECLARE_TIMER(3109, "Currently not used.")
 | 
					DECLARE_TIMER(3109, "Currently not used.")
 | 
				
			||||||
DECLARE_TIMER(3111, "Currently not used.")
 | 
					DECLARE_TIMER(3111, "Set the RSL timeout to wait before releasing the RF Channel.")
 | 
				
			||||||
DECLARE_TIMER(3113, "Set the time to try paging a subscriber.")
 | 
					DECLARE_TIMER(3113, "Set the time to try paging a subscriber.")
 | 
				
			||||||
DECLARE_TIMER(3115, "Currently not used.")
 | 
					DECLARE_TIMER(3115, "Currently not used.")
 | 
				
			||||||
DECLARE_TIMER(3117, "Currently not used.")
 | 
					DECLARE_TIMER(3117, "Currently not used.")
 | 
				
			||||||
DECLARE_TIMER(3119, "Currently not used.")
 | 
					DECLARE_TIMER(3119, "Currently not used.")
 | 
				
			||||||
DECLARE_TIMER(3141, "Currently not used.")
 | 
					DECLARE_TIMER(3141, "Currently not used.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
/* per-BTS configuration */
 | 
					/* per-BTS configuration */
 | 
				
			||||||
DEFUN(cfg_bts,
 | 
					DEFUN(cfg_bts,
 | 
				
			||||||
      cfg_bts_cmd,
 | 
					      cfg_bts_cmd,
 | 
				
			||||||
@@ -1337,6 +1630,26 @@ DEFUN(cfg_bts_rach_max_trans,
 | 
				
			|||||||
	return CMD_SUCCESS;
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_bts_rach_nm_b_thresh,
 | 
				
			||||||
 | 
					      cfg_bts_rach_nm_b_thresh_cmd,
 | 
				
			||||||
 | 
					      "rach nm busy threshold <0-255>",
 | 
				
			||||||
 | 
					      "Set the NM Busy Threshold in DB")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct gsm_bts *bts = vty->index;
 | 
				
			||||||
 | 
						bts->rach_b_thresh = atoi(argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_bts_rach_nm_ldavg,
 | 
				
			||||||
 | 
					      cfg_bts_rach_nm_ldavg_cmd,
 | 
				
			||||||
 | 
					      "rach nm load average <0-65535>",
 | 
				
			||||||
 | 
					      "Set the NM Loadaver Slots value")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct gsm_bts *bts = vty->index;
 | 
				
			||||||
 | 
						bts->rach_ldavg_slots = atoi(argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
 | 
					DEFUN(cfg_bts_cell_barred, cfg_bts_cell_barred_cmd,
 | 
				
			||||||
      "cell barred (0|1)",
 | 
					      "cell barred (0|1)",
 | 
				
			||||||
      "Should this cell be barred from access?")
 | 
					      "Should this cell be barred from access?")
 | 
				
			||||||
@@ -1495,6 +1808,16 @@ DEFUN(cfg_bts_gprs_nsvc_rip, cfg_bts_gprs_nsvc_rip_cmd,
 | 
				
			|||||||
	return CMD_SUCCESS;
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(cfg_bts_pag_free, cfg_bts_pag_free_cmd,
 | 
				
			||||||
 | 
					      "paging free FREE_NR",
 | 
				
			||||||
 | 
					      "Only page when having a certain amount of free slots. -1 to disable")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct gsm_bts *bts = vty->index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bts->paging.free_chans_need = atoi(argv[0]);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DEFUN(cfg_bts_gprs_rac, cfg_bts_gprs_rac_cmd,
 | 
					DEFUN(cfg_bts_gprs_rac, cfg_bts_gprs_rac_cmd,
 | 
				
			||||||
	"gprs routing area <0-255>",
 | 
						"gprs routing area <0-255>",
 | 
				
			||||||
	"GPRS Routing Area Code")
 | 
						"GPRS Routing Area Code")
 | 
				
			||||||
@@ -1721,13 +2044,18 @@ int bsc_vty_init(struct gsm_network *net)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	install_element(VIEW_NODE, &show_paging_cmd);
 | 
						install_element(VIEW_NODE, &show_paging_cmd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	openbsc_vty_add_cmds();
 | 
						install_element(VIEW_NODE, &drop_bts_cmd);
 | 
				
			||||||
 | 
						install_element(VIEW_NODE, &test_bts_lchan_alloc_cmd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						openbsc_vty_add_cmds();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
	install_element(CONFIG_NODE, &cfg_net_cmd);
 | 
						install_element(CONFIG_NODE, &cfg_net_cmd);
 | 
				
			||||||
	install_node(&net_node, config_write_net);
 | 
						install_node(&net_node, config_write_net);
 | 
				
			||||||
	install_default(GSMNET_NODE);
 | 
						install_default(GSMNET_NODE);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
 | 
				
			||||||
 | 
						install_element(GSMNET_NODE, &cfg_core_net_ncc_cmd);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
 | 
				
			||||||
 | 
						install_element(GSMNET_NODE, &cfg_core_net_mnc_cmd);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
 | 
				
			||||||
@@ -1743,6 +2071,9 @@ int bsc_vty_init(struct gsm_network *net)
 | 
				
			|||||||
	install_element(GSMNET_NODE, &cfg_net_ho_pwr_interval_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_ho_pwr_interval_cmd);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_ho_pwr_hysteresis_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_ho_pwr_hysteresis_cmd);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_ho_max_distance_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_ho_max_distance_cmd);
 | 
				
			||||||
 | 
						install_element(GSMNET_NODE, &cfg_net_supported_codecs_cmd);
 | 
				
			||||||
 | 
						install_element(GSMNET_NODE, &cfg_net_ipacc_rtp_payload_cmd);
 | 
				
			||||||
 | 
						install_element(GSMNET_NODE, &cfg_net_rtp_base_port_cmd);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_T3101_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_T3101_cmd);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_T3103_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_T3103_cmd);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_T3105_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_T3105_cmd);
 | 
				
			||||||
@@ -1754,6 +2085,12 @@ int bsc_vty_init(struct gsm_network *net)
 | 
				
			|||||||
	install_element(GSMNET_NODE, &cfg_net_T3117_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_T3117_cmd);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_T3119_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_T3119_cmd);
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_net_T3141_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_net_T3141_cmd);
 | 
				
			||||||
 | 
						install_element(GSMNET_NODE, &cfg_net_bsc_token_cmd);
 | 
				
			||||||
 | 
						install_element(GSMNET_NODE, &cfg_net_pag_any_tch_cmd);
 | 
				
			||||||
 | 
						install_element(GSMNET_NODE, &cfg_net_msc_ip_cmd);
 | 
				
			||||||
 | 
						install_element(GSMNET_NODE, &cfg_net_msc_port_cmd);
 | 
				
			||||||
 | 
						install_element(GSMNET_NODE, &cfg_net_ping_time_cmd);
 | 
				
			||||||
 | 
						install_element(GSMNET_NODE, &cfg_net_pong_time_cmd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	install_element(GSMNET_NODE, &cfg_bts_cmd);
 | 
						install_element(GSMNET_NODE, &cfg_bts_cmd);
 | 
				
			||||||
	install_node(&bts_node, config_write_bts);
 | 
						install_node(&bts_node, config_write_bts);
 | 
				
			||||||
@@ -1771,6 +2108,8 @@ int bsc_vty_init(struct gsm_network *net)
 | 
				
			|||||||
	install_element(BTS_NODE, &cfg_bts_challoc_cmd);
 | 
						install_element(BTS_NODE, &cfg_bts_challoc_cmd);
 | 
				
			||||||
	install_element(BTS_NODE, &cfg_bts_rach_tx_integer_cmd);
 | 
						install_element(BTS_NODE, &cfg_bts_rach_tx_integer_cmd);
 | 
				
			||||||
	install_element(BTS_NODE, &cfg_bts_rach_max_trans_cmd);
 | 
						install_element(BTS_NODE, &cfg_bts_rach_max_trans_cmd);
 | 
				
			||||||
 | 
						install_element(BTS_NODE, &cfg_bts_rach_nm_b_thresh_cmd);
 | 
				
			||||||
 | 
						install_element(BTS_NODE, &cfg_bts_rach_nm_ldavg_cmd);
 | 
				
			||||||
	install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
 | 
						install_element(BTS_NODE, &cfg_bts_cell_barred_cmd);
 | 
				
			||||||
	install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
 | 
						install_element(BTS_NODE, &cfg_bts_ms_max_power_cmd);
 | 
				
			||||||
	install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
 | 
						install_element(BTS_NODE, &cfg_bts_per_loc_upd_cmd);
 | 
				
			||||||
@@ -1784,6 +2123,7 @@ int bsc_vty_init(struct gsm_network *net)
 | 
				
			|||||||
	install_element(BTS_NODE, &cfg_bts_gprs_nsvc_lport_cmd);
 | 
						install_element(BTS_NODE, &cfg_bts_gprs_nsvc_lport_cmd);
 | 
				
			||||||
	install_element(BTS_NODE, &cfg_bts_gprs_nsvc_rport_cmd);
 | 
						install_element(BTS_NODE, &cfg_bts_gprs_nsvc_rport_cmd);
 | 
				
			||||||
	install_element(BTS_NODE, &cfg_bts_gprs_nsvc_rip_cmd);
 | 
						install_element(BTS_NODE, &cfg_bts_gprs_nsvc_rip_cmd);
 | 
				
			||||||
 | 
						install_element(BTS_NODE, &cfg_bts_pag_free_cmd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	install_element(BTS_NODE, &cfg_trx_cmd);
 | 
						install_element(BTS_NODE, &cfg_trx_cmd);
 | 
				
			||||||
	install_node(&trx_node, dummy_config_write);
 | 
						install_node(&trx_node, dummy_config_write);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										75
									
								
								openbsc/src/vty_interface_bsc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								openbsc/src/vty_interface_bsc.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,75 @@
 | 
				
			|||||||
 | 
					/* OpenBSC interface to quagga VTY - BSC options */
 | 
				
			||||||
 | 
					/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					#include <sys/types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vty/command.h>
 | 
				
			||||||
 | 
					#include <vty/buffer.h>
 | 
				
			||||||
 | 
					#include <vty/vty.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <openbsc/gsm_data.h>
 | 
				
			||||||
 | 
					#include <openbsc/vty.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sccp/sccp.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct gsm_network *gsmnet = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern struct llist_head *bsc_sccp_connections();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(show_bsc, show_bsc_cmd, "show bsc",
 | 
				
			||||||
 | 
						SHOW_STR "Display information about the BSC\n")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bss_sccp_connection_data *con;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						vty_out(vty, "BSC Information%s", VTY_NEWLINE);
 | 
				
			||||||
 | 
						llist_for_each_entry(con, bsc_sccp_connections(), active_connections) {
 | 
				
			||||||
 | 
							vty_out(vty, " Connection: LCHAN: %p sec LCHAN: %p SCCP src: %d dest: %d%s",
 | 
				
			||||||
 | 
								con->lchan, con->secondary_lchan,
 | 
				
			||||||
 | 
								con->sccp ? (int) sccp_src_ref_to_int(&con->sccp->source_local_reference) : -1,
 | 
				
			||||||
 | 
								con->sccp ? (int) sccp_src_ref_to_int(&con->sccp->destination_local_reference) : -1,
 | 
				
			||||||
 | 
								VTY_NEWLINE);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFUN(show_stats,
 | 
				
			||||||
 | 
					      show_stats_cmd,
 | 
				
			||||||
 | 
					      "show statistics",
 | 
				
			||||||
 | 
						SHOW_STR "Display network statistics\n")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct gsm_network *net = gsmnet;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						openbsc_vty_print_statistics(vty, net);
 | 
				
			||||||
 | 
						return CMD_SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int bsc_vty_init_extra(struct gsm_network *net)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						gsmnet = net;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* get runtime information */
 | 
				
			||||||
 | 
						install_element(VIEW_NODE, &show_bsc_cmd);
 | 
				
			||||||
 | 
						install_element(VIEW_NODE, &show_stats_cmd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -58,7 +58,7 @@ static int dummy_config_write(struct vty *v)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static struct buffer *argv_to_buffer(int argc, const char *argv[], int base)
 | 
					static struct buffer *argv_to_buffer(int argc, const char *argv[], int base)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct buffer *b = buffer_new(1024);
 | 
						struct buffer *b = buffer_new(NULL, 1024);
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!b)
 | 
						if (!b)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1 +1 @@
 | 
				
			|||||||
SUBDIRS = debug gsm0408 db channel sccp
 | 
					SUBDIRS = debug gsm0408 db channel sccp bsc-nat
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										17
									
								
								openbsc/tests/bsc-nat/Makefile.am
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								openbsc/tests/bsc-nat/Makefile.am
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					INCLUDES = $(all_includes) -I$(top_srcdir)/include
 | 
				
			||||||
 | 
					AM_CFLAGS=-Wall -ggdb3 $(LIBOSMOCORE_CFLAGS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					EXTRA_DIST = bsc_data.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					noinst_PROGRAMS = bsc_nat_test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bsc_nat_test_SOURCES = bsc_nat_test.c \
 | 
				
			||||||
 | 
								$(top_srcdir)/src/nat/bsc_filter.c \
 | 
				
			||||||
 | 
								$(top_srcdir)/src/nat/bsc_sccp.c \
 | 
				
			||||||
 | 
								$(top_srcdir)/src/nat/bsc_nat_utils.c \
 | 
				
			||||||
 | 
								$(top_srcdir)/src/nat/bsc_mgcp_utils.c \
 | 
				
			||||||
 | 
								$(top_srcdir)/src/mgcp/mgcp_protocol.c \
 | 
				
			||||||
 | 
								$(top_srcdir)/src/mgcp/mgcp_network.c \
 | 
				
			||||||
 | 
								$(top_srcdir)/src/bssap.c
 | 
				
			||||||
 | 
					bsc_nat_test_LDADD = $(top_builddir)/src/libbsc.a $(top_builddir)/src/libsccp.a $(LIBOSMOCORE_LIBS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										154
									
								
								openbsc/tests/bsc-nat/bsc_data.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										154
									
								
								openbsc/tests/bsc-nat/bsc_data.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,154 @@
 | 
				
			|||||||
 | 
					/* test data */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* BSC -> MSC, CR */
 | 
				
			||||||
 | 
					static const u_int8_t bsc_cr[] = {
 | 
				
			||||||
 | 
					0x00, 0x2e, 0xfd,
 | 
				
			||||||
 | 
					0x01, 0x00, 0x00, 0x15, 0x02, 0x02, 0x04, 0x02,
 | 
				
			||||||
 | 
					0x42, 0xfe, 0x0f, 0x21, 0x00, 0x1f, 0x57, 0x05,
 | 
				
			||||||
 | 
					0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x1c, 0xc3,
 | 
				
			||||||
 | 
					0x51, 0x17, 0x12, 0x05, 0x08, 0x20, 0x72, 0xf4,
 | 
				
			||||||
 | 
					0x90, 0x20, 0x1d, 0x50, 0x08, 0x29, 0x47, 0x80,
 | 
				
			||||||
 | 
					0x00, 0x00, 0x00, 0x00, 0x80, 0x00 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const u_int8_t bsc_cr_patched[] = {
 | 
				
			||||||
 | 
					0x00, 0x2e, 0xfd,
 | 
				
			||||||
 | 
					0x01, 0x00, 0x00, 0x05, 0x02, 0x02, 0x04, 0x02,
 | 
				
			||||||
 | 
					0x42, 0xfe, 0x0f, 0x21, 0x00, 0x1f, 0x57, 0x05,
 | 
				
			||||||
 | 
					0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x1c, 0xc3,
 | 
				
			||||||
 | 
					0x51, 0x17, 0x12, 0x05, 0x08, 0x20, 0x72, 0xf4,
 | 
				
			||||||
 | 
					0x90, 0x20, 0x1d, 0x50, 0x08, 0x29, 0x47, 0x80,
 | 
				
			||||||
 | 
					0x00, 0x00, 0x00, 0x00, 0x80, 0x00 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* CC, MSC -> BSC */
 | 
				
			||||||
 | 
					static const u_int8_t msc_cc[] = {
 | 
				
			||||||
 | 
					0x00, 0x0a, 0xfd,
 | 
				
			||||||
 | 
					0x02, 0x00, 0x00, 0x05, 0x01, 0x1f, 0xe4, 0x02,
 | 
				
			||||||
 | 
					0x01, 0x00 };
 | 
				
			||||||
 | 
					static const u_int8_t msc_cc_patched[] = {
 | 
				
			||||||
 | 
					0x00, 0x0a, 0xfd,
 | 
				
			||||||
 | 
					0x02, 0x00, 0x00, 0x15, 0x01, 0x1f, 0xe4, 0x02,
 | 
				
			||||||
 | 
					0x01, 0x00 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Classmark, BSC -> MSC */
 | 
				
			||||||
 | 
					static const u_int8_t bsc_dtap[] = {
 | 
				
			||||||
 | 
					0x00, 0x17, 0xfd,
 | 
				
			||||||
 | 
					0x06, 0x01, 0x1f, 0xe4, 0x00, 0x01, 0x10, 0x00,
 | 
				
			||||||
 | 
					0x0e, 0x54, 0x12, 0x03, 0x50, 0x18, 0x93, 0x13,
 | 
				
			||||||
 | 
					0x06, 0x60, 0x14, 0x45, 0x00, 0x81, 0x00 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const u_int8_t bsc_dtap_patched[] = {
 | 
				
			||||||
 | 
					0x00, 0x17, 0xfd,
 | 
				
			||||||
 | 
					0x06, 0x01, 0x1f, 0xe4, 0x00, 0x01, 0x10, 0x00,
 | 
				
			||||||
 | 
					0x0e, 0x54, 0x12, 0x03, 0x50, 0x18, 0x93, 0x13,
 | 
				
			||||||
 | 
					0x06, 0x60, 0x14, 0x45, 0x00, 0x81, 0x00 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Clear command, MSC -> BSC */
 | 
				
			||||||
 | 
					static const u_int8_t msc_dtap[] = {
 | 
				
			||||||
 | 
					0x00, 0x0d, 0xfd,
 | 
				
			||||||
 | 
					0x06, 0x00, 0x00, 0x05, 0x00, 0x01, 0x06, 0x00,
 | 
				
			||||||
 | 
					0x04, 0x20, 0x04, 0x01, 0x09 };
 | 
				
			||||||
 | 
					static const u_int8_t msc_dtap_patched[] = {
 | 
				
			||||||
 | 
					0x00, 0x0d, 0xfd,
 | 
				
			||||||
 | 
					0x06, 0x00, 0x00, 0x15, 0x00, 0x01, 0x06, 0x00,
 | 
				
			||||||
 | 
					0x04, 0x20, 0x04, 0x01, 0x09 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*RLSD, MSC -> BSC */
 | 
				
			||||||
 | 
					static const u_int8_t msc_rlsd[] = {
 | 
				
			||||||
 | 
					0x00, 0x0a, 0xfd,
 | 
				
			||||||
 | 
					0x04, 0x00, 0x00, 0x05, 0x01, 0x1f, 0xe4, 0x00,
 | 
				
			||||||
 | 
					0x01, 0x00 };
 | 
				
			||||||
 | 
					static const u_int8_t msc_rlsd_patched[] = {
 | 
				
			||||||
 | 
					0x00, 0x0a, 0xfd,
 | 
				
			||||||
 | 
					0x04, 0x00, 0x00, 0x15, 0x01, 0x1f, 0xe4, 0x00,
 | 
				
			||||||
 | 
					0x01, 0x00 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* RLC, BSC -> MSC */
 | 
				
			||||||
 | 
					static const u_int8_t bsc_rlc[] = {
 | 
				
			||||||
 | 
					0x00, 0x07, 0xfd,
 | 
				
			||||||
 | 
					0x05, 0x01, 0x1f, 0xe4, 0x00, 0x00, 0x15 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const u_int8_t bsc_rlc_patched[] = {
 | 
				
			||||||
 | 
					0x00, 0x07, 0xfd,
 | 
				
			||||||
 | 
					0x05, 0x01, 0x1f, 0xe4, 0x00, 0x00, 0x05 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* a paging command */
 | 
				
			||||||
 | 
					static const u_int8_t paging_by_lac_cmd[] = {
 | 
				
			||||||
 | 
					0x00, 0x22, 0xfd, 0x09,
 | 
				
			||||||
 | 
					0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x02, 0x00,
 | 
				
			||||||
 | 
					0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x12, 0x00,
 | 
				
			||||||
 | 
					0x10, 0x52, 0x08, 0x08, 0x29, 0x47, 0x10, 0x02,
 | 
				
			||||||
 | 
					0x01, 0x50, 0x02, 0x30, 0x1a, 0x03, 0x05, 0x20,
 | 
				
			||||||
 | 
					0x15 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* an assignment command */
 | 
				
			||||||
 | 
					static const u_int8_t ass_cmd[] = {
 | 
				
			||||||
 | 
					0x00, 0x12, 0xfd, 0x06,
 | 
				
			||||||
 | 
					0x00, 0x00, 0x49, 0x00, 0x01, 0x0b, 0x00, 0x09,
 | 
				
			||||||
 | 
					0x01, 0x0b, 0x03, 0x01, 0x0a, 0x11, 0x01, 0x00,
 | 
				
			||||||
 | 
					0x15 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * MGCP messages
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* nothing to patch */
 | 
				
			||||||
 | 
					static const char crcx[] = "CRCX 23265295 8@mgw MGCP 1.0\r\nC: 394b0439fb\r\nL: p:20, a:AMR, nt:IN\r\nM: recvonly\r\n";
 | 
				
			||||||
 | 
					static const char crcx_patched[] = "CRCX 23265295 8@mgw MGCP 1.0\r\nC: 394b0439fb\r\nL: p:20, a:AMR, nt:IN\r\nM: recvonly\r\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* patch the ip and port */
 | 
				
			||||||
 | 
					static const char crcx_resp[] = "200 23265295\r\nI: 1\r\n\r\nv=0\r\nc=IN IP4 172.16.18.2\r\nm=audio 4002 RTP/AVP 98\r\na=rtpmap:98 AMR/8000\r\n";
 | 
				
			||||||
 | 
					static const char crcx_resp_patched[] = "200 23265295\r\nI: 1\r\n\r\nv=0\r\nc=IN IP4 10.0.0.1\r\nm=audio 999 RTP/AVP 98\r\na=rtpmap:98 AMR/8000\r\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* patch the ip and port */
 | 
				
			||||||
 | 
					static const char mdcx[] = " MDCX 23330829 8@mgw MGCP 1.0\r\nC: 394b0439fb\r\nI: 1\r\nL: p:20, a:AMR, nt:IN\r\nM: recvonly\r\n\r\nv=0\r\no=- 1049380491 0 IN IP4 172.16.18.2\r\ns=-\r\nc=IN IP4 172.16.18.2\r\nt=0 0\r\nm=audio 4410 RTP/AVP 126\r\na=rtpmap:126 AMR/8000/1\r\na=fmtp:126 mode-set=2;start-mode=0\r\na=ptime:20\r\na=recvonly\r\nm=image 4412 udptl t38\r\na=T38FaxVersion:0\r\na=T38MaxBitRate:14400\r\n";
 | 
				
			||||||
 | 
					static const char mdcx_patched[] = " MDCX 23330829 8@mgw MGCP 1.0\r\nC: 394b0439fb\r\nI: 1\r\nL: p:20, a:AMR, nt:IN\r\nM: recvonly\r\n\r\nv=0\r\no=- 1049380491 0 IN IP4 172.16.18.2\r\ns=-\r\nc=IN IP4 10.0.0.23\r\nt=0 0\r\nm=audio 6666 RTP/AVP 126\r\na=rtpmap:126 AMR/8000/1\r\na=fmtp:126 mode-set=2;start-mode=0\r\na=ptime:20\r\na=recvonly\r\nm=image 4412 udptl t38\r\na=T38FaxVersion:0\r\na=T38MaxBitRate:14400\r\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char mdcx_resp[] = "200 23330829\r\n\r\nv=0\r\nc=IN IP4 172.16.18.2\r\nm=audio 4002 RTP/AVP 98\r\na=rtpmap:98 AMR/8000\r\n";
 | 
				
			||||||
 | 
					static const char mdcx_resp_patched[] = "200 23330829\r\n\r\nv=0\r\nc=IN IP4 10.0.0.23\r\nm=audio 5555 RTP/AVP 98\r\na=rtpmap:98 AMR/8000\r\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* different line ending */
 | 
				
			||||||
 | 
					static const char mdcx_resp2[] = "200 33330829\n\nv=0\nc=IN IP4 172.16.18.2\nm=audio 4002 RTP/AVP 98\na=rtpmap:98 AMR/8000\n";
 | 
				
			||||||
 | 
					static const char mdcx_resp_patched2[] = "200 33330829\n\nv=0\nc=IN IP4 10.0.0.23\nm=audio 5555 RTP/AVP 98\na=rtpmap:98 AMR/8000\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct mgcp_patch_test {
 | 
				
			||||||
 | 
						const char *orig;
 | 
				
			||||||
 | 
						const char *patch;
 | 
				
			||||||
 | 
						const char *ip;
 | 
				
			||||||
 | 
						const int port;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const struct mgcp_patch_test mgcp_messages[] = {
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.orig = crcx,
 | 
				
			||||||
 | 
							.patch = crcx_patched,
 | 
				
			||||||
 | 
							.ip = "0.0.0.0",
 | 
				
			||||||
 | 
							.port = 2323,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.orig = crcx_resp,
 | 
				
			||||||
 | 
							.patch = crcx_resp_patched,
 | 
				
			||||||
 | 
							.ip = "10.0.0.1",
 | 
				
			||||||
 | 
							.port = 999,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.orig = mdcx,
 | 
				
			||||||
 | 
							.patch = mdcx_patched,
 | 
				
			||||||
 | 
							.ip = "10.0.0.23",
 | 
				
			||||||
 | 
							.port = 6666,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.orig = mdcx_resp,
 | 
				
			||||||
 | 
							.patch = mdcx_resp_patched,
 | 
				
			||||||
 | 
							.ip = "10.0.0.23",
 | 
				
			||||||
 | 
							.port = 5555,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.orig = mdcx_resp2,
 | 
				
			||||||
 | 
							.patch = mdcx_resp_patched2,
 | 
				
			||||||
 | 
							.ip = "10.0.0.23",
 | 
				
			||||||
 | 
							.port = 5555,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										572
									
								
								openbsc/tests/bsc-nat/bsc_nat_test.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										572
									
								
								openbsc/tests/bsc-nat/bsc_nat_test.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,572 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * BSC NAT Message filtering
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
 | 
				
			||||||
 | 
					 * (C) 2010 by On-Waves
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * All Rights Reserved
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software; you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation; either version 2 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU General Public License along
 | 
				
			||||||
 | 
					 * with this program; if not, write to the Free Software Foundation, Inc.,
 | 
				
			||||||
 | 
					 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <openbsc/debug.h>
 | 
				
			||||||
 | 
					#include <openbsc/gsm_data.h>
 | 
				
			||||||
 | 
					#include <openbsc/bsc_nat.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <osmocore/talloc.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* test messages for ipa */
 | 
				
			||||||
 | 
					static u_int8_t ipa_id[] = {
 | 
				
			||||||
 | 
						0x00, 0x01, 0xfe, 0x06,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* SCCP messages are below */
 | 
				
			||||||
 | 
					static u_int8_t gsm_reset[] = {
 | 
				
			||||||
 | 
						0x00, 0x12, 0xfd,
 | 
				
			||||||
 | 
						0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe,
 | 
				
			||||||
 | 
						0x02, 0x42, 0xfe, 0x06, 0x00, 0x04, 0x30, 0x04,
 | 
				
			||||||
 | 
						0x01, 0x20,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const u_int8_t gsm_reset_ack[] = {
 | 
				
			||||||
 | 
						0x00, 0x13, 0xfd,
 | 
				
			||||||
 | 
						0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
 | 
				
			||||||
 | 
						0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x03,
 | 
				
			||||||
 | 
						0x00, 0x01, 0x31,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const u_int8_t gsm_paging[] = {
 | 
				
			||||||
 | 
						0x00, 0x20, 0xfd,
 | 
				
			||||||
 | 
						0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
 | 
				
			||||||
 | 
						0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x10,
 | 
				
			||||||
 | 
						0x00, 0x0e, 0x52, 0x08, 0x08, 0x29, 0x47, 0x10,
 | 
				
			||||||
 | 
						0x02, 0x01, 0x31, 0x97, 0x61, 0x1a, 0x01, 0x06,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* BSC -> MSC connection open */
 | 
				
			||||||
 | 
					static const u_int8_t bssmap_cr[] = {
 | 
				
			||||||
 | 
						0x00, 0x2c, 0xfd,
 | 
				
			||||||
 | 
						0x01, 0x01, 0x02, 0x03, 0x02, 0x02, 0x04, 0x02,
 | 
				
			||||||
 | 
						0x42, 0xfe, 0x0f, 0x1f, 0x00, 0x1d, 0x57, 0x05,
 | 
				
			||||||
 | 
						0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x12, 0xc3,
 | 
				
			||||||
 | 
						0x50, 0x17, 0x10, 0x05, 0x24, 0x11, 0x03, 0x33,
 | 
				
			||||||
 | 
						0x19, 0xa2, 0x08, 0x29, 0x47, 0x10, 0x02, 0x01,
 | 
				
			||||||
 | 
						0x31, 0x97, 0x61, 0x00
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* MSC -> BSC connection confirm */
 | 
				
			||||||
 | 
					static const u_int8_t bssmap_cc[] = {
 | 
				
			||||||
 | 
						0x00, 0x0a, 0xfd,
 | 
				
			||||||
 | 
						0x02, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* MSC -> BSC released */
 | 
				
			||||||
 | 
					static const u_int8_t bssmap_released[] = {
 | 
				
			||||||
 | 
						0x00, 0x0e, 0xfd,
 | 
				
			||||||
 | 
						0x04, 0x00, 0x00, 0x03, 0x01, 0x02, 0x03, 0x00, 0x01, 0x0f,
 | 
				
			||||||
 | 
						0x02, 0x23, 0x42, 0x00,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* BSC -> MSC released */
 | 
				
			||||||
 | 
					static const u_int8_t bssmap_release_complete[] = {
 | 
				
			||||||
 | 
						0x00, 0x07, 0xfd,
 | 
				
			||||||
 | 
						0x05, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* both directions IT timer */
 | 
				
			||||||
 | 
					static const u_int8_t connnection_it[] = {
 | 
				
			||||||
 | 
						0x00, 0x0b, 0xfd,
 | 
				
			||||||
 | 
						0x10, 0x01, 0x02, 0x03, 0x01, 0x02, 0x03,
 | 
				
			||||||
 | 
						0x00, 0x00, 0x00, 0x00,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* error in both directions */
 | 
				
			||||||
 | 
					static const u_int8_t proto_error[] = {
 | 
				
			||||||
 | 
						0x00, 0x05, 0xfd,
 | 
				
			||||||
 | 
						0x0f, 0x22, 0x33, 0x44, 0x00,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* MGCP wrap... */
 | 
				
			||||||
 | 
					static const u_int8_t mgcp_msg[] = {
 | 
				
			||||||
 | 
						0x00, 0x03, 0xfc,
 | 
				
			||||||
 | 
						0x20, 0x20, 0x20,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct filter_result {
 | 
				
			||||||
 | 
						const u_int8_t *data;
 | 
				
			||||||
 | 
						const u_int16_t length;
 | 
				
			||||||
 | 
						const int dir;
 | 
				
			||||||
 | 
						const int result;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const struct filter_result results[] = {
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = ipa_id,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(ipa_id),
 | 
				
			||||||
 | 
							.dir = DIR_MSC,
 | 
				
			||||||
 | 
							.result = 1,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = gsm_reset,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(gsm_reset),
 | 
				
			||||||
 | 
							.dir = DIR_MSC,
 | 
				
			||||||
 | 
							.result = 1,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = gsm_reset_ack,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(gsm_reset_ack),
 | 
				
			||||||
 | 
							.dir = DIR_BSC,
 | 
				
			||||||
 | 
							.result = 1,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = gsm_paging,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(gsm_paging),
 | 
				
			||||||
 | 
							.dir = DIR_BSC,
 | 
				
			||||||
 | 
							.result = 0,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = bssmap_cr,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(bssmap_cr),
 | 
				
			||||||
 | 
							.dir = DIR_MSC,
 | 
				
			||||||
 | 
							.result = 0,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = bssmap_cc,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(bssmap_cc),
 | 
				
			||||||
 | 
							.dir = DIR_BSC,
 | 
				
			||||||
 | 
							.result = 0,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = bssmap_released,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(bssmap_released),
 | 
				
			||||||
 | 
							.dir = DIR_MSC,
 | 
				
			||||||
 | 
							.result = 0,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = bssmap_release_complete,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(bssmap_release_complete),
 | 
				
			||||||
 | 
							.dir = DIR_BSC,
 | 
				
			||||||
 | 
							.result = 0,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = mgcp_msg,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(mgcp_msg),
 | 
				
			||||||
 | 
							.dir = DIR_MSC,
 | 
				
			||||||
 | 
							.result = 0,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = connnection_it,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(connnection_it),
 | 
				
			||||||
 | 
							.dir = DIR_BSC,
 | 
				
			||||||
 | 
							.result = 0,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = connnection_it,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(connnection_it),
 | 
				
			||||||
 | 
							.dir = DIR_MSC,
 | 
				
			||||||
 | 
							.result = 0,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = proto_error,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(proto_error),
 | 
				
			||||||
 | 
							.dir = DIR_BSC,
 | 
				
			||||||
 | 
							.result = 0,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.data = proto_error,
 | 
				
			||||||
 | 
							.length = ARRAY_SIZE(proto_error),
 | 
				
			||||||
 | 
							.dir = DIR_MSC,
 | 
				
			||||||
 | 
							.result = 0,
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void test_filter(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* start testinh with proper messages */
 | 
				
			||||||
 | 
						fprintf(stderr, "Testing BSS Filtering.\n");
 | 
				
			||||||
 | 
						for (i = 0; i < ARRAY_SIZE(results); ++i) {
 | 
				
			||||||
 | 
							int result;
 | 
				
			||||||
 | 
							struct bsc_nat_parsed *parsed;
 | 
				
			||||||
 | 
							struct msgb *msg = msgb_alloc(4096, "test-message");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							fprintf(stderr, "Going to test item: %d\n", i);
 | 
				
			||||||
 | 
							memcpy(msg->data, results[i].data, results[i].length);
 | 
				
			||||||
 | 
							msg->l2h = msgb_put(msg, results[i].length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
							if (!parsed) {
 | 
				
			||||||
 | 
								fprintf(stderr, "FAIL: Failed to parse the message\n");
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							result = bsc_nat_filter_ipa(results[i].dir, msg, parsed);
 | 
				
			||||||
 | 
							if (result != results[i].result) {
 | 
				
			||||||
 | 
								fprintf(stderr, "FAIL: Not the expected result got: %d wanted: %d\n",
 | 
				
			||||||
 | 
									result, results[i].result);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							msgb_free(msg);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "bsc_data.c"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void copy_to_msg(struct msgb *msg, const u_int8_t *data, unsigned int length)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						msgb_reset(msg);
 | 
				
			||||||
 | 
						msg->l2h = msgb_put(msg, length);
 | 
				
			||||||
 | 
						memcpy(msg->l2h, data, msgb_l2len(msg));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define VERIFY(con_found, con, msg, ver, str) \
 | 
				
			||||||
 | 
						if (!con_found || con_found->bsc != con) { \
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to find the con: %p\n", con_found); \
 | 
				
			||||||
 | 
							abort(); \
 | 
				
			||||||
 | 
						} \
 | 
				
			||||||
 | 
						if (memcmp(msg->data, ver, sizeof(ver)) != 0) { \
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to patch the %s msg.\n", str); \
 | 
				
			||||||
 | 
							abort(); \
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* test conn tracking once */
 | 
				
			||||||
 | 
					static void test_contrack()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int rc;
 | 
				
			||||||
 | 
						struct bsc_nat *nat;
 | 
				
			||||||
 | 
						struct bsc_connection *con;
 | 
				
			||||||
 | 
						struct sccp_connections *con_found;
 | 
				
			||||||
 | 
						struct bsc_nat_parsed *parsed;
 | 
				
			||||||
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fprintf(stderr, "Testing connection tracking.\n");
 | 
				
			||||||
 | 
						nat = bsc_nat_alloc();
 | 
				
			||||||
 | 
						con = bsc_connection_alloc(nat);
 | 
				
			||||||
 | 
						con->cfg = bsc_config_alloc(nat, "foo", 23);
 | 
				
			||||||
 | 
						msg = msgb_alloc(4096, "test");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* 1.) create a connection */
 | 
				
			||||||
 | 
						copy_to_msg(msg, bsc_cr, sizeof(bsc_cr));
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						con_found = patch_sccp_src_ref_to_msc(msg, parsed, con);
 | 
				
			||||||
 | 
						if (con_found != NULL) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Con should not exist %p\n", con_found);
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						rc = create_sccp_src_ref(con, msg, parsed);
 | 
				
			||||||
 | 
						if (rc != 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to create a ref\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						con_found = patch_sccp_src_ref_to_msc(msg, parsed, con);
 | 
				
			||||||
 | 
						if (!con_found || con_found->bsc != con) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to find the con: %p\n", con_found);
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (memcmp(msg->data, bsc_cr_patched, sizeof(bsc_cr_patched)) != 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to patch the BSC CR msg.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						talloc_free(parsed);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* 2.) get the cc */
 | 
				
			||||||
 | 
						copy_to_msg(msg, msc_cc, sizeof(msc_cc));
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
 | 
				
			||||||
 | 
						VERIFY(con_found, con, msg, msc_cc_patched, "MSC CC");
 | 
				
			||||||
 | 
						if (update_sccp_src_ref(con_found, parsed) != 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to update the SCCP con.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* 3.) send some data */
 | 
				
			||||||
 | 
						copy_to_msg(msg, bsc_dtap, sizeof(bsc_dtap));
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						con_found = patch_sccp_src_ref_to_msc(msg, parsed, con);
 | 
				
			||||||
 | 
						VERIFY(con_found, con, msg, bsc_dtap_patched, "BSC DTAP");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* 4.) receive some data */
 | 
				
			||||||
 | 
						copy_to_msg(msg, msc_dtap, sizeof(msc_dtap));
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
 | 
				
			||||||
 | 
						VERIFY(con_found, con, msg, msc_dtap_patched, "MSC DTAP");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* 5.) close the connection */
 | 
				
			||||||
 | 
						copy_to_msg(msg, msc_rlsd, sizeof(msc_rlsd));
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
 | 
				
			||||||
 | 
						VERIFY(con_found, con, msg, msc_rlsd_patched, "MSC RLSD");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* 6.) confirm the connection close */
 | 
				
			||||||
 | 
						copy_to_msg(msg, bsc_rlc, sizeof(bsc_rlc));
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						con_found = patch_sccp_src_ref_to_msc(msg, parsed, con);
 | 
				
			||||||
 | 
						if (!con_found || con_found->bsc != con) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to find the con: %p\n", con_found);
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (memcmp(msg->data, bsc_rlc_patched, sizeof(bsc_rlc_patched)) != 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to patch the BSC CR msg.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						remove_sccp_src_ref(con, msg, parsed);
 | 
				
			||||||
 | 
						talloc_free(parsed);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						copy_to_msg(msg, bsc_rlc, sizeof(bsc_rlc));
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						con_found = patch_sccp_src_ref_to_msc(msg, parsed, con);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* verify that it is gone */
 | 
				
			||||||
 | 
						if (con_found != NULL) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Con should be gone. %p\n", con_found);
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						talloc_free(parsed);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						talloc_free(nat);
 | 
				
			||||||
 | 
						msgb_free(msg);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void test_paging(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int lac;
 | 
				
			||||||
 | 
						struct bsc_nat *nat;
 | 
				
			||||||
 | 
						struct bsc_connection *con;
 | 
				
			||||||
 | 
						struct bsc_nat_parsed *parsed;
 | 
				
			||||||
 | 
						struct bsc_config cfg;
 | 
				
			||||||
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fprintf(stderr, "Testing paging by lac.\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat = bsc_nat_alloc();
 | 
				
			||||||
 | 
						con = bsc_connection_alloc(nat);
 | 
				
			||||||
 | 
						con->cfg = &cfg;
 | 
				
			||||||
 | 
						cfg.lac = 23;
 | 
				
			||||||
 | 
						con->authenticated = 1;
 | 
				
			||||||
 | 
						llist_add(&con->list_entry, &nat->bsc_connections);
 | 
				
			||||||
 | 
						msg = msgb_alloc(4096, "test");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Test completely bad input */
 | 
				
			||||||
 | 
						copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd));
 | 
				
			||||||
 | 
						if (bsc_nat_find_bsc(nat, msg, &lac) != 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Should have not found anything.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Test it by not finding it */
 | 
				
			||||||
 | 
						copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd));
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						if (bsc_nat_find_bsc(nat, msg, &lac) != 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Should have not found aynthing.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						talloc_free(parsed);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Test by finding it */
 | 
				
			||||||
 | 
						cfg.lac = 8213;
 | 
				
			||||||
 | 
						copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd));
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						if (bsc_nat_find_bsc(nat, msg, &lac) != con) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Should have found it.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						talloc_free(parsed);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void test_mgcp_ass_tracking(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_connection *bsc;
 | 
				
			||||||
 | 
						struct bsc_nat *nat;
 | 
				
			||||||
 | 
						struct sccp_connections con;
 | 
				
			||||||
 | 
						struct bsc_nat_parsed *parsed;
 | 
				
			||||||
 | 
						struct msgb *msg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fprintf(stderr, "Testing MGCP.\n");
 | 
				
			||||||
 | 
						memset(&con, 0, sizeof(con));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat = bsc_nat_alloc();
 | 
				
			||||||
 | 
						nat->bsc_endpoints = talloc_zero_array(nat,
 | 
				
			||||||
 | 
										       struct bsc_endpoint,
 | 
				
			||||||
 | 
										       33);
 | 
				
			||||||
 | 
						bsc = bsc_connection_alloc(nat);
 | 
				
			||||||
 | 
						bsc->cfg = bsc_config_alloc(nat, "foo", 2323);
 | 
				
			||||||
 | 
						con.bsc = bsc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						msg = msgb_alloc(4096, "foo");
 | 
				
			||||||
 | 
						copy_to_msg(msg, ass_cmd, sizeof(ass_cmd));
 | 
				
			||||||
 | 
						parsed = bsc_nat_parse(msg);
 | 
				
			||||||
 | 
						if (bsc_mgcp_assign(&con, msg) != 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to handle assignment.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (con.msc_timeslot != 21) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Timeslot should be 21.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (con.bsc_timeslot != 21) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Assigned timeslot should have been 21.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						talloc_free(parsed);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bsc_mgcp_dlcx(&con);
 | 
				
			||||||
 | 
						if (con.bsc_timeslot != -1 || con.msc_timeslot != -1) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Clearing should remove the mapping.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						talloc_free(nat);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* test the code to find a given connection */
 | 
				
			||||||
 | 
					static void test_mgcp_find(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct bsc_nat *nat;
 | 
				
			||||||
 | 
						struct bsc_connection *con;
 | 
				
			||||||
 | 
						struct sccp_connections *sccp_con;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fprintf(stderr, "Testing finding of a BSC Connection\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						nat = bsc_nat_alloc();
 | 
				
			||||||
 | 
						con = bsc_connection_alloc(nat);
 | 
				
			||||||
 | 
						llist_add(&con->list_entry, &nat->bsc_connections);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sccp_con = talloc_zero(con, struct sccp_connections);
 | 
				
			||||||
 | 
						sccp_con->msc_timeslot = 12;
 | 
				
			||||||
 | 
						sccp_con->bsc_timeslot = 12;
 | 
				
			||||||
 | 
						sccp_con->bsc = con;
 | 
				
			||||||
 | 
						llist_add(&sccp_con->list_entry, &nat->sccp_connections);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc_mgcp_find_con(nat, 11) != NULL) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Found the wrong connection.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc_mgcp_find_con(nat, 12) != sccp_con) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Didn't find the connection\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sccp_con->msc_timeslot = 0;
 | 
				
			||||||
 | 
						sccp_con->bsc_timeslot = 0;
 | 
				
			||||||
 | 
						if (bsc_mgcp_find_con(nat, 1) != sccp_con) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Didn't find the connection\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* free everything */
 | 
				
			||||||
 | 
						talloc_free(nat);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void test_mgcp_rewrite(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
						struct msgb *output;
 | 
				
			||||||
 | 
						fprintf(stderr, "Test rewriting MGCP messages.\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < ARRAY_SIZE(mgcp_messages); ++i) {
 | 
				
			||||||
 | 
							const char *orig = mgcp_messages[i].orig;
 | 
				
			||||||
 | 
							const char *patc = mgcp_messages[i].patch;
 | 
				
			||||||
 | 
							const char *ip = mgcp_messages[i].ip;
 | 
				
			||||||
 | 
							const int port = mgcp_messages[i].port;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							char *input = strdup(orig);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							output = bsc_mgcp_rewrite(input, strlen(input), ip, port);
 | 
				
			||||||
 | 
							if (msgb_l2len(output) != strlen(patc)) {
 | 
				
			||||||
 | 
								fprintf(stderr, "Wrong sizes for test: %d  %d != %d != %d\n", i, msgb_l2len(output), strlen(patc), strlen(orig));
 | 
				
			||||||
 | 
								fprintf(stderr, "String '%s' vs '%s'\n", (const char *) output->l2h, patc);
 | 
				
			||||||
 | 
								abort();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (memcmp(output->l2h, patc, msgb_l2len(output)) != 0) {
 | 
				
			||||||
 | 
								fprintf(stderr, "Broken on %d msg: '%s'\n", i, (const char *) output->l2h);
 | 
				
			||||||
 | 
								abort();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							msgb_free(output);
 | 
				
			||||||
 | 
							free(input);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void test_mgcp_parse(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int code, ci;
 | 
				
			||||||
 | 
						char transaction[60];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fprintf(stderr, "Test MGCP response parsing.\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (bsc_mgcp_parse_response(crcx_resp, &code, transaction) != 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to parse CRCX resp.\n");
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (code != 200) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to parse the CODE properly. Got: %d\n", code);
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (strcmp(transaction, "23265295") != 0) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to parse transaction id: '%s'\n", transaction);
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ci = bsc_mgcp_extract_ci(crcx_resp);
 | 
				
			||||||
 | 
						if (ci != 1) {
 | 
				
			||||||
 | 
							fprintf(stderr, "Failed to parse the CI. Got: %d\n", ci);
 | 
				
			||||||
 | 
							abort();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char **argv)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct log_target *stderr_target;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log_init(&log_info);
 | 
				
			||||||
 | 
						stderr_target = log_target_create_stderr();
 | 
				
			||||||
 | 
						log_add_target(stderr_target);
 | 
				
			||||||
 | 
						log_set_all_filter(stderr_target, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						test_filter();
 | 
				
			||||||
 | 
						test_contrack();
 | 
				
			||||||
 | 
						test_paging();
 | 
				
			||||||
 | 
						test_mgcp_ass_tracking();
 | 
				
			||||||
 | 
						test_mgcp_find();
 | 
				
			||||||
 | 
						test_mgcp_rewrite();
 | 
				
			||||||
 | 
						test_mgcp_parse();
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void input_event()
 | 
				
			||||||
 | 
					{}
 | 
				
			||||||
 | 
					int nm_state_event()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -76,6 +76,8 @@ int main(int argc, char** argv)
 | 
				
			|||||||
void nm_state_event() {}
 | 
					void nm_state_event() {}
 | 
				
			||||||
void input_event() {}
 | 
					void input_event() {}
 | 
				
			||||||
void sms_alloc() {}
 | 
					void sms_alloc() {}
 | 
				
			||||||
 | 
					void _lchan_release() {}
 | 
				
			||||||
 | 
					void gsm_net_update_ctype(struct gsm_network *network) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct tlv_definition nm_att_tlvdef;
 | 
					struct tlv_definition nm_att_tlvdef;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -264,6 +264,10 @@ static const u_int8_t it_test[] = {
 | 
				
			|||||||
0x10, 0x01, 0x07, 
 | 
					0x10, 0x01, 0x07, 
 | 
				
			||||||
0x94, 0x01, 0x04, 0x00, 0x02, 0x00, 0x00, 0x00 };
 | 
					0x94, 0x01, 0x04, 0x00, 0x02, 0x00, 0x00, 0x00 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const u_int8_t proto_err[] = {
 | 
				
			||||||
 | 
					0x0f, 0x0c, 0x04, 0x00, 0x00,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct sccp_parse_header_result parse_result[] = {
 | 
					static const struct sccp_parse_header_result parse_result[] = {
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		.msg_type	= SCCP_MSG_TYPE_IT,
 | 
							.msg_type	= SCCP_MSG_TYPE_IT,
 | 
				
			||||||
@@ -287,6 +291,21 @@ static const struct sccp_parse_header_result parse_result[] = {
 | 
				
			|||||||
		.input		= it_test,
 | 
							.input		= it_test,
 | 
				
			||||||
		.input_len	= sizeof(it_test),
 | 
							.input_len	= sizeof(it_test),
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							.msg_type	= SCCP_MSG_TYPE_ERR,
 | 
				
			||||||
 | 
							.wanted_len	= 0,
 | 
				
			||||||
 | 
							.src_ssn	= -1,
 | 
				
			||||||
 | 
							.dst_ssn	= -1,
 | 
				
			||||||
 | 
							.has_src_ref	= 0,
 | 
				
			||||||
 | 
							.has_dst_ref	= 1,
 | 
				
			||||||
 | 
							.dst_ref	= {
 | 
				
			||||||
 | 
								.octet1 = 0x0c,
 | 
				
			||||||
 | 
								.octet2 = 0x04,
 | 
				
			||||||
 | 
								.octet3 = 0x00,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							.input		= proto_err,
 | 
				
			||||||
 | 
							.input_len	= sizeof(proto_err),
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -777,7 +796,7 @@ static void test_sccp_parsing(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		memset(&result, 0, sizeof(result));
 | 
							memset(&result, 0, sizeof(result));
 | 
				
			||||||
		if (sccp_parse_header(msg, &result) != 0) {
 | 
							if (sccp_parse_header(msg, &result) != 0) {
 | 
				
			||||||
			fprintf(stderr, "Failed to parse test: %d\n", current_test);
 | 
								fprintf(stderr, "Failed to sccp parse test: %d\n", current_test);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if (parse_result[current_test].wanted_len != result.data_len) {
 | 
								if (parse_result[current_test].wanted_len != result.data_len) {
 | 
				
			||||||
				fprintf(stderr, "Unexpected data length.\n");
 | 
									fprintf(stderr, "Unexpected data length.\n");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user